?
Solved

Custom Post Type – Year/Month Archive List

Posted on 2013-02-03
10
Medium Priority
?
518 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
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 1000 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
 
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

752 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