WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is_home() == true, on archive page? (7 posts)

  1. rbishop
    Member
    Posted 7 years ago #

    I'm using an adaptation of Charlie's Hemmed theme. Essentially it has an include for a file named "bottombar.php." I'm attempting to utilize The Popularity Contest plugin to echo specific archive information in one of the columns of this bottom bar. Here's the code:

    <?php if (is_home()) { ?>
    	<h2><?php _e('Most Popular'); ?></h2>
    	</div>
    	<ul><?php akpc_most_popular(); ?></ul>
    <?php } elseif (is_month()) { ?>
    	<h2>Most Popular in <?php the_time('F Y'); ?></h2>
    	</div>
    	<ul><?php akpc_most_popular_in_month(); ?></ul>
    <?php } elseif (is_category()) { ?>
    	<h2>Most Popular in '<?php single_cat_title(); ?>'</h2>
    	</div>
    	<ul><?php akpc_most_popular_in_cat(); ?></ul>
    <?php } ?>

    Trouble is, for some reason is_home() is true no matter what page I hit within my site.

    example 1: (actual home page)
    http://www.iddream.com

    example 2: (category archive page)
    http://www.iddream.com/category/brilliant-mistake/

    The code above should replace 'Most Popular' on the home page with 'Most Popular in Brilliant Mistake' on the category archive page right?

    I'm new to WordPress, is there something I overlooked?

  2. rbishop
    Member
    Posted 7 years ago #

    Let me guess, I'm going to have to create three separate bottombar.php files and have the above conditional on the archive page? Any alternative before I do this?

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    It looks like it's working to me. Although your category page has some other sort of problem, it's not showing the is_home stuff like you're talking about.

  4. rbishop
    Member
    Posted 7 years ago #

    I'm in the process of figuring it out. A copy of bottombar.php won't work because any included page from the archive page doesn't seem to carry the same values as the archive page itself. So calls like single_cat_title(), won't work like they do on the archive page (without an ID).

    So I'm attempting to capture the ID on the archive page and pass it into the bottombar.php when it loads:

    archive page:

    if (is_category()) {
       $archive_type = 2;
       $myType = single_cat_title();
    }

    bottombar.php:

    <?php if ($archive_type==2) { ?>
    <h2>Most Popular in '<?php _e($myType); ?>'</h2>
    <?php } ?>

    It's still not working but it's closer than before.

  5. rbishop
    Member
    Posted 7 years ago #

    Here's the solution:

    On my archive page I put:

    <?php if (is_month()) {
    	$archive_type = 1;
    	$myDate = get_the_time('F Y');
    	$myDateStr = get_the_time('Ym');
    } elseif (is_category()) {
    	$archive_type = 2;
    	$myID = $cat;
    	$cat = get_the_category();
    	$cat = $cat[0];
    	$myName = $cat->cat_name;
    } else {
    	$archive_type = 0;
    } ?>

    And on the bottombar.php I put:

    <?php if ($archive_type==0 || $archive_type==undefined) { ?>
    <h2>All Time Top 10</h2>
    </div>
    <ul><?php akpc_most_popular(); ?></ul>
    <?php } /* month */ elseif ($archive_type==1) { ?>
    <h2>Top in <?php echo $myDate; ?></h2>
    </div>
    <ul><?php akpc_most_popular_in_month($limit = 10, $before = '<li>', $after = '</li>', $m = $myDateStr); ?></ul>
    <?php } /* category */ elseif ($archive_type==2) { ?>
    <h2>Top in <?php echo $myName; ?></h2>
    </div>
    <ul><?php akpc_most_popular_in_cat($limit = 10, $before = '<li>', $after = '</li>', $cat_ID = $myID); ?></ul>
    <?php } ?>

    Pretty simple. Thanks for all the help.. Oh wait, nevermind.

  6. Chris_K
    Member
    Posted 7 years ago #

    Thanks for all the help.. Oh wait, nevermind.

    Nice...

    [insert standard reminder about unpaid volunteer support here in gently chiding tone]

  7. rbishop
    Member
    Posted 7 years ago #

    [insert, sarcasm doesn't come across well on the internet in gently chiding tone]

Topic Closed

This topic has been closed to new replies.

About this Topic