WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Conditions (4 posts)

  1. shaza
    Member
    Posted 5 years ago #

    Hi,
    Because of my client's webhost I have to use wordpress as a CMS. I am banging my head over how to do this, basically I have navigation that needs to change based on the post's category and also section. So I don't know how to do this, because I think I have something wrong in the code below. ALSO I need to insert links in there, so like in the category "services" I need it to show a list of links. How would I go about doing that. The category 'services' and the page "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_page()) {
            if (is_page('Services')) {
                 echo "Services Navigation";
            } elseif (is_page('Business')) {
                 echo "Business Navigation";
            } elseif (is_page('Products')) {
                 echo "Products Navigation";
            } else {
                  // catch-all for other pages
                  echo "<p>Vote for Pedro!</p>";
            }
    } else {
            echo "";
    }
    ?>
  2. shaza
    Member
    Posted 5 years ago #

    helppp mee

  3. iridiax
    Member
    Posted 5 years ago #

    Try it this way:

    <?php if (is_home()) { ?>
    <!-- code here -->
    <?php } elseif (is_category()) { ?>
    <!-- code here -->
    <?php } elseif (is_page()) { ?>
    <!-- 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 pages, look at using the_title to automatically get the page title:

    http://codex.wordpress.org/Template_Tags/the_title

    For categories, look at using single_cat_title to automatically get the category title:

    http://codex.wordpress.org/Template_Tags/single_cat_title

    I have navigation that needs to change based on the post's category

    This requires the in_category conditional tag, not the is_category tag:

    http://codex.wordpress.org/Template_Tags/in_category

  4. shaza
    Member
    Posted 5 years ago #

    Thanks! That seems to work pretty well!

Topic Closed

This topic has been closed to new replies.

About this Topic