$10
Hide homepage content on blog pagination
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.
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>
<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 -->
Dan Davies | 03/09/10 at 7:57am
| Edit
(1) Possible Answers Submitted...
-

Last edited:
03/09/10
8:07amBen Huson says: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 } ?>
This question has expired.
Current status of this question: Completed





