views:

19

answers:

2

I'm trying to have a post from a certain category display on my static homepage.

I seem to everything working just how I'd like with one exception.

I'd like the post to included the standard Continue reading (<!--more-->) link, but I can't seem to get it to work on my homepage instead all the post's content is displayed.

Here's the code I'm using to display the one post from a catagory on my home page:

<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php the_content( __( 'Continue reading &rarr;')); ?>
<?php endwhile; ?>

How do I get the <!--more--> tag to work correctly with the above code?

+1  A: 

The <!--more--> quicktag generally doesn't work on anything other than the Home page. Try following the advice here under "How to Read More in Pages", i.e. like this:

<?php
global $more;
$more = 0;
?>
//The code must be inserted ahead of the call to the content

Then continue as you were:

<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php the_content( __( 'Continue reading &rarr;')); ?>
<?php endwhile; ?>

Though I'm not sure if you'll need to set $more to 0 before every the_content() call; I don't know whether it's reset every time through The Loop or not.

The discussion topic referenced from that Codex entry talks about exactly the problem you're solving, I think.

Matt Gibson
A: 

I was able to find some information here: http://codex.wordpress.org/Function_Reference/the_content

Found these lines which seem to do the trick:

global $more;    // Declare global $more (before the loop).
$more = 0;       // Set (inside the loop) to display content above the more tag.
the_content("Read More");

Added the information to my code and everything work! Added in the Read More link when the more tag was added to the post.

Here's my final code:

<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php global $more;
$more = 0;
the_content("Read More");
 ?>
Adam