• Resolved mr_sheen

    (@mr_sheen)


    Hi

    I’m new to using WordPress and whereas I’m computer literate and have some experience with coding, none of this is with WordPress…so be gentle ??

    What I’m trying to find is a way to display an archive menu on the sidebar of my Blog page for posts on my site that are assigned to my ‘Blog’ category. Like this:

    Archive
    April 2010
    March 2010
    February 2010
    etc.

    I’ve tried searching this site, Google, and have installed dozens of Widgets but have yet to come across a way that works for my site.

    The ‘Query Posts’ Widget has been the nearest thing to what I want, but it just lists the titles of the posts in the sidebar.

    Would appreciate any help with this, or pointing in the right direction. Apologies if there’s another post here for it, but I’ve tried a number of searches with a variety of keywords and nothing that’s similar to this was coming up.

    Thanks in advance.
    Chris
    https://www.chris-seddon.co.uk/category/blog/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter mr_sheen

    (@mr_sheen)

    Thanks for the link. I installed this but not too sure where I need to paste the <?php wp_get_archives(‘cat=1’); ?> section of code. I tried in Category.php but it caused an error when I checked the page.

    Any chance of a little more help in what to do with this? Thanks.

    It depends on whether you are using widgets or not. For this, it would be easier not to use the widgets, and instead paste that line into sidebar.php.

    Thread Starter mr_sheen

    (@mr_sheen)

    aha, cool. added it to the sidebar.php file and it appears fine.

    sorry to be a pain, but is there any simple coding I can add to that line that would give it a title that appears above the months? Also, is there anyway to amend this so that the archive list only appears on 1 page of my site? At the moment it’s showing on all of them.

    appreciate the help though. thanks.

    Where on your site did you put the archive list? I’m not seeing it.

    Thread Starter mr_sheen

    (@mr_sheen)

    oh, sorry, I took it off until I’d sorted it so that it was appearing on just the Blog page like I wanted. should i put it back up there for you?

    Yes, if you could put it back temporarily, it will make it easier for me to answer your questions.

    Thread Starter mr_sheen

    (@mr_sheen)

    okay, it’s back on there. thanks again. ??

    I see it now. Do you want that to display only on the blog index page, or on the individual blog posts as well?

    Also, in order to implement the fix I have in mind, you’ll need to edit the header.php file in your theme, find the body tag, and add the body_class function, like this:

    <body <?php body_class(); ?>>

    Thread Starter mr_sheen

    (@mr_sheen)

    I honestly don’t mind, so whichever option is easier to do. If there’s no difference then I’d say, have the archive list displayed on the blog index page and on each post too.

    I’ve added that line into the header.php file.

    OK, here it is. This is a bit tricky, but I think it will be easier for you than trying to create custom category templates. Add these lines to the bottom of your CSS file, in this order:

    #sidebar { display: none; } /* hide the sidebar on all pages */

    body.category-blog #sidebar { display: block; } /* restore the sidebar on the blog index */

    Now, if you want the list displayed on each post as well, you’ll need to install a plugin (which I wrote just for this kind of situation):

    https://www.ambrosite.com/plugins/body-class-enhanced-for-wordpress

    Then add this line to your CSS file (after the other two):

    body.single-blog #sidebar { display: block; } /* restore the sidebar on each blog post */

    Thread Starter mr_sheen

    (@mr_sheen)

    Spot on! Works perfectly. Thank you so much for your help with this! It’s been bugging me for ages. Really appreciate you spending your time looking at this. Thanks.

    You’re welcome. I see that you installed my plugin, I’m glad it’s working for you.

    One last thing: if you want to put a title above the list, you can do it by editing sidebar.php like this:

    <h3>Archives</h3>
    <ul>
    <?php wp_get_archives('cat=1'); ?>
    </ul>
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Sidebar Post Archive By Month for Single Category’ is closed to new replies.