WordPress博客将文章日期链接到归档的方法

 WordPress博客如何将文章发布日期链接到归档 ?大部分WordPress博客都有一个基于日期的文章归档列表,但是如何提高它的曝光率以获得最好的流量却又是博主们应该思考的另一个问题。有的人可能会选择通过侧边栏小工具来显示归档,但是有的人可能不太喜欢在侧边栏显示的方式,觉得有点浪费宝贵的空间,那么有没有其他更好的解决办法呢?下面来详细来说一下如何将这些日期链接到对应的归档页面:
    1.创建发表日期的链接功能
    首先需要在主题的functions.php文件里创建一个函数和短代码:

    <?php
    add_shortcode( ‘entry-link-published’, ‘my_entry_published_link’ );
    function my_entry_published_link() {
    /* Get the year, month, and day of the current post. */
    $year = get_the_time( ‘Y’ );
    $month = get_the_time( ‘m’ );
    $day = get_the_time( ‘d’ );
    $out = ”;
    /* Add a link to the monthly archive. *
    / $out .= ‘<a href=”‘ . get_month_link( $year, $month ) . ‘” title=”Archive for ‘ . esc_attr( get_the_time( ‘F Y’ ) ) . ‘”>’ . get_the_time( ‘F’ ) . ‘</a>’;
    /* Add a link to the daily archive. */ $out .= ‘ <a href=”‘ . get_day_link( $year, $month, $day ) . ‘” title=”Archive for ‘ . esc_attr( get_the_time( ‘F d, Y’ ) ) . ‘”>’ . $day . ‘</a>’;
    /* Add a link to the yearly archive. */
    $out .= ‘, <a href=”‘ . get_year_link( $year ) . ‘” title=”Archive for ‘ . esc_attr( $year ) . ‘”>’ . $year . ‘</a>’;
    return $out;
    }
    ?>
    2.在主题里使用发布的链接
    在主题functions.php添加完函数之后,现在需要在主题里使用这个函数。所有的主题可能或多或少都有点不同,这里不能确切告诉你该把下面的代码添加在哪里,不过可以肯定的是它必需在循环里使用:

    <?php echo my_entry_published_link(); ?>
    如果你使用的是一个超级智能的主题,如Hybrid,可以使用上面的 [entry-link-published] 短代码,如果你不是使用类似Hybrid的主题,想了解如何在主题模板里运行短代码,可以试试下面的代码:

    <?php echo do_shortcode( ‘[entry-link-published]’ ); ?>

    此时,你可能会问这样做有什么好处呢?其实主要有4个好处:

    (1)让读者更加容易访问到你的文章归档,这也是挽留住读者的一种方式。
    (2)这也算给博客稍微打扮下,是一件挺有意思的事情。
    (3)可以让读者轻松地通过年月日找到归档。
    (4)不占据博客的任何空间。