• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

Custom Post Type – Year/Month Archive List

Hi there,

I'd like to create a list of archive links to the years/months that I have a post for a particular custom post type. I haven't quite been able to figure it out. Here is essentially what I'm looking for:

<ul>
  <li><a href="#">2013</a>
    <ul>
      <li><a href="#">January</a></li>
      <li><a href="#">February</a></li>
    </ul>
  </li>
  <li><a href="#">2012</a>
    <ul>
      <li><a href="#">November</a></li>
    </ul>
  </li>
</ul>

Open in new window

Any help would be greatly appreciated. Thanks!
0
Adam
Asked:
Adam
  • 5
  • 3
  • 2
1 Solution
 
COBOLdinosaurCommented:
What exactly are you expecting from that code.  All I see are a serious of links to the top of the page.  If you are trying to go to a particular position in the page then you put an id on the target and then use the id in the link like this:
href="theid#"

This article will show you how to style targets

Cd&
0
 
AdamAuthor Commented:
Sorry COBOLdinosaur, but I think you're misunderstanding what I'm asking. I guess what I didn't make clear in my question is that I'd like to do this for my Wordpress site.

In the sidebar on my site, I want to display links for the years/month of all the posts for a particular post-type. So when a user clicks let's say "2013", it will take them to an archive page that shows them all posts from 2013. If they select "November 2012", they will go to an archive page for all November 2012 post, etc....

The sample code I added to my question was just to demonstrate the structure of what I wanted. I guess I could have just written something like this:

2013
-- January
-- Feburary

2012
-- November
-- December

etc..

So I'm looking for some code that will create a list similar to this. Does that make sense?
0
 
COBOLdinosaurCommented:
I don't really do much Wordpress support, and I don't understand why a simple list would be difficult.  So the best I can do is post some links dealing with Wordpress archives.  

http://wordpress.org/extend/plugins/custom-post-archives/
http://mark.mcwilliams.me/wordpress/custom-post-type-archives/
http://en.support.wordpress.com/archives-shortcode/
http://wpguy.com/articles/an-archives-page-with-all-the-posts-in-cronological-order/
http://yoast.com/wordpress-archive-pages/

Perhaps an Expert who is actively supporting Wordpress will come along with more detailed help.

Cd&
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AdamAuthor Commented:
Thanks for the links Cd&. I am familiar with Wordpress and have searched around for solutions but can't seem to find one that does exactly what I'm looking for.

Hopefully someone else will come along and help out. Thanks anyway.
0
 
Jason C. LevineNo oneCommented:
Here's a fix.  It's raw code directly in in your template though...

http://www.wpbeginner.com/wp-themes/how-to-customize-the-display-of-wordpress-archives-in-your-sidebar/
0
 
AdamAuthor Commented:
Thanks jason1178! I think this will work for my purposes. One small thing though—the code generates something along the lines of this:

<ul>
  <li><a href="#">2013</a></li>
  <li><a href="#">January</a></li>
  <li><a href="#">February</a></li>
  <li><a href="#">2012</a></li>
  <li><a href="#">December</a></li>
</ul>

Open in new window

However, I am hoping to have the structure of the unordered list like the following:

<ul>
  <li><a href="#">2013</a>
    <ul>
      <li><a href="#">January</a></li>
      <li><a href="#">February</a></li>
    </ul>
  </li>
  <li><a href="#">2012</a>
    <ul>
      <li><a href="#">December</a></li>
    </ul>
  </li>
</ul>

Open in new window

I thought that I just needed to make a slight modification to the code but I can't seem to get it to work. Any suggestions?
0
 
Jason C. LevineNo oneCommented:
It's not the easiest thing in the world to do given how the foreach loop is constructing the entries.  This is why they specifically give you a CSS solution to offset the years from the months.  I would urge you to keep that intact and use CSS to indent month <li> tags or otherwise make them stand out from year <li> tags.
0
 
AdamAuthor Commented:
Thanks jason178, however, the years/months need to go in a drop-down menu (you hover over the year then a sub-menu appears with the archive months) and it would have been much easier to work with if the lists were structured the way I presented them in my question. Also, the structure I'm looking for would be better semantically and for accessibility purposes.

Sorry if I'm being a bit picky. I do appreciate the help.
0
 
Jason C. LevineNo oneCommented:
That's alright.  From my end, though, I don't have the time or inclination to pull apart the foreach loop and test see if the element is first/last and then add the extra <ul> tags as needed.  You may want to close this now (with or without points, your call) and repost the foreach code in the PHP TA and see if someone there is willing to rewrite it for you.
0
 
AdamAuthor Commented:
Thanks again for the help jason1178. I will create a new question as you suggested and hopefully someone will be able to help modify the code to get it to where I need.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now