We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Entries Number

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I released version 1.7 of Entries Number plugin.

In this plugin a new parameter - required_field - was implemented. It is an optional parameter which allows you to specify which custom field(s) should not be empty. Pipe character is supported; “not” operator is not supported.

E.g. if we have required_field=”custom_field1|custom_field2”, then only those entries will be counted which have at least one of these fields not empty.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

There are situations when something (say, A) should be outputted if in certain weblog or category there are certain number of entries but inside A also something should be outputted (say, B) if in certain other weblog or category there are certain number of entries. Unfortunately, EE plugins cannot be nested, that is, the code as this would not work:

{exp:entries_number category="6" weblog="not weblog1|weblog4" site="1"}
{if entries_number==0}
Some code
{exp:entries_number category="9" weblog="weblog5|weblog8" site="1"}
{if entries_number>0}
Some code
{/if}
{/exp:entries_number}
Some code
{/if}
{/exp:entries_number}

In order to be able to write this kind of code I released a clone of Entries Number plugin - Entries Number2. Its code is exactly the same as that of original plugin, except that the tag name is now {exp:entries_number2} and the variable is {entries_number2}.

Having installed both Entries Number and its clone Entries Number2 you can write the code as this:

{exp:entries_number category="6" weblog="not weblog1|weblog4" site="1"}
{if entries_number==0}
Some code
{exp:entries_number2 category="9" weblog="weblog5|weblog8" site="1"}
{if entries_number2>0}
Some code
{/if}
{/exp:entries_number2}
Some code
{/if}
{/exp:entries_number}

and it will work correctly.

Grab the file of Entries Number2 using the link in the first post in thread.

       
minimal design's avatar
minimal design
356 posts
16 years ago
minimal design's avatar minimal design

I’m a little confused as to what this plugin is for (could be the lack of sleep… ;)

Here’s what I’m trying to do, would this plugin allow to output something like that?

<ul>
    <li><a href="#">category (count)</a></li>
    <li><a href="#">category (count)</a>
        <ul>
            <li><a href="#">sub-category (count)</a></li>
            <li><a href="#">sub-category (count)</a></li>
        </ul>
    </li>
    <li><a href="#">category (count)</a></li>
</ul>

Thanks!

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi, minimal design,

What means {count} in your code - number of entries posted into certain category or ordinary number of the category in the list?

       
minimal design's avatar
minimal design
356 posts
16 years ago
minimal design's avatar minimal design

yep, it mean the number of entries under each category + subcategory… These count would be restricted to the current weblog too (same categories used for several weblogs). Thanks!

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Which EE tag or plugin tag you use for ouputting your nested list of categories?

That is what is your current template code which outputs the code of your example?

       
minimal design's avatar
minimal design
356 posts
16 years ago
minimal design's avatar minimal design

I don’t have code yet, I”m trying to figure out the best way to do that. The native EE tag for nested categories is not flexible at all, so I know I need to figure out another way, I”m looking at the easiest way to have nested categories + entries count for each category, in relation to a specific weblog, but for now, haven’t implemented any code. Thanks!

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

If you can specify weblog then it seems that what you need can be achieved using exp:weblog:categories tag together with Entries Number plugin:

{exp:weblog:categories weblog="my_weblog" parse="inward" style="nested"}

{category_name},{exp:entries_number weblog="my_weblog" category="{category_id}"}{entries_number} entries{/exp:entries_number}

{/exp:weblog:categories}

If it is not possible to specify weblog then it depends on how complicated your categories are.

If you have only parent categories and subcategories, then perhaps, you could use Child Categories plugin together with Entries Number plugin; if you have subcategories which in their turn have subcategories, then perhaps, you could use Recursive Subcategories plugin together with Entries Number plugin.

       
Steptoe's avatar
Steptoe
19 posts
16 years ago
Steptoe's avatar Steptoe

Thanks for this plug-in, very helpful and just what I needed.

       
minimal design's avatar
minimal design
356 posts
16 years ago
minimal design's avatar minimal design
Hi, If you can specify weblog then it seems that what you need can be achieved using exp:weblog:categories tag together with Entries Number plugin:
{exp:weblog:categories weblog="my_weblog" parse="inward" style="nested"}

{category_name},{exp:entries_number weblog="my_weblog" category="{category_id}"}{entries_number} entries{/exp:entries_number}

{/exp:weblog:categories}
If it is not possible to specify weblog then it depends on how complicated your categories are. If you have only parent categories and subcategories, then perhaps, you could use Child Categories plugin together with Entries Number plugin; if you have subcategories which in their turn have subcategories, then perhaps, you could use Recursive Subcategories plugin together with Entries Number plugin.

I still have to do some more testing, but so far it seems to be working very well. Thanks!!!

       
Ryan 2010's avatar
Ryan 2010
265 posts
16 years ago
Ryan 2010's avatar Ryan 2010

Hi again Laisvunas,

Your plugin is working perfectly! I was wondering though…

Would you be able to add this parameter to your plugin (search:field_name=)?

ie:

search:field="fieldvalue"

Thanks, Ryan

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi Ryan,

Entries Number plugin has parameter “required_field”. Isn’t it what you need?

       
Ryan 2010's avatar
Ryan 2010
265 posts
16 years ago
Ryan 2010's avatar Ryan 2010

Hi Laisvunas,

The required_field could work for what I need, however it isn’t working. Here’s my code:

{exp:entries_number weblog="weblog1" category="24&56;" status="not closed" show_expired="no" required_field="extrainfo"}{entries_number} ads{/exp:entries_number}

I have 3 entries that would appear, I have removed content from the “extrainfo” field from one of the entries and it still counts all three entries even though only 2 of them have content in the extrainfo field.

Am I doing something wrong?

Thanks, Ryan

       
Ryan 2010's avatar
Ryan 2010
265 posts
16 years ago
Ryan 2010's avatar Ryan 2010

found the problem!

I’m using v1.5 Will upgrade now!

sorry.

       
Ryan 2010's avatar
Ryan 2010
265 posts
16 years ago
Ryan 2010's avatar Ryan 2010

ok. I’ve upgraded and got the required_field parameter to work.

I’ve noticed that my queries shoot up to from 50 to 260 queries when I implement the required_field once on my page. Is this a bug? If I use the plugin 4 times on my page I get over 1000 queries taking place.

The number of queries seem to be relative to the number of entries being counted. for example, if I have 100 entries I’ll have 100 queries plus the standard EE queries for a template.

Ryan

       
1 2 3 4 5

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.