Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'); }
share|improve this question
add comment

migrated from stackoverflow.com Apr 11 '11 at 23:55

This question came from our site for professional and enthusiast programmers.

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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 '11 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 '11 at 13:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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