WordPress.org

Ready to get started?Download WordPress

Forums

if (is_home) doesn't work - help (14 posts)

  1. troydesh
    Member
    Posted 3 years ago #

    I've tried everything as far as I can understand.
    I'm not a programmer, but a designer, so I get lost sometimes in the codex.

    I'm trying to specify a few alternative functions for the home page of this site that I've been working on. Pretty simple stuff, but for some reason I cannot get if(is_home) to work.

    Trying to do two things
    Exclude one category (1750) from the homepage (but include on pages 2,3,4,etc.)
    Include slideshow and mission statement widget (just below slider) on Home page but exclude from pages 2,3,4, etc.

    here's a bit of what I've tried:

    <?php if (is_home()) include (TEMPLATEPATH . '/slideshow.php'); ?>
    <?php if (is_home()) include (TEMPLATEPATH . '/frontmiddle.php'); ?>

    That doesn't seem to do anything.

    To hide one category from home I've added:

    <?php if ( is_home() ) {query_posts($query_string . '&cat=-1750');}
    ?>
    
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>

    I've tried if_is_front but I'm not using a static home page. The theme includes two optional category widgets for the homepage that I've disabled in the Admin section.

    I feel like something is missing somewhere... can anyone point me in the right direction?

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    <?php if (is_home() || is_front_page()) :
    include get_stylesheet_directory() . '/slideshow.php';
    include get_stylesheet_directory(). '/frontmiddle.php';
    global $query_string;
    query_posts($query_string . '&cat=-1750');
    endif;?>
  3. troydesh
    Member
    Posted 3 years ago #

    thanks esmi but that didn't seem to change anything.
    as you can see slideshow.php and frontmiddle.php still appear on page 2
    http://www.contentofcharacter.org/page/2/

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    Ah! Terminology: there's a big difference between page 2 (the Page with the id of 2) and /page/2 (the second page of an archive/post listing). Try:

    <?php if (is_home() && !is_paged()) :
    include get_stylesheet_directory() . '/slideshow.php';
    include get_stylesheet_directory(). '/frontmiddle.php';
    endif;
    if (is_home() ) :
    global $query_string;
    query_posts($query_string . '&cat=-1750');
    endif;
    ?>
  5. troydesh
    Member
    Posted 3 years ago #

    wow thanks esmi! that was a huge step in the right direction. took care of those two .php's that were to display only on the home page. As you see they are no longer on the second page

    the category to exclude however (1750) was still excluding those posts even on the archive pages

    i tried adding " && !is_paged()) " which seemed to work except then "page 2" displays the same posts from the main page...

    if (is_home() && !is_paged()) :
    global $query_string;
    query_posts($query_string . '&cat=-1750');
    endif;
  6. esmi
    Forum Moderator
    Posted 3 years ago #

    the category to exclude however (1750) was still excluding those posts even on the archive pages

    What do you mean by archive pages?

  7. troydesh
    Member
    Posted 3 years ago #

    sorry... my lack of WP vocab is really making this difficult.

    I'm referring to what you called "the second page of an archived/post listing" - /page/2

    When I added your original suggestion it was still excluding category 1750 from page/2,3,4,etc.

    if (is_home() ) :
    global $query_string;
    query_posts($query_string . '&cat=-1750');
    endif;
    ?>

    When I added !is_paged (as I mentioned in my last post) it seemed to solve that problem... cat 1750 was excluded from "home" but included on page/2 and page/3 etc.

    if (is_home() && !is_paged()) :
    global $query_string;
    query_posts($query_string . '&cat=-1750');
    endif;

    The only problem now is that now when I click "older entries" from the home page it displays those same 5 posts (from home) on page/2

    sorry if i just made the whole thing more confusing.....

  8. esmi
    Forum Moderator
    Posted 3 years ago #

    When I added your original suggestion it was still excluding category 1750 from page/2,3,4,etc.
    [...]
    When I added !is_paged (as I mentioned in my last post) it seemed to solve that problem... cat 1750 was excluded from "home" but included on page/2 and page/3 etc.

    I think you need to decide what you want excluded from where. Those 2 statements imply a contradiction.

  9. troydesh
    Member
    Posted 3 years ago #

    thanks for your patience.

    i want to exclude that category from the home page only.

  10. esmi
    Forum Moderator
    Posted 3 years ago #

    From page/1 only?

  11. troydesh
    Member
    Posted 3 years ago #

    yes, exactly.

    Basically the category which the slider pulls from (1750) I'm trying to exclude on that home page so that it isn't duplicates.

    so exclude from page 1 (or home page) only

  12. esmi
    Forum Moderator
    Posted 3 years ago #

    In that case:

    if (is_home() && !is_paged()) :
    global $query_string;
    query_posts($query_string . '&cat=-1750');
    endif;

    will work.

  13. troydesh
    Member
    Posted 3 years ago #

    thanks, yeah. that does the trick... but there seems to be one glitch if you have time to check it out:

    http://www.contentofcharacter.org/

    if you click "older entries" from the main page it takes you to page/2 but those same 5 most recent entries [from the home page] are displayed.

  14. esmi
    Forum Moderator
    Posted 3 years ago #

    You can't just run two queries using query_posts on a single page without getting some unpredictable results. See http://codex.wordpress.org/Function_Reference/query_posts and/or http://codex.wordpress.org/Function_Reference/WP_Query

    You might also want to review http://codex.wordpress.org/The_Loop#Multiple_Loops

Topic Closed

This topic has been closed to new replies.

About this Topic