3

Im trying to set up an if statement to display certain code, if the user is on a certain page. I've got the links and student work pages to work, but when I add the if not link and not student work I get an unexpected T_BOOLEAN_AND error. How can I fix this so I can list the pages I don't want custom code for and use just page.php

<?php 
            if (!is_page('links')) && (!is_page('student-work'))  {
                include(TEMPLATEPATH . '/pages/page.php');
            } elseif (is_page('links')) {
                query_posts('cat=2');
                include(TEMPLATEPATH . '/pages/links.php');
            } elseif (is_page('student-work')) {
                query_posts('cat=4');
                include(TEMPLATEPATH . '/pages/student-work.php');
            }
?>
4

I just used this code and it works for me. Hopefully it solves your problem.

if( ! is_page( array( 'links', 'student-work' ) ) ) { /* ... */ }
  • Could you edit your answer and expand upon why this solves OPs question and supply any links that supports how this solves the problem please? – Howdy_McGee Jan 26 '17 at 20:35
3

This is really just PHP, not WP, but your initial if statement has an extra parenthesis after !is_page('links'), so the && is outside and PHP doesn’t know what to do with it. It'd be better to reorganize the block anyway, e.g.

<?php 
        if (is_page('links')) {
            query_posts('cat=2');
            include(TEMPLATEPATH . '/pages/links.php');
        } elseif (is_page('student-work')) {
            query_posts('cat=4');
            include(TEMPLATEPATH . '/pages/student-work.php');
        }
        else  {
            include(TEMPLATEPATH . '/pages/page.php');
        }
?>

In terms of WordPress, you'd probably be better off using page-specific template files, such as page-links.php or page-student-work.php. You could also use get_template_part() instead of includes to accomplish what that if/else block does in just one line if you need to keep this all in one file for some reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.