我有一个名为“博客”的自定义帖子类型,在我的模板中,我循环浏览博客类型并执行以下操作,
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="news">
<h2 class="title"><?php echo strtolower(the_title()); ?></h2>
<h4><?php userphoto_the_author_thumbnail();?> Posted By <?php the_author(); ?> - <?php the_date("l jS M Y"); ?></h4>
<p class="tags">
<?php $tags = wp_get_post_tags($post->ID); ?>
<?php foreach ($tags as $tag) : ?>
<a href="<?php echo $tag->slug; ?>"> <?php echo $tag->name; ?> </a> |
<?php endforeach; ?>
</p>
<?php the_content("Read More"); ?>
</section>
<?php endwhile; endif; ?>
我的帖子包括以下内容,
Hello World I am teaser
<!--more-->
Hello World I am a the content
我希望输出如下所示,
Hello Word I am teaser
<a href="link_url">Read More</a>
然而,我得到的是:,
Hello World I am teaser
Hello World I am a the content
SO网友:Jeremy Jared
尝试用以下方式替换现有内容:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="news">
<h2 class="title"><?php echo strtolower(the_title()); ?></h2>
<h4><?php userphoto_the_author_thumbnail();?> Posted By <?php the_author(); ?> - <?php the_date("l jS M Y"); ?></h4>
<p class="tags">
<?php $tags = wp_get_post_tags($post->ID); ?>
<?php foreach ($tags as $tag) : ?>
<a href="<?php echo $tag->slug; ?>"> <?php echo $tag->name; ?> </a> |
<?php endforeach; ?>
</p>
<?php the_excerpt(); ?>
</section>
<?php endwhile; endif; ?>
然后将其添加到函数中。php替代了现在用于more标记的内容(如果存在):
<?php
function all_excerpts_get_more_link($post_excerpt) {
return \'\' . $post_excerpt . \'\' . \'<span class="readmore"><a href="\'. get_permalink($post->ID) . \'">\' . \'Read More\' . \'</span>\';
}
add_filter(\'wp_trim_excerpt\', \'all_excerpts_get_more_link\');
?>