• Resolved mheathgriffin

    (@mheathgriffin)


    I realize the topic title is a little confusing, so I’ll try to explain it a little better.

    I have a ul that contains my navigation and I want to append a class of ‘active’ when a series of pages are not displayed. I’ve tried the following code, but it, and different variations of it, do not seem to work.

    <li><a href="/news"<?php if (!is_home() || !is_page('about') || !is_page('past_conferences') || !is_page('upcoming_conferences') || !is_page('contact') || !is_page('join')) : ?> class="active" <?php endif; ?>>News</a></li>

    I am using wordpress as a CMS with only one “Page” (News) containing the blog where the rest of the pages have static content but can be updated/changed through WordPress. Whenever a page that would be part of the blog (except the defined pages in the code) is active, I want that link to be active. I’ve tried using is_page_template(‘template.php’) where “template.php” is replaced with the different templates used to format the blog. This doesn’t seem to work. I’ve also tried wrapping the ! in () outside of the condition as follows:
    if (!(is_home()) || !(is_page('about')))
    but that doesn’t seem to work either. If anyone knows how I can check to see if specific pages are not active then continue the loop, that’d be great.

    Thanks,

    – Heath G.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi

    I believe the problem is that your “OR’s” need to be “AND’s”. You have a series of negative conditions and you want them all to be true before adding the action class. When using OR’s, if any one of them is true then the class of Active is added. And at least one of them will always be true.

    Change || to && and see if that helps

    Thread Starter mheathgriffin

    (@mheathgriffin)

    Thanks stvwlf I’ll give that a try. I swear i miss the most obvious mistakes sometimes!

    That worked. For those looking for the correct code, here ya go:

    <li><a href="/news"<?php if (!is_home() && !is_page('about') && !is_page('past_conferences') && !is_page('upcoming_conferences') && !is_page('contact') && !is_page('join')) : ?> class="active" <?php endif; ?>>News</a></li>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Execute php command based on what page isn’t active’ is closed to new replies.