Php Wordpress显示在条目页脚中阅读更多信息

Php Wordpress显示在条目页脚中阅读更多信息,php,wordpress,Php,Wordpress,以下是我想做的: 我有一篇博客文章,我只想显示到一个特定的点。所以在我的帖子里 <!--more--> 在正确的位置上 My content.php如下所示: <div class="entry-content"> <?php the_content('read more'); ?> </div><!-- .entry-content --> <footer class="entry-footer">

以下是我想做的:

我有一篇博客文章,我只想显示到一个特定的点。所以在我的帖子里

<!--more-->

在正确的位置上

My content.php如下所示:

<div class="entry-content">
    <?php the_content('read more'); ?>
</div><!-- .entry-content -->

<footer class="entry-footer">
    <?php mytheme_entry_footer(); ?>
</footer><!-- .entry-footer -->

“阅读更多”链接将显示在内容的后面。但是如何在带有“注释”链接的条目页脚中显示它呢

摘录有解决方案吗

<?php the_excerpt(); ?>


我认为这样会更好,因为我不需要在每篇文章中都加上这一行。

您可以在
函数中使用以下过滤器删除“read more”。php

add_filter( 'the_content_more_link', 'remove_more_link', 10, 2 );

function remove_more_link( $more_link, $more_link_text ) {
    return;
}
现在,您可以在条目页脚内创建自己的“阅读更多”链接:

<footer class="entry-footer">
    <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">Read more</a>
    <?php mytheme_entry_footer(); ?>
</footer><!-- .entry-footer -->

编辑:

在下面的评论中,提出了以下问题:

我使用了_摘录()而不是_内容()。如果文章太长,是否可以只显示链接

您可以通过检查摘录是否与内容不同来实现这一点。如果是这种情况(因此内容比摘录显示的要多),您可以显示“阅读更多”链接:

<?php if ( get_the_content() != get_the_excerpt() ){ ?>

    <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">Read more</a> 

<?php } ?>

我使用一种解决方法:

//REMOVE 'MORE' LINK AND HARDCODE IT INTO PAGE - TEASER JUST PLAIN ELLIPSIS
function modify_read_more_link() {
    if ( is_front_page() ) {
        return '...';
    } else {
        return '</div><footer class="clearfix"><a class="mg-read-more" href="' . get_permalink() . '">Continue Reading <i class="fa fa-long-arrow-right"></i></a>';
    }
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );

这对我来说很好。我使用了_摘录()而不是_内容()。如果文章太长,是否可以只显示链接?(超过55个字符)@HansUllrich也许你可以检查摘录的长度(
get\u extract()
)是否等于内容的长度(
get\u content()
)。如果它们不同,您可以显示“阅读更多”链接。好的,如果我设置条件“获取内容”,它将始终显示链接。另一方面,它不显示链接。如果我问它们是否相等,我会得到以下错误:“不能在写上下文中使用函数返回值”@HansUllrich刚刚在我的答案中添加了一个示例。刚刚测试过这个,它应该可以工作。