【发布时间】:2016-12-10 16:26:49
【问题描述】:
我正在使用最新版本的 WordPress 开发网站。
我的网站设置为首页显示最新帖子。
摘录显示了每个帖子的全部内容。 如何缩短这些内容并为每个内容添加一个阅读更多链接?
以下是每个帖子的循环播放内容:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?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(); ?>
</div><!-- .entry-meta -->
<?php
endif; ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php
the_content( sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( 'Continue reading %s <span class="meta-nav">→</span>', 'blogtristan' ), array( 'span' => array( 'class' => array() ) ) ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
) );
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'blogtristan' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php blogtristan_entry_footer(); ?>
</footer><!-- .entry-footer -->
【问题讨论】:
-
这是你的 index.php 吗?你试过the_excerpt()函数了吗?
-
这是因为你使用了the_content()函数,它返回整个帖子内容
-
好的,我已经把它改成了 。它现在只显示部分内容。如何添加阅读更多链接?