Support » Plugins » Add a "post-counter" by category on your nav-menu

  • >>>>>>>> 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;

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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”.


    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

    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…


    Hi Erve1879,

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

    see ya

    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!

    Great hack. Thank you very much!

    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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add a "post-counter" by category on your nav-menu’ is closed to new replies.