ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Can you use the {exp:weblog:entries} tag inside the {exp:weblog:categories} tag?

July 16, 2007 12:28pm

Subscribe [3]
  • #1 / Jul 16, 2007 12:28pm

    Mikee Bee

    179 posts

    Hi all, I’m using Mark Huot’s “Custom Fields in {exp:weblog:entries /}” extension. To have a page that only displays entries with a certain custom field checked as Yes.

    To give you a little background the site is for company that have hundreds of stockists of their various products. There are 5 types of products that each potentially can stock

    FABRICS, WALLPAPERS, PAINTS, PAINT POTS, TRIMMINGS & FURNITURE

    Some stock fabrics and wallpapers, some only stock furniture etc.

    I have set up a number of checkboxes (each a seperate custom field) that my client can ‘tick off’ what the stockist offers. This then via conditionals displays a little icon that shows what they stock.

    I use the extension to have a page that only show people who stock FURNITURE (if furniture has been selected in the entry). This works great on the page with the entries on but *all the entries are in categories* (which are regions across the world) so I need to be able to have a page that displays ONLY the categories that have entries with the custom field marked as Yes in the entries tag.

    This is the entries code, you can see that the last part that stipulates if the {stockist-paint} custom field is marked with Yes the entries show.

    {exp:weblog:entries weblog="stockists_uk|stockists_europe|stockists_world" limit="9" stockist-paint="Yes"}


    This is the categories page code

    {exp:weblog:categories weblog="stockists_uk|stockists_europe|stockists_world" show_empty="no" style="linear"}
    
    <li><a href="http://{path=">{category_name}</a></li>
    
    {/exp:weblog:categories}

    I’ve asked the maker of the extension if it can be made to work at the category level but I haven’t heard back in a while and the deadline is looming so I wondered could you use the entries tag within the categories tag to somehow use the parameters set on the entries tag affect the weblog categories tag???

    Let me know if you need any of that clarifying

    Thanks

  • #2 / Jul 17, 2007 7:32am

    Mikee Bee

    179 posts

    I’m getting closer… I found this post which answers my question about using {weblog:entries} inside {weblog:categories}. You need to {embed} the full weblog loop within the categories tag.

    So this is in my main template…

    {exp:weblog:categories weblog="stockists_uk" show_empty="no" style="linear"}
    
    <li><a href="http://{path=">{category_name}</a></li>
    
    {embed="includes/paint-weblog" paint="Yes" cat="{category_id}"}
    
    {/exp:weblog:categories}

    And this is in the include (most of it can be ignored the ONLY important bits are the parts that refer to {stockist-paint})

    <ol id="stockistslist">
    
    {exp:weblog:entries weblog="stockists_uk" paginate="bottom" limit="9" stockist-paint="{embed:paint}" category="{embed:cat}"}
    
    <li>
    <dl>
    <dt>{title}</dt>
    
    <dd>
    
        <ul class="offers">
            {if stockist-fabric == "Yes"}<li class="fabric-icon">Fabrics</li>{/if}
            {if stockist-wallpaper == "Yes"}<li class="wallpaper-icon">Wallpapers</li>{/if}
            {if stockist-paint == "Yes"}<li class="paint-icon">Paints</li>{/if}
            {if stockist-sample-pots == "Yes"}<li class="sample-icon">Paint Sample Pots</li>{/if}
            {if stockist-trimmings == "Yes"}<li class="trimmings-icon">Trimmings</li>{/if}
            {if stockist-furniture == "Yes"}<li class="furniture-icon">Furniture</li>{/if}
        </ul>
        
    </dd>
    </dl>
    </li>
    
    
    {/exp:weblog:entries}
    
    </ol>

    So at this stage my page is still showing ALL the categories from the weblog BUT its only showing entries that have a parameter met. How can I stop the categories that don’t have the parameter met stockist-paint=“Yes”?

  • #3 / Sep 26, 2007 7:54am

    Mikee Bee

    179 posts

    Has anyone got any ideas for this? Please let me know if anything needs clarifying. Could you use a query or something. I think Sue Crocker found a way to do this but I haven’t heard back : (

  • #4 / Sep 27, 2007 6:14am

    silenz

    1651 posts

    This seems to be indeed a job for a query.
    What is sort order of the categories? Alphabetical or Custom Sort Order?

  • #5 / Sep 27, 2007 6:24am

    Mikee Bee

    179 posts

    Alphabetical, also uses that category offset plugin you did : ) This is one of the pages if it helps

  • #6 / Sep 27, 2007 8:07am

    silenz

    1651 posts

    Alphabetical, also uses that category offset plugin you did : )

    Which is nice and bad at the same time :grrr:

    It’s not too hard to write a query that only pulls out the category_id’s of categories that have weblog entries in which the field stockist-paint is set to Yes.

    The problem is that this would have to replace the {exp:weblog:categories}-tag and thus your offsetting feature…

    Hm…

  • #7 / Sep 27, 2007 8:18am

    Mikee Bee

    179 posts

    Ah bummer… Quite the pickle. Defo need the listings in columns, could you offset with the queries and do say 3 or sets of tags?

    I posted a simpler version of my issue here, was Sue Crocker onto anything with her thoughts?

  • #8 / Sep 27, 2007 8:41am

    silenz

    1651 posts

    Wait.
    I think my plugin does even work without there being an {exp:weblog:categories}-tag at all :gulp:
    Let ... me ... think.

  • #9 / Sep 27, 2007 9:18am

    silenz

    1651 posts

    Well, it does work flawlessly with a query instead a categories-tag.

    Next problem 😉

    What I gather from your code above you want to create a list of counties with stockists that offer paint.

    You print the county as sub-headline.
    Below that a list of all stockists in that county.
    Then the next county as sub-headline.
    List of all stockists in that county.
    And so on.

    The output will pretty look like what exp:weblog:category_archive would do.
    But you don’t use that because you need exp:weblog:entries to only pull out the paint-stockists only.

    Then you want to split that listing into three columns.

    Correct so far?

  • #10 / Sep 27, 2007 10:00am

    Mikee Bee

    179 posts

    Spot on my boy, except its four columns

  • #11 / Sep 27, 2007 11:02am

    Mark Huot

    587 posts

    @Mikee Bee - I’m posting this from another thread (http://) because it seemed more relevant here than there.  I’m not sure if any plugins got you where you need to be but you could very easily do this with a query:

    {exp:query sql="SELECT c.* FROM exp_weblog_categories c, exp_category_posts cp, exp_weblog_data d WHERE d.field_id_XX='Yes' AND d.entry_id=cp.entry_id AND c.cat_id=cp.cat_id GROUP BY c.cat_id ORDER BY c.cat_name ASC"}
    -- category has entry with field_id_XX set to 'yes': {cat_name}
    
    {/exp:query}
  • #12 / Sep 27, 2007 11:22am

    Mikee Bee

    179 posts

    Thanks Mark, Silenz has deduced we can use a query also, the problem now is that we need the listed categories in 4 columns!

  • #13 / Sep 27, 2007 11:31am

    Mark Huot

    587 posts

    Hum.  I’d drop in a little PHP then:

    <?php $count = 1; ?>
    {exp:query sql="SELECT c.* FROM exp_weblog_categories c, exp_category_posts cp, exp_weblog_data d WHERE d.field_id_XX='Yes' AND d.entry_id=cp.entry_id AND c.cat_id=cp.cat_id GROUP BY c.cat_id ORDER BY c.cat_name ASC"}
    <?php if($count++ % 5 == 0): ?><ul class="col" start="<?php echo $count; ?>"><?php endif; ?>
    <li>{cat_name}<li>
    <?php if($count++ % 4 == 0): ?></ul><?php endif; ?>
    {/exp:query}

    Then you can use any column list method you’d like (http://), but the easiest is probably:

    <style type="text/css" media="screen">
        ul.col { width:100px; float:left; }
    </style>
  • #14 / Sep 27, 2007 11:37am

    Mikee Bee

    179 posts

    Sounds good! But before I get onto the columns (Sorry for being dumb) which parts of the query string that you gave me do I need to change as I can’t seem to get it displaying anything.

  • #15 / Sep 27, 2007 11:39am

    Mark Huot

    587 posts

    @Mikee Bee - field_id_XX should be field_id_3 (assuming when you hover over the field name in the Admin » Custom Fields section of EE the status bar shows a field_id of 3).

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases