西门的后花园

一个热爱网络的年轻人的博客

WordPress博客首页不显示整篇文章的两种方法

今天分享一下博客首页不显示整篇文章的两种方法。这两种方法也是以前在别人那里学习过来的,弄了自己的博客后,记录下来,需要的朋友可以参考一下。我的博客首页用的是第二种方法。

方法一:

就在编辑文章的上面,找到“插入‘More’标签(Alt+Shift+T)”你想首页显示那一段,就在那段后面加上这个,方法很简单,就是每次编辑文章不能忘记按了。

WordPress博客首页不显示整篇文章的两种方法

方法二:

在你主题文件夹下面的index.php页面,找到一段类似

<?php the_content(__(‘More &gt;&gt;’)); ?>

的代码,如果找不到,Ctrl+F找

php the_content

一般只会有一句这个代码,这一排代码就是输出整篇文章内容的。换成:

<?php
        if(has_excerpt())
                {the_excerpt();?>
                <a rel=”more-link” href=”<?php the_permalink() ?>”  title=”<?php the_title(); ?>”>&gt;&gt;阅读全文&lt;&lt;</a>
                <?php }
        else {
                echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 500,”……”); ?>
                                <a rel=”more-link” href=”<?php the_permalink() ?>”  title=”<?php the_title(); ?>”>&gt;&gt;阅读全文&lt;&lt;</a>
<?php }//end else ?>

简单的解释下这段代码有什么用。

如果你不写编辑框下面的摘要,首页只显示文章的500个文字。如果你写了摘要,首页只显示摘要里面的内容。是不是很人性化呢?

效果看看我的首页就知道啦~~~

评论列表

  1. 沙发了 谢谢了

  2. 恩 又能折腾一下了

  3. 田瑶瑶

    非常感谢!
    如法炮制,设置成功! 😳

  4. 显示摘要?标题不太好认啊

  5. 西门大哥,我那主题不知道怎么折腾那首页文章问题,就是按照你的做了,还是不得。 😥

  6. 受用了~~~~ 😛 😛

  7. 学习了学习了~~

  8. 我目前是第一种 我觉得第一种更好写吧

  9. 逍遥醉

    😥 我还是看不太懂

  10. 大山路

    尴尬了,真的没找到您说的那段代码。index.php下全代码如下:
    <?php
    /**
    * The main template file.
    *
    * This is the most generic template file in a WordPress theme
    * and one of the two required files for a theme (the other being style.css).
    * It is used to display a page when nothing more specific matches a query.
    * E.g., it puts together the home page when no home.php file exists.
    * Learn more: http://codex.wordpress.org/Template_Hierarchy
    *
    * @package WordPress
    * @subpackage Twenty_Ten
    * @since Twenty Ten 1.0
    */

    get_header(); ?>

    <div id="container">
    <div id="content" role="main">

    <?php
    /* Run the loop to output the posts.
    * If you want to overload this in a child theme then include a file
    * called loop-index.php and that will be used instead.
    */
    get_template_part( 'loop', 'index' );
    ?>
    </div><!– #content –>
    </div><!– #container –>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

  11. 又学到了一些知识呀,就是一直都想只显示摘要啊,真是太感谢楼主了,先去尝试下!!

  12. 我也是没有找到你所说的地方哦,难道只能注定用more?哎杯具了!!

  13. 关键你说的那些代码我这没

  14. 很好的方法 支持一下

sunny进行回复 取消回复

分类目录