• In the following code:
    query_posts( ‘showposts=5&cat=4’ );
    if (have_posts()) { while (have_posts()) { the_post();
    if(is_home()){
    ////do some stuff
    }
    if(is_category()){
    /////do some other stuff
    }

    When on my home page, is_home returns false and is_category returns true.

    If I remove the &cat=4 from query_posts things behave as normal. Of course then I get all the posts instead of just the posts from category 4 like I want.

    Is this expected behavior or a bug?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Expected behavior. When you use query_posts, you are modifying the default query, and that affects those template tags.

    If this is not your main page’s Loop, then you should not use query_posts. You should create a new WP_Query object and use that instead, as a separate query won’t modify those values.

    Are you trying to show only the posts from particular category on your main page?. If so why not just use

    query_posts( ‘showposts=5&cat=4’ );
    if (have_posts()) { while (have_posts()) { the_post();

    ////do some stuff

    }

    in your index.php page.

    If your theme has single page (index.php) taking care of both category and mainpage, then
    1.Upload category.php (same file as index.php but renamed to category.php) to example.com/wp-content/themes/[theme-name]/ .

    2.or try this instead,
    if(is_home()){
    query_posts( ‘showposts=5&cat=4’ );
    if (have_posts()) { while (have_posts()) { the_post(); //****** }
    }
    if(is_category()){
    /////do some other stuff
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is this expected is_home() behavior?’ is closed to new replies.