单一类别的日期订购存档页面?

时间:2014-02-12 作者:user47499

下面的代码可以按日期顺序归档帖子。但我不知道如何改变这一点,所以它只会吸引一类帖子。

Link

非常感谢您的帮助

<?php

//* Template Name: Custom Archive

//* Remove standard post content output
remove_action( \'genesis_post_content\', \'genesis_do_post_content\' );
remove_action( \'genesis_entry_content\', \'genesis_do_post_content\' );

add_action( \'genesis_entry_content\', \'sk_page_archive_content\' );
add_action( \'genesis_post_content\', \'sk_page_archive_content\' );
/**
 * This function outputs posts grouped by year and then by months in descending order.
 *
 */


function sk_page_archive_content() {

    global $post;

        $lastposts = get_posts(\'numberposts=-1\') ;
        $year = \'\';
        $month = \'\';
        foreach($lastposts as $post) :
            setup_postdata($post);

            if(ucfirst(get_the_time(\'F\')) != $month && $month != \'\'){
                echo \'</ul></li>\';
            }
            if(get_the_time(\'Y\') != $year && $year != \'\'){
                echo \'</ul></li>\';
            }
            if(get_the_time(\'Y\') != $year){
                $year = get_the_time(\'Y\');
                echo \'<li><h2>\' . $year . \'</h2><ul class="monthly-archives">\';
            }
            if(ucfirst(get_the_time(\'F\')) != $month){
                $month = ucfirst(get_the_time(\'F\'));
                echo \'<li><h3>\' . $month . \'</h3><ul>\';
            }

        ?>
            <li>
                <span class="the_date"><?php the_time(\'d\') ?>:</span>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            </li>
        <?php endforeach; ?>

        </ul>
        <?php           
}

remove_action( \'genesis_entry_footer\', \'genesis_entry_footer_markup_open\', 5 );
remove_action( \'genesis_entry_footer\', \'genesis_post_meta\' );
remove_action( \'genesis_entry_footer\', \'genesis_entry_footer_markup_close\', 15 );

genesis();

1 个回复
SO网友:stemie

也许您可以将类别添加到此行:

$lastposts = get_posts(\'numberposts=-1&category=7\');
将7替换为您需要使用的任何类别ID。

链接到WordPress Codex页面get_posts() - Parameters.

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register