Add back button on single posts pages
-
I have developed a site where the client writes blog posts for two different categories called ‘News’ and ‘Company News’.
Everything for ‘News’ is listed on the news page and everything for ‘Company News’ is listed on the ‘Company News’ page.I have been asked to add a back button to each post which takes the user back to the parent list page for that category, i.e. if the post is listed under ‘News’ the back button will take them to the ‘News’ page.
My problem is that all blog posts use the ‘single.php’ template regardless of the category they’re associated with.
I have written the following which works in a way, but it takes me to a specific category area rather than the ‘News’ or ‘Company News’ list pages.
/////////////////////// <?php $cats=get_the_category(); foreach($cats as $cat){ if($cat->category_parent == 0 && $cat->term_id != 1){ echo '<h2 class="link"><a>term_id ).'">Return</a></h2>'; } break; } ?> ///////////////////////
I’m struggling to adapt this to take the user to the right page.
Thanks
- This topic was modified 4 years, 9 months ago by .
- This topic was modified 4 years, 9 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘Add back button on single posts pages’ is closed to new replies.