任何人都可以知道如何在菜单中添加月份存档以及不同部分的一些自定义值。 这里有wordpress过滤器添加菜单。
function add_archive($items, $args) {
$items1 .= '<a href="#">archives</a><ul class="sub-menu">';
$items1 .= get_archives('monthly', '12', 'custom','<li>','</li>', FALSE,0);
$items1 .= '</ul></li>';
return str_replace('<a href="#">archives</a></li>',$items1,$items);
}
?>
HTML输出我正在寻找存档菜单,如下所示......
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-619" id="menu-item-619">
<a href="#">Archive</a>
<ul class="sub-menu" style="display: none;">
<div class="drop-dowm">
<div><a href="/2015/05">May 2015</a></div>
<div><a href="/2015/04">April 2015</a></div>
<div><a href="/2015/03">March 2015</a></div>
<div><a href="/2015/02">February 2015</a></div>
<div><a href="/2015/01">January 2015</a></div>
<div><a href="/2013/12">December 2013</a></div>
<div><a href="/2013/11">November 2013</a></div>
</div>
<div class="drop-dowm">
<div><a href="/2013/10">October 2013</a></div>
<div><a href="/2013/09">September 2013</a></div>
<div><a href="/2013/08">August 2013</a></div>
<div><a href="/2013/07">July 2013</a></div>
<div><a href="/2013/06">June 2013</a></div>
<div><a href="/2013/05">May 2013</a></div>
<div><a href="/2013/04">April 2013</a></div>
</div>
<div class="drop-dowm">
<div><a href="/2013/03">March 2013</a></div>
<div><a href="/2013/02">February 2013</a></div>
<div><a href="/2012/10">October 2012</a></div>
<div><a href="/2012/06">June 2012</a></div>
<div><a href="/2012/05">May 2012</a></div>
<div><a href="/2012/03">March 2012</a></div>
<div><a href="/2011/12">December 2011</a></div>
</div>
</ul>
</li>
plz help ..
答案 0 :(得分:1)
您有两个return
来电
您正在追加$items1
而未声明。
最重要的是,你没有说明你面临的问题。
答案 1 :(得分:-1)
在这里,我得到了自己的问题的解决方案。可能对其他人有所帮助。
<?php
add_filter( 'wp_nav_menu_items', 'add_archive');
function add_archive($items, $args) {
$l = 0;
$ar = '';
$ar = '';
$ar .= '<li class="parent-category"><a href="#">archives</a><ul class="sub-menu">';
global $wpdb;
$months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'post' GROUP BY month , year ORDER BY post_date DESC");
foreach($months as $month)
{
if($l==0)
{
$ar .= '<div class="drop-dowm">';
}
elseif($l % 7 ==0)
{
$ar .= '</div><div class="drop-dowm">';
}
$ar .= '<div>';
$ar .= '<a href="'.get_bloginfo('url').'/'. $month->year.'/'.$month->name.date("m", mktime(0, 0, 0, $month->month, 1, $month->year)).'">'.date("F", mktime(0, 0, 0, $month->month, 1, $month->year)).' '. $month->year.'</a>';
$ar .= '</div>';
$l++;
}
$ar .= '</ul></li>';
$items1 .= $ar;
return str_replace('<a href="#">archives</a></li>',$items1,$items);
}
?>