Can anyone know how to add month archive in menu with some custom value of different part. here wordpress filter to add in menu.
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);
}
?>
The HTML output i'm looking for archive menu as follows...
<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..
here i got solution for my own question. may it help other.
<?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);
}
?>