• Resolved catyco

    (@catyco)


    Hi,
    I have this elseif statement and last 2 elseif is not working. The catid is correct.

    Please help!

    $catID != 0;
    if (is_page(‘Training & Fitness’)) {
    $catID=55;
    } elseif (is_page(‘Health & Nutrition’)) {
    $catID=26;
    } elseif (is_page(‘Hair & Beauty’)) {
    $catID=58;
    } elseif (is_page(‘Fashion’)) {
    $catID=58;
    }

    if ($catID) {
    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    query_posts(“cat=$catID&paged=$paged”);
    } ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The first line $catID != 0; will cause a PHP Undefined variable notice. You can replace that part with $catID = false;

    Where is this code? Is it in a page template? Are there any other custom queries being called before the code?

    To debug whats going on try this:

    $catID = false;
    if (is_page('Training & Fitness')) {
        $catID=55;
    } elseif (is_page('Health & Nutrition')) {
        $catID=26;
    } elseif (is_page('Hair & Beauty') || is_page('Fashion')) {
        $catID=58;
    }
    var_dump( $catID );

    The results of the var_dump(); will give you the value of $catID. If it returns as false then you will know that none of your if statements returned true.

    If your using query_posts() make sure you reset the query by calling wp_reset_query(); Or better yet use new WP_Query instead.

    Thread Starter catyco

    (@catyco)

    It is in the page template. No custom queries being called. I edit the code to include the var_dump and doesn’t call catid for last 2 elseif statement.

    Thread Starter catyco

    (@catyco)

    never mind the problem is solved. Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Else If Statement not working’ is closed to new replies.