Add a "post-counter" by category on your nav-menu (8 posts)

  1. cavimaster
    Posted 5 years ago #

    >>>>>>>> IN "NAV-MENU.PHP" ADD

    function post_count($cat,$depth){
    global $wpdb;
    $post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=$cat;");
    for ($i=0;$i<$post_count;$i++){
    $post_count_id[$i] = $wpdb->get_var("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id=$cat;");
    $post_cont_pub[$i]= $wpdb->get_var("SELECT * FROM $wpdb->posts WHERE post_status='publish' AND ID=$post_count_id[$i];");
    if($post_cont_pub[$i]){ $a++; }
    if ($depth=='1'){
    $post_count= sprintf("%02d", $a);
    return '<span>_'.$post_count.'</span> ';}


    found >>> $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    replace by >>>> $item_output .= $args->link_before . apply_filters( 'the_title', post_count($item->object_id,$depth).$item->title, $item->ID ) . $args->link_after;

  2. Jackxugao
    Posted 5 years ago #

    hi, cavimaster

    I downloaded your private categories plugin. From the description of this plugin: "A login will then appear on the selected category page". How can I let the login area showing on the selected category page ? when I click the category name "History" in my site, the page shows "no pages found".


  3. cavimaster
    Posted 5 years ago #

    Hi Jack,

    Perhaps you have not created a post or page in the history class?

    Complies with the procedure:

    - create a category [X]
    - go to the plugin settings and make it private
    - create at least one article (private) and assign it to category [X]

    When you click to go to a login category [X] then appears

  4. Erve1879
    Posted 5 years ago #

    Cavimaster - can you help me with the code - I couldn't find nav-menu-template.php
    and I wasn't sure which instance of nav-menu.php I should be editing...


  5. cavimaster
    Posted 5 years ago #

    Hi Erve1879,

    you can found "nav-menu-template.php" and "nav-menu.php" in wp-include, not inside the theme folder.

    see ya

  6. Erve1879
    Posted 5 years ago #

    Thanks cavimaster - I tried the code, but it didn't work. I followed your instructions to the t, emptied the cache and reloaded the page.

    The sub-menu items had "_00" or "_02" before them, but the main nav items had nothing....

    I assume your code just isn't compatible with the theme I'm using....?

    Thanks for your help!

  7. Nenad1389
    Posted 4 years ago #

    Great hack. Thank you very much!

  8. cavimaster
    Posted 4 years ago #

    Thank you Nenad1389!

    In the same way, i fund a better code on the web. Am sorry but i dont remember the name of the original source...
    So, it's almost the same.


    Obviously this solution disappears if you made the WP next update

    See ya

Topic Closed

This topic has been closed to new replies.

About this Topic