フォーラムへの返信

5件の返信を表示中 - 1 - 5件目 (全5件中)
  • フォーラム: 使い方全般
    返信が含まれるトピック: 特定のカテゴリに属するタグ一覧を表示させたい
    トピック投稿者 mimumu0000

    (@mimumu0000)

    色々と検索していたら、このコードを見つけました。

    ほぼほぼやりたいことはできたのですが、
    ここから任意の件数分表示したい場合どのようにしたらいいでしょうか?

    <?php
    
    function nestmenu( $args ) {
    
        $nestmenu = '';
    
        if ( ! isset( $args['exclude'] ) ) {
            $args['exclude'] = '';
        }
    
        $opt = array(
            'hide_empty'   => true,
            'exclude_tree' => $args['exclude']
        );
    
        $cat_array = get_categories( $opt );
    
        $nestmenu  = "<div id='nestmenu'>\n";
        $nestmenu .= "<ul class='nestmenu-category'>\n";
    
        foreach ( $cat_array as $key => $cat ) {
    
            $cat_name = $cat->name;
            $cat_num = $cat->count;
            $cat_link = get_category_link( $cat->term_id );
            $tag_array = nestmenu_relation($cat->term_id);
    
            $nestmenu .= "<li><h2><a href='$cat_link' title='$cat_name'>$cat_name ($cat_num)</a></h2></li>\n";
            $nestmenu .= "<ul class='nestmenu-tag'>\n";
    
            foreach ( $tag_array as $tags ) {
    
                foreach ( $tags as $tag ) {
    
                    $tag_link = esc_url( home_url( '/' ) . '?cat=' . $cat->term_id . '&tag=' . $tag['slug'] );
                    $nestmenu .= "<li><a href='$tag_link' title='$tag[name]'>$tag[name] ($tag[count])</a></li>";
    
                }
    
            }
    
            $nestmenu .= "</ul>\n";
    
        }
    
        $nestmenu .= "</ul>\n";
        $nestmenu .= "</div>\n";
    
        return $nestmenu;
    
    }
    add_shortcode( 'nestmenu', 'nestmenu' );
    add_filter( 'widget_text', 'do_shortcode' );
    
    function nestmenu_relation( $term_id = false ) {
    
        if ( $term_id === false ) {
            return $term_ids;
        }
    
        $taxonomy = get_terms(
            array(
                'category',
                'post_tag'
            ),
            array(
                'hide_empty' => true,
                'include'    => $term_id
            )
        );
    
        $taxonomy = $taxonomy[0]->taxonomy;
    
        if ( ! is_null( $taxonomy ) ) {
    
            $args = array(
                'nopaging'            => 1,
                'ignore_sticky_posts' => 1,
                'order'               => 'ASK',
                'tax_query'           => array(
                    array(
                        'taxonomy' => $taxonomy,
                        'terms'    => $term_id,
                        'field'    => 'id',
                        'operator' => 'AND'
                     )
                )
            );
    
            $my_query = new WP_Query( $args );
    
            if( $my_query->have_posts() ) {
    
                if ( $taxonomy === 'category' ) {
                    $taxonomy = 'post_tag';
                } else {
                    $taxonomy = 'category';
                }
    
                while ( $my_query->have_posts() ) : $my_query->the_post();
    
                    $term = get_the_terms( get_the_ID(), $taxonomy );
    
                    if ( $term ) {
    
                        foreach ( $term as $value ) {
    
                            if ( ! isset( $term_ids['term'][$value->term_id] ) ) {
    
                                $term_info = array(
                                    'id'   => $value->term_id,
                                    'name' => $value->name,
                                    'slug' => $value->slug,
                                );
    
                                $term_ids['term'][$value->term_id] = $term_info;
    
                            }
    
                            $term_ids['term'][$value->term_id]['count'] += 1;
    
                        }
    
                    }
    
                endwhile;
    
                wp_reset_query();
    
            }
    
            if ( $term_ids['term'] ) {
    
                $term_ids['term'] = array_merge( $term_ids['term'] );
    
                foreach ( $term_ids['term'] as $key => $value ) {
                    $key_id[$key] = $value['count'];
                }
                array_multisort( $key_id, SORT_DESC, $term_ids['term'] );
    
            }
    
        }
    
        return $term_ids;
    }
    
    ?>
    トピック投稿者 mimumu0000

    (@mimumu0000)

    すみません、お教えいただいたことがやっとわかりました!
    勉強不足で申し訳ございませんでした。
    解決済みとします。

    フォーラム: 使い方全般
    返信が含まれるトピック: ターム内の子カテゴリ記事一覧を表示させたい
    トピック投稿者 mimumu0000

    (@mimumu0000)

    何度もすみません、
    色々と調べていたら、
    http://q.hatena.ne.jp/1382148601
    にたどりつき、無事表示されましたので、解決済みにいたします。

    フォーラム: 使い方全般
    返信が含まれるトピック: ターム内の子カテゴリ記事一覧を表示させたい
    トピック投稿者 mimumu0000

    (@mimumu0000)

    すみません、
    「一つの子カテゴリ」の一覧ではなく、
    「一つのターム内の、全子カテゴリの見出しと一覧」
    でした。
    わかりにくくて申し訳ございません。

    トピック投稿者 mimumu0000

    (@mimumu0000)

    早速のご回答ありがとうございます。

    テーマは「ビズベクトル」で、

    <?php
    $args = array(
    	'show_option_none'		=> '',
    	'title_li'				=> '',
    	'taxonomy' 				=> 'albumcate',
    	'orderby'				=> 'order',
    	'echo'					=> 0    /* 直接出力させない為 */
    );
    $catlist = wp_list_categories( $args );
    if ( !empty($catlist) ) { ?>
    	<div class="localSection sideWidget">
    	<div class="localNaviBox">
    	<h3 class="localHead">カテゴリー</h3>
    	<ul class="localNavi">
        <?php echo $catlist; ?>
    	</ul>
    	</div>
    	</div>
    <?php } ?>

    となっております。
    何度も申し訳ございませんが、よろしくお願いいたします。

5件の返信を表示中 - 1 - 5件目 (全5件中)