• I feel like I’ve exhausted all searches on this subject & still not found one definitive answer! I have a client who needs to display a list of archives by month & with count within a menu. However, because they have also used posts to categorize client case study pages, they only wish to display a list of posts in the menu from one category & by month & with count;

    January 2012 (7)
    December 2011 (2)
    etc..

    I have tried pretty much every suggestion so far on this forum on this subject but with no luck s yet. This article did manage to get the list itself to appear correct but when the links were clicked, archives from all categories appeared again! I imagine that’s down to WP not being able to differentiate between archive categories when also dividing into months.

    I was wondering whether if the archive.php page within my theme could be made to filter only 1 category’s results?

    Anyways, any advise or suggestions would be most welcome!

    Many thanks in advance.

Viewing 11 replies - 31 through 41 (of 41 total)
  • Thread Starter deeve

    (@deeve)

    ..solved the month output in list πŸ™‚
    http://pastebin.com/nKBwW017

    Okay deeve,
    Let’s first take a look at the link you’ve constructed here:
    http://pastebin.com/RTtmBM5U

    I’ve cleaned it up a little here:
    http://pastebin.com/LTXHFW5S

    Now, why were you putting ‘2956’ at the beginning of your link? After you create a new Page in your WordPress it give you a slug under the title. That slug should be what your link starts with.

    Example:
    If I create a new Page in my WordPress Page section called “Category by Month Archive”, assign it the tmpl-archive-cat-month.php as its template, and publish it – it gives me a slug of “http://MY-DOMAIN.com/category-by-month-archive/”. That is what you would start you link with:

    bloginfo( 'url' ) gives your site’s domain WITHOUT the trailing slash, and after that you can enter the slug (look in my link and you’ll see my placeholder.

    How’s this make sense?

    Cleaned up the code you gave me: http://pastebin.com/nKBwW017

    Awesome job getting the month name in there, btw! I’m gonna use that in the future.

    Here’s my cleaned up version, still needs the page slug and I didn’t think $monthNum was a necessary variable: http://pastebin.com/kTHJiiPJ

    Finally, cleaned up and left you some notes in the first link you sent this evening (http://pastebin.com/vX9hjy44) right over here:
    http://pastebin.com/dDRQQyEF

    Hopefully I closed all those <div>s correctly, and didn’t totally fuck it up πŸ˜›

    Thread Starter deeve

    (@deeve)

    Wow! Many thanks for all the advice & for tidying up my crude code – point taken on my use of line break’s πŸ˜‰ Have just tried your suggestions & now have an interesting conundrum: If I use the template page’s slug ‘category-archive’ within the list href attribute I get the following in the url:

    /category-archive?month=5&year=2011&cat=7

    & WP says the page does not exist. But if I use the page’s post ID of 2956 [us in url: ‘post.php?post=2956&action=edit’ when in WP Admin], I get this in the url

    /2011/?month=5&cat=7

    & do see posts, just too many.

    I’m wondering if this may have something to do with my site’s permalink structure which is set to custom & ‘/%category%/%postname%/’ or whether it’s not & the year is being dropped some other way?

    Well test going to the page you set up from the WordPress admin. There’s a button that says “View Page” and it will send you to that page (just without any of the parameters it needs to spit out posts). Does that work? Or do you get a “page does not exist” message?

    If it works, try adding some testing echo lines in a few places like echo 'this is the category archive page!'; but put it near the top of the template code (outside any while or if statements. Refresh the page. It should still not give you any posts but those echo lines should appear. Whether it does or not will tell us if this URL is using the template you want it to or not.

    Once you have it printing the test lines, try adding a query string into the end of the URL. Something you know will give you posts, like ‘?month=5&year=2011&cat=7’. And see if you get posts. It could be that you misstyped the URL.

    ALso, can I get the URL of this page? I’ll try adding some parameters to it as well.

    Thread Starter deeve

    (@deeve)

    Since my last post I did try what you mention above & did get a positive result using the page slug ‘category-archive’ & without the query string but obviously this outputs the last archive [which happens not to be in category 7]. When I add a query string I get a page not found error.

    So imagine that suggests the query string is not being evaluated correctly by the page query? I’ll email you the page link as is a client’s dev server & not for public viewing.

    The list is outputted within the ‘Our Blog’ link in the side nav. It’s currently within an accordion menu [which is not the final version] – I’ll have a page specific dynamic menu in the final design but this shouldn’t effect testing.

    me [at] [my username] [dot] com

    Thread Starter deeve

    (@deeve)

    ..couldn’t find your email on here so maybe if you don’t mind, drop me a line:

    at = @
    steve at vidiwell.co.uk

    & I’ll get back in touch with that page link.

    Thread Starter deeve

    (@deeve)

    As promised, here’s the working code which iamgarrett kindly perfected. After testing the previous code, we realised month & year vars were not unique. Once changed to $themonth & $theyear the Queries worked perfectly together. Now all I have to do is figure a way out to output just the latest post on the initial template page load, which seems like it should be some form of conditional code above the template query:

    Menu query:
    http://pastebin.com/TwzJgmKa

    Template query:
    http://pastebin.com/B2uH5C0a

Viewing 11 replies - 31 through 41 (of 41 total)
  • The topic ‘List of posts from specific category by month & with count?’ is closed to new replies.