Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:56:48+00:00 2026-06-11T13:56:48+00:00

I’m trying to create a blog archive list which shows all articles by year

  • 0

I’m trying to create a blog archive list which shows all articles by year and month (which I’ve done with PHP/MySQL)

Now I’m trying to make it so that on page load, all years are collapsed except the latest year/month and also that each will collapse/expand on click.

At the moment my jQuery click function will open or close all of the li elements rather than just the one I click. I’m still pretty new to jQuery so am not sure how to make it just affect the list section that I click on.

Any help would be grand!

Here’s my code so far (the list is generated from PHP/MySQL loops)

<ul class="archive_year">
<li id="years">2012</li>
    <ul class="archive_month">
        <li id="months">September</li>
            <ul class="archive_posts">
                <li id="posts">Product Review</li>
                <li id="posts">UK men forgotten how to act like Gentlemen</li>
                <li id="posts">What Do Mormons Believe? Ex-Mormon Speaks Out</li>
                <li id="posts">Here is a new post with lots of text and a long title</li>
            </ul>
        <li id="months">August</li>
            <ul class="archive_posts">
                <li id="posts">A blog post with an image!</li>
            </ul>
    </ul>
<li id="years">2011</li>
    <ul class="archive_month">
        <li id="months">July</li>
            <ul class="archive_posts">
                <li id="posts">New Blog!</li>
            </ul>
    </ul>
<li id="years">2009</li>
    <ul class="archive_month">
        <li id="months">January</li>
            <ul class="archive_posts">
                <li id="posts">Photography 101</li>
            </ul>
    </ul>
</ul>​

And here is the jQuery so far:

$(document).ready(function() {

//$(".archive_month ul:gt(0)").hide();

$('.archive_month ul').hide();

$('.archive_year > li').click(function() {
    $(this).parent().find('ul').slideToggle();
});

$('.archive_month > li').click(function() {
    $(this).parent().find('ul').slideToggle();
});


});

I was experimenting with the $(“.archive_month ul:gt(0)”).hide(); but it didn’t work as expected, it would switch the open and closed around.

Any help/thoughts?

Also, here is a fiddle for live example: http://jsfiddle.net/MrLuke/VNkM2/1/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:56:49+00:00Added an answer on June 11, 2026 at 1:56 pm

    First about the issues:

    1. ID-s must be unique!
    2. You have to properly nest your <li>-s

    And here is how you can solve the problem – DEMO

    jQuery

    $('.archive_month ul').hide();
    
    $('.months').click(function() {
        $(this).find('ul').slideToggle();
    });
    

    HTML (fixed)

    <ul class="archive_year">
    <li class="years">2012
        <ul class="archive_month">
            <li class="months">September
                <ul class="archive_posts">
                    <li class="posts">Article 1</li>
                    <li class="posts">Article 2</li>
                    <li class="posts">Article 3</li>
                    <li class="posts">Article 4</li>
                </ul>
            </li>
            <li class="months">August
                <ul class="archive_posts">
                    <li class="posts">Article 1</li>
                </ul>
            </li>
        </ul>
    </li>
    <li class="years">2011</li>
        <ul class="archive_month">
            <li class="months">July
                <ul class="archive_posts">
                    <li class="posts">Article 1</li>
                </ul>
            </li>
        </ul>
    </li>
    <li class="years">2009</li>
        <ul class="archive_month">
            <li class="months">January
                <ul class="archive_posts">
                    <li class="posts">Article 1</li>
                </ul>
            </li>
        </ul>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.