0

現在のページにあるかどうかに応じて、メニュー項目を強調表示しようとしています。以下のコードは、foreachループ内にあるため、現在すべてのメニュー項目を強調表示しています。特定のページIDにあり、その用語のみ(すべてではない)である場合、分類用語を強調表示するにはどうすればよいですか?

                    <?php $args = array( 'taxonomy' => 'blog' );
                        $terms = get_terms('blog', $args);

                        $count = count($terms); $i=0;
                        if ($count > 0) {
                            $cape_list = '<p class="my_term-archive">';
                            echo $postid;
                            foreach ($terms as $term) {
                                $i++;
                                $absolute = get_bloginfo('url');
                                $postid = get_the_ID();
                                if($postid == "561") {
                                    $term_list .= '<a class="menu-active" style="padding-left:30px;width:88%!IMPORTANT;" href="' . $absolute . '/blog/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';
                                } else {
                                    $term_list .= '<a style="padding-left:30px;width:88%!IMPORTANT;" href="' . $absolute . '/blog/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';
                                } } ?>

                            <?php echo $term_list; } ?>
4

1 に答える 1

1

現在のページに属する分類用語をクエリし、foreachループでそれらのIDを比較する必要があります。

このget_the_ID()関数は、現在の分類法ではなく、現在の投稿のIDを返します。

現在の分類用語をクエリする方法を示すワードプレス関連の質問へのリンクは次のとおりです。

https://wordpress.stackexchange.com/questions/20431/how-to-get-taxonomy-term-of-the-current-page-and-populate-queries-in-the-templat

于 2012-12-18T16:57:49.583 に答える