Conditional statements and the Loop – help :)
-
Hi there,
I wondered if somebody out there can help me! ??
I’m trying to output a link at the end of my loop to take the user back to the correct category depending on some conditions.
I have read many help forums and tried a combination of things, but couldn’t see the answer.
At the end of my loop I want it to output the correct link depending on if the post was categorised as “blog”, “in the news”, “event updates” etc.
So for example, say I click on Blog then one of the posts listed on that page, at the foot of post (when viewed as a single post) I want to output “back to blog.” The same for Event Updates, when a user is viewing a single post view, I want my loop to output a link that takes the user back to ‘Event Updates’.
Here’s my code, at the end of my loop (which works perfectly fine otherwise!:
<?php else : ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php get_search_form(); ?> <?php endif; ?> <?php if (get_the_category('blog')) { echo '<a href="/blog">Back to blog</a>'; } elseif (get_the_category('eventsupdates')) { echo '<a href="/event-updates">Back to event updates</a>';} else { echo '<a href="/in-the-news/">Back to in the news</a>'; }
Any help gratefully received!
- The topic ‘Conditional statements and the Loop – help :)’ is closed to new replies.