0

I have my home page set to a static page with a custom page template. Here I want to show posts, but just the excerpts with a "Read more" link. I want to use the more tag, which is a part of wordpress so I hate the fact that this doesn't work! If I simplify the code that would be it:

while ( $q->have_posts() ) : $q->the_post();
    $the_exc = get_the_excerpt();
    echo $the_exc;
endwhile;

So how do I convince wordpress that on my home page I just want to show the excerpts (until the more tag). And this is like 75th time I'm dealing with this the_excerpt, the_content, issue. How do you guys do this?

1 Answer 1

1

Based on this...

... I just want to show the excerpts (until the more tag).

... it sounds like what you want is to show the post content up to the <!--more--> tag, rather than the excerpt proper which is hand-written into a special field. To do that, you need to use the_content()/get_the_content() rather than the excerpt cousin functions, and you need to have the global variable $more set correctly, but that is not hard to do.

$q = new WP_Query(array('post_type'=>'post'));

global $more;

while ( $q->have_posts() ) {
  $q->the_post();
  $more = 0;
  $the_exc = get_the_content();
  echo $the_exc;
}

The technique is explained in the Codex.

1
  • nice! now I'll never need to pull my hair again because of this! btw I edited your answer a bit..
    – user568021
    Commented Apr 27, 2014 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.