1 of 2
1
Can you use the {exp:weblog:entries} tag inside the {exp:weblog:categories} tag?
Posted: 16 July 2007 09:28 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

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="{path="stockists/listing/{segment_3}/C{category_id}}">{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

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 17 July 2007 04:32 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

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="{path="stockists/paint-listing/{segment_3}/C{category_id}}">{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”?

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 26 September 2007 04:54 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

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 : (

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 27 September 2007 03:14 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  597
Joined  10-22-2006

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

Profile
 
 
Posted: 27 September 2007 03:24 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

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

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 27 September 2007 05:07 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  597
Joined  10-22-2006
Mikee Bee - 27 September 2007 03:24 AM

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…

Profile
 
 
Posted: 27 September 2007 05:18 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

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?

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 27 September 2007 05:41 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
RankRankRank
Total Posts:  597
Joined  10-22-2006

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

Profile
 
 
Posted: 27 September 2007 06:18 AM   [ Ignore ]   [ # 8 ]  
Research Assistant
RankRankRank
Total Posts:  597
Joined  10-22-2006

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

Next problem wink

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?

Profile
 
 
Posted: 27 September 2007 07:00 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

Spot on my boy, except its four columns

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 27 September 2007 08:02 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

@Mikee Bee - I’m posting this from another thread (http://expressionengine.com…) 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}<br />
{/exp:query}

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 27 September 2007 08:22 AM   [ Ignore ]   [ # 11 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

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

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 27 September 2007 08:31 AM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

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://www.alistapart.com…), but the easiest is probably:

<style type="text/css" media="screen">
    
ul.col { width:100px; float:left; }
</style>

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 27 September 2007 08:37 AM   [ Ignore ]   [ # 13 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

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.

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 27 September 2007 08:39 AM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

@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).

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 27 September 2007 08:44 AM   [ Ignore ]   [ # 15 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  318
Joined  03-07-2006

Done that, still nothing. Do you mind if I PM you a login so you can have a quick peak?

 Signature 

· Confused… but happy ·

Profile
 
 
Posted: 27 September 2007 08:46 AM   [ Ignore ]   [ # 16 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

@Mikee Bee - Sure thing!

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 27 September 2007 08:53 AM   [ Ignore ]   [ # 17 ]  
Research Assistant
RankRankRank
Total Posts:  597
Joined  10-22-2006

Then the one thing that is missing is, that to make colums with even height, we do not only need the total number of categories, like on that page you linked, but also the total number of entries in each category ...

Profile
 
 
Posted: 27 September 2007 09:03 AM   [ Ignore ]   [ # 18 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1184
Joined  01-05-2006

@Mikee Bee - Alright, I took a peak at your query and I was wrong to call `exp_weblog_categories` it should be `exp_categories`.  That seemed to fix it.  The only other thing you may need is to limit your categories by group: so add in c.cat_group=X like so:

{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 c.group_id=X 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}<br />
{/exp:query}

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65027 Total Logged-in Users: 23
Total Topics: 82117 Total Anonymous Users: 16
Total Replies: 441316 Total Guests: 192
Total Posts: 523433    
Members ( View Memberlist )