WordPress.org

Ready to get started?Download WordPress

Forums

if(!is_page()) (6 posts)

  1. Darfuria
    Member
    Posted 4 years ago #

    I've got a few bits of template functionality in PHP files that I call in using include (TEMPLATEPATH . '/path/to/file'); however, I want to prevent those bits of code from being included on certain pages.

    I've added the below code to my template, and that prevents the code from being included on the specified page.

    if (!is_page(1)) { include (TEMPLATEPATH . 'path/to/file'); }

    However, if I try to exclude multiple pages, or a combination of pages and categories, it stops the code from working completely, using the below code:

    if (!is_page(1) || !is_page(2)) { include (TEMPLATEPATH . 'path/to/file'); }

    if (!is_page(1) || !is_category(1)) { include (TEMPLATEPATH . 'path/to/file'); }

    Is there a correct/better way of doing this?

    Cheers.

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    try:
    if ( !(is_page(1) || is_page(2)) ) { include (TEMPLATEPATH . 'path/to/file'); }

  3. Darfuria
    Member
    Posted 4 years ago #

    That excludes it on page 1 and includes it on page 2

  4. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    check the brackets:
    if ( !( is_page(1) || is_page(2) ) ) { include (TEMPLATEPATH . 'path/to/file'); }

    this is inside the if:

    !( is_page(1) || is_page(2) )

  5. demetris
    Member
    Posted 4 years ago #

    Darfuria, see:

    http://codex.wordpress.org/Conditional_Tags

    Conditonial tags like is_page() can take a list of parameters passed in an array. E.g., you can write your condition like this:

    !is_page(array('1', '2', '3'))

    The article on Conditional Tags has several examples and explanations.

  6. Darfuria
    Member
    Posted 4 years ago #

    @demetris - Ah, that resolves my issue when using multiple pages - thanks

    @alchymyth - that seems to have fixed it for now. Brilliant, thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.