只有在wordpress中提供内容摘录时,才能阅读更多链接


read more link only when excerpt of content is available in wordpress

我在一个包含帖子的主页上工作,有时帖子只有特色图片而没有内容,有时帖子既有特色图片又有内容。当帖子中有可用的内容时,我想用readmore按钮显示帖子的摘录。我添加了一个阅读更多按钮,但它甚至显示了没有任何内容的帖子。只有当内容有摘录时,我才能显示它。这是摘录部分的代码。

<div class="entry-excerpt">
            <?php
                    if( strlen( $post -> post_excerpt . $post -> post_content ) > 0 ){
                ?>
                        <div class="excerpt">
                            <?php
                                if( is_user_logged_in () ){
                                    the_excerpt();
                                    echo '<a href="' . get_permalink() . '" title="' . __('Continue Reading ', 'cosmotheme') . get_the_title() . '" rel="bookmark">Continue Reading</a>';
                                }else{
                                    $meta = meta::get_meta( $post -> ID  , 'settings' );
                                    if( isset( $meta['safe'] ) ){
                                        if( !meta::logic( $post , 'settings' , 'safe' ) ){
                                            the_excerpt();
                                            echo '<a href="' . get_permalink() . '" title="' . __('Continue Reading ', 'cosmotheme') . get_the_title() . '" rel="bookmark">Continue Reading</a>';
                                        }
                                    }else{
                                        the_excerpt();
                                    }
                                }
                            ?>
                        </div>
                <?php
                    }
                ?>
            </div>

问题解决了。。。如果将来有人需要的话。

只需在functions.php 中添加此代码

<?php
function new_excerpt_more($more) {
   global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>'; } add_filter('excerpt_more', 'new_excerpt_more'); ?>
<?php the_content( $more_link_text , $strip_teaser ); ?> 

$more_link_text将链接文本设置为"阅读更多"。第二个是$strip_teaser,设置"更多"链接是隐藏(TRUE)还是显示(FALSE)。默认值为FALSE,显示链接文本。