最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Read more link isn't working with custom query

programmeradmin3浏览0评论

Trying to show the latest post with a featured tag. The query is working fine but it always shows all the content.. not the content before the more link which is all I want.

Here is my code.

$query = new WP_Query('numberposts=1&orderby=date&tag=featured');

// The loop!
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>

<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>

<div class="post-meta-bar">
    <div class="date-meta">By <?php the_author(); ?> on <?php the_time('j F Y') ?></div>
    <div class="comment-meta"><a href="<?php the_permalink() ?>#comments" rel="bookmark" title="Link to <?php the_title_attribute(); ?>"><?php comments_number( 'Remove' ); ?></a></div>
</div>

<div class="entry">
    <?php the_content('Read More'); ?>
</div>


<?php endwhile; else: ?>

<p>Sorry, no posts are featured.</p>

<?php endif; ?>

In the editor I definitely have the <!--more--> link but it always shows ALL the content.

What am I doing wrong?

Trying to show the latest post with a featured tag. The query is working fine but it always shows all the content.. not the content before the more link which is all I want.

Here is my code.

$query = new WP_Query('numberposts=1&orderby=date&tag=featured');

// The loop!
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>

<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>

<div class="post-meta-bar">
    <div class="date-meta">By <?php the_author(); ?> on <?php the_time('j F Y') ?></div>
    <div class="comment-meta"><a href="<?php the_permalink() ?>#comments" rel="bookmark" title="Link to <?php the_title_attribute(); ?>"><?php comments_number( 'Remove' ); ?></a></div>
</div>

<div class="entry">
    <?php the_content('Read More'); ?>
</div>


<?php endwhile; else: ?>

<p>Sorry, no posts are featured.</p>

<?php endif; ?>

In the editor I definitely have the <!--more--> link but it always shows ALL the content.

What am I doing wrong?

Share Improve this question edited Jun 26, 2014 at 2:07 markstewie asked Jun 26, 2014 at 1:56 markstewiemarkstewie 1731 gold badge1 silver badge6 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Finally found the answer for anyone else out there having the same problem.

Turns out for custom queries like mine using WP_Query more link functionality is OFF by default. To turn it on... this worked for me.

<?php global $more; $more = 0; the_content('Read More'); ?>

In the editor put Read More link. See in the screen shot.

发布评论

评论列表(0)

  1. 暂无评论