Solved

Custom Post Type – Year/Month Archive List

Posted on 2013-02-03
10
510 Views
Last Modified: 2013-02-05
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
Comment
Question by:Adam
  • 5
  • 3
  • 2
10 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38848733
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
 
LVL 1

Author Comment

by:Adam
ID: 38848766
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38848799
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
 
LVL 1

Author Comment

by:Adam
ID: 38848805
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
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 38849878
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:Adam
ID: 38852865
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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38853072
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
 
LVL 1

Author Comment

by:Adam
ID: 38853125
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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38853265
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
 
LVL 1

Author Closing Comment

by:Adam
ID: 38854217
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now