我在category部分创建了一个字段,它是category color
Codes are in different lines in file so I will paste them separately
$kategoriler_self = get_categories(array( \'hide_empty\' => false ));
foreach ($kategoriler_self as $kategori){
$this->kategoriler[$kategori->cat_ID] = $kategori->cat_name;
*
$kategoriid = $kategori;
$catquery = new WP_Query( \'cat=\' .$kategoriid. \'&posts_per_page=1\' );
while($catquery->have_posts()) : $catquery->the_post();
*
/* Cat Color Option */
$color = get_term_meta( $kategoriid, \'_category_color\', true );
$color = ( ! empty( $color ) ) ? "#{$color}" : \'#000\';
我用这个代码显示我的类别颜色
<?php echo $color; ?>
So, I want to do same thing for my menu.这是我的菜单代码。
<?php wp_nav_menu(array(\'theme_location\' => \'sidebar-kategori\', \'container\' => \'false\', \'items_wrap\' => \'<ul>%3$s</ul>\')); ?>
How can I show category color for every li in menu ?
感谢您的阅读!
UPDATE:
我找到了一篇关于我的问题的好文章,我想与大家分享。
https://digwp.com/2011/11/html-formatting-custom-menus/
SO网友:hwl
你可以add_filter()
这个wp_nav_menu_items()
钩它允许访问列表项的html输出$items
.
紧接着这个钩子wp_nav_menu_{$menu->slug}_items()
钩子,使您可以访问相同但特定的菜单。
Info on add-filter()
if you need it.
两个
wp_nav_menu_items
上下文中的相关挂钩:
They are at lines 220 and 231 of wp-includes/nav-menu-template.php
来自trac:
/**
211 * Filters the HTML list content for navigation menus.
212 *
213 * @since 3.0.0
214 *
215 * @see wp_nav_menu()
216 *
217 * @param string $items The HTML list content for the menu items.
218 * @param stdClass $args An object containing wp_nav_menu() arguments.
219 */
220 $items = apply_filters( \'wp_nav_menu_items\', $items, $args );
221 /**
222 * Filters the HTML list content for a specific navigation menu.
223 *
224 * @since 3.0.0
225 *
226 * @see wp_nav_menu()
227 *
228 * @param string $items The HTML list content for the menu items.
229 * @param stdClass $args An object containing wp_nav_menu() arguments.
230 */
231 $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );