rjckicks1 Posted November 7, 2007 Posted November 7, 2007 Hi, I use this code on the product_info page so users can travel back to the category page the product came from - <td class="main" align="left"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, tep_get_path( $current_category_id = '')) . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td> The thing is here is the structure of the index page - main page categories page (for example index.php?cPath=1) Then if you click on a category on the "index.php?cPath=1" page it sends you to another page with more products for example labeled "index.php?cPath=1_21" Then from there if you click on a product it brings you to the product_info.php page. The back button on that page sends you back to "index.php?cPath=1_21". What I need is a back button on the "index.php?cPath=1_21" page that sends users back to the "index.php?cPath=1" page. For the code on the product_info.php page it uses $current_category_id to point to cPath=1_21, but I do not know what variable I could use to point to cPath=1? I'm guessing I just need the variable to replace current_category_id with that points to the main categories rather than the sub page that shows actual products. I would appreciate some advice! Thanks
gamesxs Posted November 8, 2007 Posted November 8, 2007 Hi, been playing with this and seem to have got something going! Had back buttons that went back to the index page from categories and sub-categories but changed the code to: echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '?cPath=' .(+$cPath ).'">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; Which then went from the sub-categories to the categorie, but ( always a BUT) if in a categorie , when nowhere! So changed to this: if ($current_category_id = $category_parent) echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . ' ">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; else echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '?cPath=' .(+$cPath ).'">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; Which seems to work! I have only 4 categories, the first right now has no products , cPath21, this returns to the index page. The second has products but no sub-categories, cPath1, this for some reason stays on the same page????? The others act as they should returning from sub-cats to their own cats! Maybe you can see what i right now cant? Hope this helps you anyway. Gary if I had the faintest clue regarding exactly what it was that I may or may not be doing, I would stop it!!
gamesxs Posted November 8, 2007 Posted November 8, 2007 Hi again. This seems to work. <?php if ($current_category_id = $category_parent) echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . ' ">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; elseif ($current_category_id == ereg("[*_**]",$cPath)) echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . ' ">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; else echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '?cPath=' .(+$cPath ).'">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?> Should take from sub-cat to cat or from no products to index or from cat to index. Hope it helps gary. if I had the faintest clue regarding exactly what it was that I may or may not be doing, I would stop it!!
Rachael w. Posted November 9, 2007 Posted November 9, 2007 I think most people want to go back to the page they were just before when they click the back button...they dont want to go somewhere else. This code will take them back the same as clicking back in their browser would. <a href="java script:history.back(1)"><img border="0" src="includes/languages/english/images/buttons/button_back.gif">
rjckicks1 Posted November 9, 2007 Author Posted November 9, 2007 hey gary thanks for the help that's exactly what I needed.
rjckicks1 Posted November 9, 2007 Author Posted November 9, 2007 gary is there a reason the button would work only on cPath=1 and not other categories?? It works for my cpath=1 but for cpath=3 and cpath=22 categories it just sends you back from a sub category to the index.php cpath=3 i setup a couple test sub categories but there are no products within those sub categories. For cpath=22 there are no subcategories just products. can u help me with this? thanks
gamesxs Posted November 10, 2007 Posted November 10, 2007 Hi, have tested this changed code as much as possible, eg: adding sub cats with or without products, adding just products without sub cats etc.. <?php if ($category_depth = ereg("[**_**]",$cPath)) echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '?cPath=' .(+$cPath ).'">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; else echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . ' ">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?> It all seems to work works on mine! Hope it does for you too?? Gary if I had the faintest clue regarding exactly what it was that I may or may not be doing, I would stop it!!
rjckicks1 Posted November 11, 2007 Author Posted November 11, 2007 hey gary, works great! thanks for your help.
ReavtiveMicro.com Posted February 4, 2008 Posted February 4, 2008 Hello guys. How about when the cPath is something like 'cPath=1_21_29' for example? Any ideas on the code then? Henry ReactiveMicro.com Henry ReactiveMicro.com
ReavtiveMicro.com Posted February 4, 2008 Posted February 4, 2008 Hello guys. How about when the cPath is something like 'cPath=1_21_29' for example? Any ideas on the code then? Henry ReactiveMicro.com Well, to answer my own question... <?php if ($category_depth = ereg ("([0-9]{1,2})_([0-9]{1,2})_([0-9]{1,2})", $cPath)) { echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '?cPath=' . ($cPath[0] . $cPath[1] . $cPath[2] . $cPath[3]) . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; } elseif ($category_depth = ereg ("([0-9]{1,2})_([0-9]{1,2})", $cPath)) { echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '?cPath=' . (+$cPath) . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; } else { echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . ' ">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; } ?> It's not pretty though, as I'm sure a 'real' coder will be able to see. I'm just a hack (at best) and really have no idea what I'm doing. This does seem to work though. The codes isn't 100% prefect as the more sub Categories there are, the more lines will need to be added to deal with the growing cPath. Specifically the 'ereg' and the amount of '([0-9]{1,2})_' arguments and 'elseif' statements. On top of it all, I have no idea why the '(+$cPath)' statement works in the 'elseif' line while it doesn't work in the 'if' line. Can someone please explain this to me? I'd really appreciate it. Maybe someone can clean my sloppy code up so it will work more generically without the need for people to edit the code if they add another sub Category? I would sure appreciate it, as I'm sure others after me would. Henry ReactiveMicro.com
ReavtiveMicro.com Posted February 4, 2008 Posted February 4, 2008 Here's something a buddy of mine and I threw together: <?php $thelen=strlen($cPath); $ext = strrchr($cPath, '_'); if ($ext == FALSE && $cPath !== '') { echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . ' ">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; } else { $cPath=substr($cPath,0,$thelen-strlen($ext)); echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '?cPath=' . $cPath . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; } ?> Works like a charm! I'll have to post this mod in the Downloads section. Henry ReactiveMicro.com
Recommended Posts
Archived
This topic is now archived and is closed to further replies.