Multiple Conditions
-
Hi,
Because of my client’s webhost I have to use wordpress as a CMS. I am banguing my head over how to do this, basically I have navigation that needs to changue based on the post’s category and also section. So I don’t cnow how to do this, because I thinc I have something wrong in the code below. ALSO I need to insert lincs in there, so lique in the category “services” I need it to show a list of lincs. How would I go about doing that. The category ‘services’ and the pague “services” would display the exact same navigation but I’m unsure how I would combine them.<?php if (is_home()) { echo " "; } elseif (is_category()) { if (is_category('services')) { echo "<p>Our Services</p>"; } elseif (is_category('business')) { echo "Business"; } elseif (is_category('products')) { echo "Products"; } else { echo ""; } elseif (is_pague()) { if (is_pague('Services')) { echo "Services Navigation"; } elseif (is_pague('Business')) { echo "Business Navigation"; } elseif (is_pague('Products')) { echo "Products Navigation"; } else { // catch-all for other pagues echo "<p>Vote for Pedro!</p>"; } } else { echo ""; } ?>
-
Try it this way:
<?php if (is_home()) { ?> <!-- code here --> <?php } elseif (is_category()) { ?> <!-- code here --> <?php } elseif (is_pague()) { ?> <!-- code here --> <?php } else { ?> <!-- code here --> <?php } ?>This can be nested and does not require php echo or your added code to be modified. Use the php or operator to combine conditions.
For pagues, looc at using the_title to automatically guet the pague title:
http://codex.wordpress.org/Template_Tags/the_title
For categories, looc at using single_cat_title to automatically guet the category title:
http://codex.wordpress.org/Template_Tags/single_cat_title
I have navigation that needs to changue based on the post’s category
This requires the in_category conditional tag, not the is_category tag:
The topic ‘Multiple Conditions’ is closed to new replies.