简体   繁体   English

仅当在wordpress中有内容摘录时,才能阅读更多链接

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

i am working on a homepage which includes post, sometimes the post is only with featured image and no content, and sometime there is post with both featured image and content. 我正在一个包含帖子的主页上工作,有时该帖子仅包含特色图片,而没有内容,有时有时会同时包含特色图片和内容。 i want to show excerpt with the post with a readmore button when there is content available with the post. 当帖子有可用内容时,我想用readmore按钮显示帖子的摘录。 i have added a read more button but it even shows with the post which don't have any content. 我添加了一个“更多阅读”按钮,但它甚至与帖子一起显示,其中没有任何内容。 how can i show it only when there is excerpt available for content. 我只有在有内容摘录时才能显示它。 here is the code for the excerpt div. 这是摘录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>

the question is solved... here if anyone want to need it in future. 这个问题已经解决了……如果有人将来需要它的话。

just add this code in functions.php 只需在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 ); ?> 

The $more_link_text sets the link text like "Read More". $more_link_text将链接文本设置为“阅读更多”。 The second one, $strip_teaser , sets whether or not the "more" link should be hidden (TRUE) or displayed (FALSE). 第二个$strip_teaser设置“更多”链接是隐藏(TRUE)还是显示(FALSE)。 The default is FALSE, which shows the link text. 默认值为FALSE,它显示链接文本。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM