【问题标题】:read more link only when excerpt of content is available in wordpress仅当 wordpress 中提供内容摘录时阅读更多链接
【发布时间】:2015-02-20 19:56:01
【问题描述】:

我正在制作一个包含帖子的主页,有时帖子只有特色图片而没有内容,有时帖子同时包含特色图片和内容。当帖子有可用内容时,我想用阅读更多按钮显示帖子的摘录。我添加了一个阅读更多按钮,但它甚至与没有任何内容的帖子一起显示。只有当有可用于内容的摘录时,我才能显示它。这是摘录 div 的代码。

<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>

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    问题解决了…… 如果将来有人需要它,请在这里。

    只需在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'); ?>
    

    【讨论】:

      【解决方案2】:
      <?php the_content( $more_link_text , $strip_teaser ); ?> 
      

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

      Source

      【讨论】:

      • 现在它在首页显示帖子的全部内容,而不是摘录。
      • 如果您正确完整地阅读了源代码,您将得到问题的答案
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 2017-04-04
      • 2015-02-04
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多