[SOLVED] Number of CGBlog articles

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm

[SOLVED] Number of CGBlog articles

Post by nervino »

Hello,
in my template I put

Code: Select all

{CGBlog category="events"}
I need to know the number of CGBlog items showed (maybe, there could be only 1 or 2 articles for that category), in order to use it to adapt a div height in the template.
For example, if that tag will output 3 items, I need that number in a smarty variable.

Which is the best way to do it?

thanks
Last edited by nervino on Thu Feb 27, 2014 12:32 pm, edited 1 time in total.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: Number of CGBlog articles

Post by JohnnyB »

You can assign it to a variable in your summary template

Code: Select all

{capture assign='articlecount'}{$items|@count}{/capture}
Then use {$articlecount} in your page/template. When using the category parameter, it should count just the articles available for that category.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
zaidcrowe
Forum Members
Forum Members
Posts: 109
Joined: Wed Jun 10, 2009 3:43 pm

Re: Number of CGBlog articles

Post by zaidcrowe »

I have'nt used this for a while - but i think this will use the Summary template to create it's output (if not the following should still be of use!)

In the template look for something like:

{foreach from=$items item=entry}

To get the number of items and assign it to a variable use:

{assign var="cat_count" value=$items@|count}

To use that variable in your template simple use:

{$cat_count}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Number of CGBlog articles

Post by velden »

Code: Select all

{assign var="cat_count" value=$items@|count}
should be

Code: Select all

{assign var="cat_count" value=$items|@count}
I guess
zaidcrowe
Forum Members
Forum Members
Posts: 109
Joined: Wed Jun 10, 2009 3:43 pm

Re: Number of CGBlog articles

Post by zaidcrowe »

im either blind - or their both the same...
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Number of CGBlog articles

Post by velden »

small change: @| vs. |@
zaidcrowe
Forum Members
Forum Members
Posts: 109
Joined: Wed Jun 10, 2009 3:43 pm

Re: Number of CGBlog articles

Post by zaidcrowe »

ahhh - interesting - is that a smarty 3 thing, or a different function - swear I always used my version and it was ok :S
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: Number of CGBlog articles

Post by JohnnyB »

not a smarty 3 thing because smarty 3 doesn't need the @.
Smarty 2 does though
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
zaidcrowe
Forum Members
Forum Members
Posts: 109
Joined: Wed Jun 10, 2009 3:43 pm

Re: Number of CGBlog articles

Post by zaidcrowe »

thanks for the info :)
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm

Re: Number of CGBlog articles

Post by nervino »

Thank you All!
Post Reply

Return to “Modules/Add-Ons”