Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Hide homepage content on blog pagination WordPress

  • SOLVED

I have an index.php file running two queries - one to get the homepage content, and another to get the latest posts and paginate them. When a visitor clicks the pagination, I'd like the homepage content to disappear.

The code I'm using is below. Suggestions for solutions or alternative methods are welcome.

<div class="content">
<?php $homepage = new WP_Query('pagename=home'); ?>
<?php if($homepage->have_posts()) : ?><?php while($homepage->have_posts()) : $homepage->the_post(); ?>
<div class="pageimage"><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumbnail", $single = true); ?>&h=278&w=611&zc=1" alt="<?php the_title(); ?>" width="611" height="278" /></div>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>

<div id="blog">
<h2 class="blog">Have your say!</h2>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="entry">
<div class="entry_date"><span class="day"><?php the_time('j'); ?></span><span class="month"><?php the_time('M'); ?></span></div>
<div class="entry_thumb"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumbnail", $single = true); ?>&h=201&w=201&zc=1" alt="<?php the_title(); ?>" width="201" height="201" /></a></div>
<div class="entry_right">
<h2 class="entry_title"><?php the_title(); ?></h2>
<div class="entry_content"><p><?php the_excerpt(); ?></p></div>
<div class="entry_actions">
<a href="<?php the_permalink(); ?>" title="Continue reading <?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/readmore.jpg" height="25" width="75" alt="read more" /></a>&nbsp;
<a href="<?php the_permalink(); ?>#respond" title="Comment on <?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/leavecomment.jpg" height="25" width="110" /></a>
</div>
</div>
<div class="entry_tweets">
<a href="#"><img src="images/tweets.jpg" height="62" width="50" /></a>
</div>
<div class="cboth"></div>
</div>
<?php endwhile; ?>
<div id="pagenavigation"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?></div>
<?php endif; ?>
</div><!-- blog -->
</div><!-- .content -->

Answers (1)

2010-03-09

Ben Huson answers:

Use the WordPress is_paged() function:
http://codex.wordpress.org/Conditional_Tags#A_Paged_Page

Simply wrap you home page content in an if statement to check that the current view is not paged.

<?php if ( !is_paged() ) { ?>
<?php $homepage = new WP_Query('pagename=home'); ?>
<?php if($homepage->have_posts()) : ?><?php while($homepage->have_posts()) : $homepage->the_post(); ?>
<div class="pageimage"><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumbnail", $single = true); ?>&h=278&w=611&zc=1" alt="<?php the_title(); ?>" width="611" height="278" /></div>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php } ?>