在官方 Wordpress 主题二十十五中,我们在 content.php 文件中有以下代码:
<div class="entry-content">
<?php
/* translators: %s: Name of current post */
the_content( sprintf(
__( 'Continue reading %s', 'twentyfifteen' ),
the_title( '<span class="screen-reader-text">', '</span>', false )
) );
wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfifteen' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>%',
'separator' => '<span class="screen-reader-text">, </span>',
) );
?>
</div><!-- .entry-content -->
我正在尝试将自定义样式应用于“继续阅读”链接(并且仅链接),但问题是“继续阅读”已经是具有“条目内容”样式的 div 的一部分。
最好我希望在其他地方有“继续阅读”,但我很困惑该怎么做。
我不太熟悉 PHP,老实说,这可能是这里的主要问题。我花了大约一个小时试图研究如何做到这一点,但我可能没有经验来理解我正在阅读的内容。
已解决:编辑/更新:
以下代码对我有用。这将插入阅读更多链接:
<div class="more-link">
<a href="<?php the_permalink(); ?>">Read more</a>
</div>
我也改了:
the_content( sprintf(
__( 'Continue reading %s', 'twentyfifteen' ),
the_title( '<span class="screen-reader-text">', '</span>', false )
为此:
the_content('');
最佳答案
您可以用引号 (the_content('')) 替换 sprint_f 部分,并使用 the_permalink() 将阅读更多链接放在任何您想要的地方
这是一个例子:
<div class="entry-content">
<?php
/* translators: %s: Name of current post */
the_content('');
?>
<a href="<?php the_permalink(); ?>">Read more</a>
<?php
wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfifteen' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>%',
'separator' => '<span class="screen-reader-text">, </span>',
) );
?>
</div><!-- .entry-content -->
关于php - 自定义 wordpress 25 主题 - 基本 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33368004/