0

現在、分類法のすべての用語を取得し、各用語の下に投稿を一覧表示するクエリを実行しています。

私がやったことはうまく働いています。「hide_empty」引数を追加してfalseに設定し、空の用語を表示できるようにしました。なんらかの理由で機能していません。

これが私の質問です:

    <?php

// List posts by the terms for a custom taxonomy of any post type

$post_type = 'streams';
$tax = 'programmes';

$tax_terms = get_terms('programmes', array(
    'hide_empty' => 0,
    'hierarchical' => 0

 ) );
if ($tax_terms) {
    foreach ($tax_terms  as $tax_term) {
    $args = array(
        'post_type' => $post_type,
        "$tax" => $tax_term->slug,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'caller_get_posts'=> 1
    );

        $my_query = null;
        $my_query = new WP_Query($args);

        if( $my_query->have_posts() ) : ?>

            <p class="breadcrumb"><?php echo $tax_term->name; ?></p>
            <ul class="taxlist">
            <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>

                <li id="post-<?php the_ID(); ?>">
                    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                </li>

            <?php endwhile; // end of loop ?>

            </ul>

        <?php else : ?>
        <?php endif; // if have_posts()
        wp_reset_query();

    } // end foreach #tax_terms
}
?>

どんな助けでも大歓迎です。

乾杯、ダン

4

1 に答える 1

2

分類用語をループしていますが、現在ループされている用語に関連付けられている投稿がない場合、何も出力していません。関係なく出力する場合$term->nameは、コードのそのセクションを次のように変更する必要があります -

$my_query = null;
$my_query = new WP_Query($args);

<p class="breadcrumb"><?php echo $tax_term->name; ?></p>

if( $my_query->have_posts() ) : ?>

    <ul class="taxlist">
于 2012-10-24T12:03:41.280 に答える