0

I have a category.php page which redirects users to a certain template page if the article in the output is in a category. However, I am seeing that if I have say 10 articles,and only one is in the special category, then it redirects. Is there a way to modify my code to only say "if all of the posts are only in this special category then show the template"?

else if (in_category('ontario-ohs-reform-alerts')) {    include(TEMPLATEPATH . '/ontario-ohs-reform-alerts.php'); }

2 Answers 2

1

Just create a template file called "category-ontario-ohs-reform-alerts.php". This way any time this category is displayed, your special template will be used.

0

The easiest way to do this would be to add your current logic into The Loop, and each time the post is in the "special category", iterate a variable. If the variable reaches a certain number (10 in this case) then spawn the redirect.

You can iterate through the loop without displaying the content (using get_ instead of the_ functions), and store the values for each in an array. Once the loop is finished, you can add your redirect logic, and then run another foreach on the new array you've created for displaying the actual data.

2
  • If you do this in the loop, you're already outputting content, so a redirect will not work - unless you remember to buffer the output so you can still send the headers.
    – Jan Fabry
    May 10, 2011 at 8:00
  • 1
    You can try iterating through the loop without displaying the content (use get_ instead of the_ functions), and instead store the values in an array. Once the loop is finished, you can add your redirect logic, and then run another foreach on the new array you've created for displaying the actual data.
    – Dave Hunt
    May 17, 2011 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.