custom page with post content using read more
You’re actually doing this in a way that is far more complicated than necessary. The foreach
is actually excessive. What you want to do is something more like this:
$args = array(
'posts_per_page' => '-1',
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $quicksand_categories
);
$query = new WP_Query( $args );
if ($query -> have_posts() {
while ($query -> have_posts() {
$query -> the_post();
// Do your display stuff here
}
}
This puts the Post object in a global $post
variable, so now you can easily use functions like the_title()
or the_permalink()
to print content without passing around an ID value to a bunch of echo
calls.
For example:
where you have: <a href="<?php echo get_permalink($item->ID); ?>">
You can now have: <a href="<?php the_permalink(); ?>">
Or, instead of $item->post_content
, you can just use the_excerpt();
Ultimately, the_excerpt()
is what you want to use in this case. Here’s a link to the codex entry. There are also some good examples there of how to customize it to your liking (like including a custom “read more” link).