0

In Wordpress I want to call a specific secondary menu in the event a page called foo is called. I've got this beviour working by using the following:

<?php if (is_page('foo') ) : ?>
<!-- NAV HTML -->
<?php endif; ?>

However I'd like this same secondary menu to be shown on some other pages, such as foo2 which I can currently call by recycling most of the above:

<?php if (is_page('foo2') ) : ?>
<!-- NAV HTML -->
<?php endif; ?>

What would be the best way to join these statements? For instance doesnt work:

<?php if (is_page('foo','foo2') ) : ?>
Dan382
  • 976
  • 6
  • 22
  • 44

4 Answers4

2

The wordpress docs suggest your example code:

<?php if (is_page('foo','foo2') ) : ?>

should work fine. http://codex.wordpress.org/Function_Reference/is_page

However i am not particularly familiar with wordpress, so as an alternative you can use php's OR operator

<?php if (is_page('foo') || is_page('foo2')) : ?>
<!-- NAV HTML -->
<?php endif; ?>

http://php.net/manual/en/language.operators.logical.php

Steve
  • 20,703
  • 5
  • 41
  • 67
  • My example code doesn't create an error and works fine for 'foo', but does not create a secondary menu for 'foo2'. Using the OR selector DOES do the trick though. Thank you. – Dan382 Nov 11 '14 at 12:07
1

You can use the OR logical operator, ||:

<?php if (is_page('foo') || is_page('foo2')) : ?>
    <!-- NAV HTML -->
<?php endif; ?>

It checks if the page is is_page('foo') OR is_page('foo2').

Sverri M. Olsen
  • 13,055
  • 3
  • 36
  • 52
1

You can combine multiple conditions by using &&(and) and ||(or), there are more, but these are the most used. In your case you want to use ||, so the if statement will be as followed:

if (is_page('foo') || is_page('foo2'))
Terry
  • 332
  • 1
  • 15
1

Use below code for getting the menu in both pages.

<?php if (is_page('foo') || is_page('foo2')) : ?>
    <!-- NAV HTML -->
<?php endif; ?>
Kausha Mehta
  • 2,828
  • 2
  • 20
  • 31