自定义邮政类型订单标题ASC

时间:2012-10-21 作者:ogni

我想按标题(如“Merecedes”)和从最低到最高的顺序(如“A级”)“ASC”显示所有汽车制造商。它应该看起来像一个词汇表。

页码:汽车。。。

宝马:
1er
2er
3er
。。。

梅赛德斯:
A级
B级
C级
。。。

Z

这是我的custom-port-type-cars.php

<h2>Mercedes</h2>
    <?php $args = array( \'post_type\' => \'cars\', \'posts_per_page\' => -1, \'orderby\' => \'title\', \'order\' => \'ASC\', 

    // ============================= Mercedes ==============================
        \'tax_query\' => array(
            array(
                \'taxonomy\' => \'manufacturer\',
                \'field\' => \'slug\',
                \'terms\' => array(\'mercedes\')
            )
        )
    );

    // ============================= OUTPUT ==============================
    $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();
        the_title(\'<h3>\', \'</h3>\');
        the_content();
    endwhile; ?>


<h2>BMW</h2> 
    <?php $args = array( \'post_type\' => \'cars\', \'posts_per_page\' => -1, \'orderby\' => \'title\', \'order\' => \'ASC\', 

    // ============================= BMW ==============================
        \'tax_query\' => array(
            array(
                \'taxonomy\' => \'manufacturer\',
                \'field\' => \'slug\',
                \'terms\' => array(\'bmw\')
            )
        )
    );


    // ============================= OUTPUT ==============================
    $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();
        the_title(\'<h3>\', \'</h3>\');
        the_content();
    endwhile; ?>
这对我不起作用。我不能同时订购标题和条款。

感谢您的帮助

1 个回复
最合适的回答,由SO网友:Mridul Aggarwal 整理而成
$index = \'A\';
$terms = get_terms(\'manufacturer\');

foreach ($terms as $term) {
    if($index != strtoupper(substr($term->name, 0, 1))) {
        $index = strtoupper(substr($term->name, 0, 1));
        echo \'<h1>\'. $index . \'</h1>\';
    }
    ?>
    <h2><?php echo $term->name; ?></h2>
    <?php $args = array( \'post_type\' => \'cars\', \'posts_per_page\' => -1, \'orderby\' => \'title\', \'order\' => \'ASC\', 
        \'tax_query\' => array(
            array(
                \'taxonomy\' => \'manufacturer\',
                \'field\' => \'slug\',
                \'terms\' => array($term->slug)
            )
        )
    );

    // ============================= OUTPUT ==============================
    $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();
        the_title(\'<h3>\', \'</h3>\');
        the_content();
    endwhile;
}
结束

相关推荐

Invalid Taxonomy in template

我已经浏览了这里涉及同样错误的帖子,没有任何运气。我有一个自定义的帖子类型(Staff)和它的自定义分类法。编制员工职位和分配术语很有效,但我想根据分类术语将所有员工分组列出。但是the terms do not come through.模板文件位于此处:http://pastie.org/4372363的(相关部分)功能。php文件位于此处:http://pastie.org/4372367我为什么不能这样做?结果如下所示:<div class=\"content\"> &