• KrisRhoades

    (@thewellministries)


    I am new to WordPress and to PHP although I have learned alot in the past two months I have been setting up my blog. This forum has helped me more times than I can tell you but I have searched and searched for my particular problem and cannot find an answer.

    I use parent categories and sub-categories. I would like to list all of the categories with the sub-categories under them, indented. I have tried all options using list_cats to no avail. So to hack my own problem I just listed each of the parent categories with their sub-categories under as you can see in the sidebar of my blog: https://www.thewellministries.org/blog with the remaining categories listed using list_cats and using exclude to not list the above categories.

    By using this method though I cannot get a post count on the categories I have listed individually. I have tried every hack and suggestion found in these forums but none work. (the only one I found that I thought would work was <?php echo $postsincat; ?> but it didn’t either)

    Also I have tried the list_cats and exclude for each section but it shows a post count of (0) even if there are posts in the category. Only the first category section shows the post count and all others show (0)s (see sidebar1.php)

    I have looked for a post-count plugin but have not found one yet.

    Any suggestions?

    Thanks,
    Kris

Viewing 9 replies - 1 through 9 (of 9 total)
  • Anything here to help?
    https://linux.linux.dk/projects/

    Thread Starter KrisRhoades

    (@thewellministries)

    Nope, tried them all. They count comments, users, characters, words, categories, the total number of posts in the entire blog, but not posts in the categories.

    Any other thoughts?

    Here I use Template_Tags/wp_list_cats and styled the nested lists in the stylesheet. It displays even the sub-sub-categories indented.

    Thread Starter KrisRhoades

    (@thewellministries)

    That looks like what I had in mind to use but I am unable to determine just how you did this to recreate it. Would you please post the exact info you used to set this up?

    Thanks

    You have to keep in mind 2 things (at least:)
    – WP generates “list in list” i.e. nested lists for the subcategories (like ul ul ul li)
    – you have to define the style for those nested lists in the style.css
    Hint: when you are not sure what code is generated by WP, always take a look at the source code of the blog when displayed in the browser. You can download that theme from the link above and take a look at the stylesheet’s #sidebar lists section.

    Thread Starter KrisRhoades

    (@thewellministries)

    moshu,

    Thanks for your answers but I tried and tried and could not get it to work. For some reason I just could not figure out the CSS to make the parent headings and the children and the lines between each work together. I was getting some extra lines after each parent section and no line under the parent listing. Needless to say, I gave up and resigned to have it the way I already did.

    I did, however, fix my own problem before totally giving up. It just took some time. One thing you did steer me towards was wp_list_cats, which, with a little effort, worked as I wanted it to when list_cats would not. (I did not need to add anything to the CSS and used the arguments.) The template I had used the list_cats but for some reason the arguments did not work as I had wanted them to. Also if anyone is interested, to get it to work as I wanted when using the wp_list_cats I was not able to use the “exclude all but the categories I wanted” but instead I had to use the “child_of” argument listing the parent category and then exclude any other category in that parent category that I didn’t want, which actually was better in the long run as I wasn’t typing so many numbers in the argument. I don’t know why it didn’t work that way but it could have something to do with the fact that my parent categories never have any posts but are just there for organizing. These may be bugs in the program or something that I was doing wrong but either way I’ve now got it to look like I wanted.

    Thread Starter KrisRhoades

    (@thewellministries)

    For anyone that is trying the same thing, here is the code I used. Might not be the best code but I figure posting it here might make someone’s life a little easier, even though you won’t learn as much this way. I would have much rather been writing in my blog than trying code after code till one worked.

    a href=”index.php?cat=xx”>Category_Name</a

      <?php wp_list_cats(‘sort_column=name&sort_order=asc&optioncount=1&hide_empty=0&children=1&child_of=x&exclude=zz’) ?>

    xx=Category_ID#
    zz=any sub categories to exclude
    I put one line for each of my parent categories.
    Be sure to put the opening and closing < > on the first line but I didn’t include it so it would print here.

    to get category counts to show in
    https://www.girlgeekette.net/
    on the left menu

    i edited wp-includes/template-functions-category.php
    so that

    if (!isset($r[‘optioncount’])) $r[‘optioncount’] = 0;

    to say
    if (!isset($r[‘optioncount’])) $r[‘optioncount’] = 1;

    ———-
    oops, I just read the last post you made where you said you fixed it, sorry!

    meetjustin

    (@meetjustin)

    The option count trick worked for me – thank you!!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Post Count in Categories’ is closed to new replies.