在我的WordPress网站上,我使用以下代码来循环播放我的最新帖子:
<?php
if ( is_single() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
endif;
if ( 'post' === get_post_type() ) : ?>
<div class="entry-meta">
<?php blogtristan_posted_on(); ?> <span class="loopdivide"> | <span class="loop-time"><?php the_time( 'H:i' );?></span> (GMT)
</div><!-- .entry-meta -->
<?php
endif; ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php
$post = $post->post_content; /* or you can use get_the_title() */
$getlength = strlen($post);
$thelength = 200;
echo substr($post, 0, $thelength);
if ($getlength > $thelength) echo "...";
?>
如何为每个循环项添加一个简单的“Read more”按钮?
答案 0 :(得分:1)
请尝试使用以下代码
if (strlen($getlength) > 200) {
echo '<a href="' . get_the_permalink(get_the_ID()) . '" title="">Read more</a>';
}else{
echo $post;
}