• Hi,

    I just want to say what a fantastic plugin Catablog is. Everything has worked perfectly for me and the documentation on the illProductions website has been great.

    Is there is a way to retrieve a count of the number of items listed in a category? For example, to use in an IF statement, to hide a link if there are no items listed?

    It’s probably worth noting that my catablog listings are brought up in the site purely through the use of the catablog_show_items() function.

    I’ve searched through the support forum and documentation but can’t seem to find a solution. I hope I haven’t missed something simple!

    Any help would be great! Thanks in advance for your time and this great plugin!

    Regards,

    Will

    http://wordpress.org/extend/plugins/catablog/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi PixelDrake,

    If you just want to display the number of items per category, there is a widget “CataBlog Categories”, which allows you to display the categories on your sidebar and enable the number of items per category.

    Kind regards

    Thread Starter PixelDrake

    (@pixeldrake)

    Hey Mbrsolution,

    Thanks for your reply. To be a bit more specific, this is what I’m trying to do:

    <? if ($categoryquantity >= ‘1’) echo(‘example text’); ?>

    So that example text only appears if there is at least one item in the specified category. I just can’t figure out a way to count the number of items in a category and make it a variable.

    The website I’m developing does not contain many of the standard wordpress elements like a side bar. The catablog categories are accessed via a panel of custom buttons. I’d like to use similar php to the above so the buttons only appear for categories that have items in them. The items in this catalog are constantly changing and among the 5 categories there will often be a few empty ones that I’d rather not have displayed.

    Thanks again for your time, I hope this is all making sense!

    Regards,

    Will

    Hi, I see what you mean. Well I am not a developer as such and I only help were ever I can with CataBlog because the developer is busy. However since I want to learn PHP 🙂 I found something on the CataBlog folder that might help you or point you in the right direction.

    /**
    	 * Template function for fetching a single catalog item by id
    	 *
    	 * @param integer $id The id of a catalog item to fetch
    	 * @return CataBlogItem|NULL Returns a CataBlogItem object if a catalog item was found, otherwise NULL
    	 */
    	function catablog_get_item($id=false) {
    		if (is_numeric($id) && $id > 0) {
    			return CataBlogItem::getItem($id);
    		}
    		return null;
    	}
    
    }
    if (version_compare(phpversion(), '5.0.0', '>=')) {
    	catablog_load_plugin();
    }

    Maybe instead of fetching an item you can set it up to fetch a category.

    I have also found this link , with many category functions that might help you set up your concept.

    Kind regards

    Thread Starter PixelDrake

    (@pixeldrake)

    Well I got my dynamic menu working, though not in a very conventional manner haha.

    After many failed attempts at more complex solutions I realised I could just make custom templates that would act as the buttons themselves.

    Here is the php I use to display each button in case it helps anyone else:

    <? if ($category == ‘Boats’) {catablog_show_items(boats, selected, menu_order, ascending, IN, 1, false);} else {catablog_show_items(boats, menu, menu_order, ascending, IN, 1, false);} ?>

    One template is called ‘selected’ and represents the currently selected category. ‘menu’ is the other template, which includes a hyperlink. I use the %CATEGORY% tag in the templates to fill out the button label, category img src and hyperlink.

    It’s a bit hacky, but hey it works! The biggest problems are that these ‘buttons’ now share the catablog-catalog style with the actual catalog items, and that it uses capitals in the %CATEGORY% tag.

    I’d still love to know if there’s an easier way to do this though, as this method is a bit… special.

    Thanks again for your responses Mbrsolution.

    Well done PixelDrake, I am glad you got it working. One question where did you place the php code?

    Kind regards

    Thread Starter PixelDrake

    (@pixeldrake)

    Anywhere you want the menu button to appear on your page really. Below is the ‘menu’ template, which should explain things a bit better.

    <a href="index.php?page=localstock&category=%CATEGORY%#Selection"><div class="btnLocalStock"><img src="images/png%CATEGORY%.png" /><br />%CATEGORY%</div></a>

    The ‘selected’ template is basically the same but minus the hyperlink and with a different image/class.

    The php in my previous post determines if it will display a ‘menu’ or ‘selected’ template based on the current $page. Then using the catablog_show_items() function with a single post limit, it displays a single copy of the template if there are any items in that category.

    Thank you for the information, I am sure someone might use this information to implement your idea.

    You might want to create a tutorial on your website or blog in a more detail manner. I am sure many would appreciate it very much.

    If your issue is resolved could you close it.

    Kind regards

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: CataBlog] Category Item Counts in php’ is closed to new replies.