Creating a count for number of classifieds posted in submenus

On our Freehuckleberryads website we have a series of 11 different menu items at this point in time.

How do we generate the number of entries shown in a category?

i.e. If you mouse over the Freehuckleberry Ads tab > then General> a selection will come to the right with different choices to pick such as
Firearms and Ammunition
Fishing Equipment
Free Items
And on down the line with other items. As items are posted to this various subheadings from people is there a way to generate how many items are posted in the post. For example if Firearms and Ammunition has 3 then it will show 3 items there, if Fishing equipment has 3 it will show there are 3 posts there, If Free Items has 6 is will show 6 and so forth thru the different menu selections.

Thank
Doug

  • Ash

    Hi there

    Thanks for rating my answer, maybe I didn't explain better - apologize.

    Sorry for your frustration here. In fact, the number of classifieds will be shown when you will use a category shortcode in page. But what you want to do is to show in menu. This is totally different. Menu items are not classifieds option, rather it is a core WP feature.

    When you will use a shortcode, then the plugin will render the shortcode and process the data as the developer wish. But in the menu, we have no control to merge with classifieds number. As this will be different for each users' cases. That's why I said it will need custom development that is applicable only for your system. Please, you need to understand the scope here.

    I have just checked your some threads and I noticed that whenever possible we (including me) have gave you custom code. If you search in the forum, you will see more complex stuffs too.

    Hope you understand. Please feel free to ask anything if you have any confusion. I will try my best to help you.

    Cheers
    Ash

  • Ash

    Hi there

    You will get all the shortcodes in Classifieds > Settings > Shortcode tab.

    If you use [cf_list_categories style="list"] or [cf_list_categories style="grid"] shortcode, then you can show the number.

    Please go to /wp-content/plugins/classifieds/core/functions.php line no 43 and 44, you will see:

    $output .= "<li>\n";
    		$output .= '<h2><a href="' . get_term_link( $category ) . '" title="' . __( 'View all posts in ', CF_TEXT_DOMAIN ) . $category->name . '" >' . $category->name . "</a> </h2>\n";

    Replace these lines with:

    $args = array(
    			'post_type' => 'classifieds',
    			'posts_per_page' => -1,
    			'post_status' => 'publish',
    			'tax_query' => array(
    				array(
    					'taxonomy' => 'classifieds_categories',
    					'field' => 'slug',
    					'terms' => $category->slug
    				)
    			)
    		);
    		$query = new WP_Query( $args );
    
    		$output .= "<li>\n";
    		$output .= '<h2><a href="' . get_term_link( $category ) . '" title="' . __( 'View all posts in ', CF_TEXT_DOMAIN ) . $category->name . '" >' . $category->name . "</a> (". $query->post_count . ") </h2>\n";

    Let me know if it works for you.

    Cheers
    Ash

  • Huckleberry Press

    Hello Ash<

    I put the shortcode here into my classified ad page:

    [cf_list_categories style="list"]

    I copied the above code you so kindly provided for me into the functions.php file at the file location you provided. I now notice that I can see a count of the number of ads when going to my classified category pages.

    Is this what the codes you supplied and the code I copied into the classified ad page now allows me to see?

    Or should I be seeing the count somewhere else too?

    I really appreciate you help!!

    Thanks
    Doug

  • Ash

    Hi there

    Thanks for the points :slight_smile:

    The shortcode you used is creating the list of categories, but no count number. The code I provided is generating the count number. Also, you can the number in anywhere you use this shortcode.

    Please note that, this changes will be lost in next update. So it's worth to note down this changes somewhere and apply again after your updates.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • Huckleberry Press

    Hello Ash!

    Question 1:
    Great! I guess I don't quite follow about how I could use this somewhere else? Confused on what you are trying to explain here? Is there somewhere else I could generate a count? Please explain.

    Question 2:
    Thank you for the heads up on the update. Is there a way to put this into my "Child Theme" so when an update comes I won't loose this code?

    I really appreciate your help!

    Thank you.
    Doug

  • Ash

    Hi there

    #1: The content you see (the category list and the number) is generated by that shortcode. I have integrated the count number in that shortcode with the above code. Now anywhere you will use the shortcode you can see that number, but in no other place you can see.

    #2: I am afraid plugins can not be used as child theme. You need to note down the changes and add again after updating the plugin.

    Though I have marked this as a feature request.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.