WordPress.org

Forums

[resolved] create special drop down menu (2 posts)

  1. hcvitto
    Member
    Posted 5 years ago #

    Hi
    i'm trying to make a navigation menu with this form:

    <ul id="mainNav">

  2. All posts
  3. in other words i need a menu which lists all the years and for each year all its posts ordered by title.
    Do you think it is possible?

    Thanks Vitto

  • hcvitto
    Member
    Posted 5 years ago #

    thanks to

    http://wpguy.com/articles/an-archives-page-with-all-the-posts-in-cronological-order/

    i got to this solution

    <ul id="mainNav">
          <li><a href="">Archive</a>
          	<ul>
            <?php
    		// Declare some helper vars
    		$previous_year = $year = 0;
    		$ul_open = false;
    		// Get the posts
    		$myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC');
    		foreach($myposts as $post) :
                // Setup the post variables
                setup_postdata($post);
                $year = mysql2date('Y', $post->post_date);
    			if($year != $previous_year) :
    				if($ul_open == true) : ?>
                        </ul></li>
                    <?php endif; ?>
                <li><?php the_time('Y'); ?>
                <ul class="month_archive">
    			<?php $ul_open = true;
    			endif;
    			$previous_year = $year;?>
                    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    		<?php endforeach; ?>
            </ul></li></ul></li>
    
        </ul>
  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags