1 of 2
1
Weblog Categories tag or Weblog Category Archive Tag?
Posted: 04 February 2008 08:53 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

I’m wanting to display categories from a weblog. I’m fairly certain that I can use either the weblog categories tag or the weblog categories archive tag, but my problem is that I’m going to have some parent categories with children under them.

These parent/child categories will be displayed as a nested list, but the parent categories will not be links, they will simply be text, with all of the children links.

I’ve tested both of the aforementioned tags, and they both do what I want to do except they both make the parent category a link.

If what I’m wanting to do isn’t possible, I believe I can do it by simply statically inserting the parent category name and then listing the child categories under the parent by using the “show=“4|7” parameter, but I’m not sure?

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 04 February 2008 09:41 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005

How about a combination of the parent_only=“yes” parameter and this wiki entry? The wiki entry uses a sql query to pull only the children.

Terry

Profile
 
 
Posted: 04 February 2008 09:46 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

hmmm, yeah I believe that could work! I don’t think I would need to use the parent_only parameter in this case since I could just manually insert the parent category into the template code and then use the query from the wiki entry below it to display the children.

I’m wondering though, if anyone else has suggestions on other ways? I’ve just read in the past that when custom queries are used, the more bandwidth that is used (although it may not worth worrying about? I don’t know?)

Thanks Terry for that. If nothing else better pops up, that should work.

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 04 February 2008 10:32 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

Actually Terry, now that I’ve had a chance to think about this solution. It might be in my best interest to use the parent_onl parameter. If I didn’t use it, I would have to manually go in and change the parent category name (if it ever changed). By using the weblog categories tag, it would all change dynamically… at least I think.

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 05 February 2008 12:27 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005

Right - using parent_only for display of the unlinked category names would give you flexibility to dynamically update any additions and changes you made to the parents categories later on. That’s what I was thinking. Then pull the children only to apply the links to them underneath each parent heading by using the sql.

Naturally, if you could do it all in a single query, it would be prettier and use fewer queries, but if the list is short to begin with and you cache your queries, it shouldn’t be much of a performance hit. And you’d retain that nice dynamic capability and not have to edit your sql ever time you added stuff.

Terry

Profile
 
 
Posted: 05 February 2008 07:31 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

Hey Terry, Thanks again for your help on this.

Yeah, starting out the list will be fairly short, but it has the potential to grow large, but it would be a while down the road. How would I go about caching my queries?

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 05 February 2008 09:17 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005

Here is the Data Caching and Performance article in the docs. Just discovered this recently myself via another thread elsewhere.

Terry

Profile
 
 
Posted: 05 February 2008 09:39 AM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

Thanks again.

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 06 February 2008 12:02 AM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

Hey Terry,

Now that I actually try this method out, I’m running into a snag.

I’m going to have my page set up like this:

Parent Category 1
-child
-child
-child

Parent Category 2
-child
-child
-child

So, with that layout, here’s what I’ve got in my template:

{exp:weblog:categories weblog="instruction" parent_only="yes"}
        
<h3>{category_name}</h3>
        
{/exp:weblog:categories}

        
<ul>
            
{exp:query sql="SELECT cat_id as category_id, cat_name AS category_name FROM exp_categories WHERE parent_id = '8'"}
            
<li><a href="{path="instruction/categories/C{category_id}"}">{category_name}</a></li>
            
{/exp:query}
        
</ul>

My problem is that when using teh exp:weblog:category tag, I don’t see an available parameter to tell it to only show the parent with a certain ID. See, I’m going to have five, maybe six different parent categories, all with children under them. If I use the basic exp:weblog:categories tag pair with parent_only=“yes” it will display ALL of the parent categories in a list. I need to be able to specify specific ones and I’m not sure if that’s a possibility. I didn’t think about this earlier.

thanks

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 06 February 2008 12:36 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005

Two immediate thoughts:

1. Can you break them up into individual category groups? That way you could do the following as many times as necessary:

{exp:weblog:categories weblog="instruction" parent_only="yes" category_group="1"}
        
<h3>{category_name}</h3>
   

        <
ul>
            
{exp:query sql="SELECT cat_id as category_id, cat_name AS category_name FROM exp_categories WHERE parent_id = '8'"}
            
<li><a href="{path="instruction/categories/C{category_id}"}">{category_name}</a></li>
            
{/exp:query}
        
</ul>
     
{/exp:weblog:categories}

2. Does moving the closing tag to the bottom as I did above allow it to cycle through them, treating the parents as headers? Can’t parent_id={category_id} in the sql code? IF so, then you wouldn’t have to worry about using the category_group parameter.

I’ll think more on that and test some setups Wednesday.

Terry

Profile
 
 
Posted: 06 February 2008 08:46 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

Hey Terry,

You can view what I’ve got thus far: http://www.kentuckygolfing.com/instruction. When moving the closing exp:weblog:categories tag below the </ul>, the formatting is right with the parent being the <h3> heading and the list items under it, but as you can see, it’s simply listing the parent category three times, instead of listing the parent with children nested below.

I’m not sure what you’re asking about the parent_id equaling {category_id}? I’m not sure if that’s possible or why I need it?

May end up having to go with simply hard coding the parent category names into the html template or going with creating separate category groups for each of the parent categories and assigning them all to the same weblog like in this thread: http://expressionengine.com/forums/viewthread/27220/P54/

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 06 February 2008 10:54 AM   [ Ignore ]   [ # 11 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005
deronsizemore - 06 February 2008 08:46 AM

Hey Terry,

You can view what I’ve got thus far: http://www.kentuckygolfing.com/instruction. When moving the closing exp:weblog:categories tag below the </ul>, the formatting is right with the parent being the <h3> heading and the list items under it, but as you can see, it’s simply listing the parent category three times, instead of listing the parent with children nested below.

I looked and what a mess. Totally unexpected behavior - why three times??

I’m not sure what you’re asking about the parent_id equaling {category_id}? I’m not sure if that’s possible or why I need it?

I really don’t know what parent_id is being derived from. Is that its category_id? I was thinking it should draw from the same exp:weblog:categories entry as the heading, dynamically. If so, I missed one of them (it was scrolled off to the right side of my box), so both should read parent_id={category_id}.

May end up having to go with simply hard coding the parent category names into the html template or going with creating separate category groups for each of the parent categories and assigning them all to the same weblog like in this thread: http://expressionengine.com/forums/viewthread/27220/P54/

If you do, detail how you go with that to me. But I’ll try to get this working as well.

Terry

Profile
 
 
Posted: 06 February 2008 10:58 AM   [ Ignore ]   [ # 12 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005

I’m also going to try the exp:weblog:category_archive tag per a conversation I had with Robin Sowell last week. It may serve our purposes better.

Terry

Profile
 
 
Posted: 06 February 2008 11:16 AM   [ Ignore ]   [ # 13 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

The parent_id is just taken from the category management screen under the Admin section of the CP. I don’t think you can set the parent id equal {category_id} but I may be wrong about that and there’s also that chance I’m still confused on what you’re asking. wink (it’s easily done).

Yeah, it seems like to me that the weblog:category_archive tag is almost identical in it’s output to the regular category tag. I just don’t see a way that I can do this with the default functionality of EE and how they next children under the parent lists. Here is the code for the weblog:category_archive tag:

{exp:weblog:category_archive weblog="instruction" style="nested"}
{categories}
<h3>{category_name}</h3>
{/categories}

{
/exp:weblog:category_archive}

The problem there is that it sets each category to <h3> (both parent and child). I need the parent to be an <h3> but the children to simply be normal sized text links. The other problem is that it generates all categories (parent and children) based on what’s between the {categories} tag pair, so if I wanted links, I would have to wrap the {category_name} in an anchor tag, which in turn would also turn the parent category into a link (which I don’t want). lol. Seems every turn I make, there is another dead end with this.

When I get some time this evening, I’m going to either set it up by hard coding the parent categories into the template and then simply using the query code from the wiki that you supplied earlier to generate the children or I’m going to create a new category group for each parent and then list the children that way. Seems to be the only way I know how to do this. The latter solution may be better (even though it offers more clutter) because at least that way, if the parent category names change, they will all update dynamically instead of me having to change them in the templates.

I’ll post my results later tonight.

Thanks

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 06 February 2008 05:26 PM   [ Ignore ]   [ # 14 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005

Weblog:category_archive tag has no “parent-only” parameter, so it is worthless to us.

I’m playing with this now. Simple enough problem, right? No link on the parents, links on the children! Just as it should be!

Terry

Profile
 
 
Posted: 06 February 2008 06:25 PM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

Yeah, one would think it would be simple enough, but it seems thats not the case

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 06 February 2008 07:04 PM   [ Ignore ]   [ # 16 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005

EDIT: NIX THIS - I HAD IT WRONG - ONLY ENTRIES LINKED - CATEGORIES DID NOT


Do you have your parents assigned to ANY items?

I ran this code just to try the category_archive tag. This is a generic categories template. I happened to have an already made category group with a bunch of child entries under two parents, and knew I had only one entry assigned. Well, without any provocation from me at all (other than there being no entries except in two categories), the parents AND the other entry-less categories were unlinked. I didn’t do anything!!!! I swear!!!

Here is an example page.

<h2 class="sidetitle">Categories</h2>

{exp:weblog:category_archive weblog="{master_weblog_name}"}

{categories}
<h4>{category_name}</h4>{/categories}

{entry_titles}
<a href="{path=science/comments}">{title}</a>{/entry_titles}

{
/exp:weblog:category_archive}

<p><a href="base1/index"><< Back to Section</a></p>

If you have parents assigned to any entries, try unassigning them entirely, and see if you get the same results. (You can do this quickly to every entry in the Edit control panel, using the drop down at the bottom left after checking the entries you want (or all entries in this case, most likely).

If it was this simple…. grrrrrrrrrrrr!!

(You called on the right man… blundering is something I do exceptionally well.)

Addemdum:(from docs)

path

{entry_titles}
<a href="{path=site/index}">{title}</a>
{/entry_titles}

The path (template_group/template) is used to create a URL to display this entry. This variable uses the entry’s url_title in the URL. This is typically used within a standard HTML link tag:

<a href="{path=site/index}">{title}</a>

You can also use SITE_INDEX in your path to point to your main site index page. If you show your blog on your home page, using SITE_INDEX is preferable since it will make the URL cleaner.

<a href="{path=SITE_INDEX}">{title}</a>

Since this variable uses the entry’s url title in the URL, if there is no entry, there is no entry title, and thus there is no URL!!!

Terry

Profile
 
 
Posted: 06 February 2008 08:30 PM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1561
Joined  08-02-2006

Thanks for putting in all of that effort to get this worked out Terry. I appreciate that!

Yeah, with your example, it links the entries, but not to the categories themselves, which I want. smile

I’m going to have another search of the forums and see what I can dig up. Someone, somewhere along the line had to have needed this functionality. Seems it would be very common to me?

I haven’t had the change to try my solution yet, but I will post my results when I get the chance. I’m hoping tomorrow on my lunch break I can take a stab at it.

Thanks

 Signature 

Deron Sizemore
==========
Random Jabber | Sizcons | NiceStylesheet | Kentucky Golfing | LogoGala
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 07 February 2008 12:48 AM   [ Ignore ]   [ # 18 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  609
Joined  06-29-2005

I just knew it had to use an embed for something. Got it working.

The query had to live in an embed and have the category_id of the parents-only category-sweep sent out to it by passing an embedded variable.

Why this stuff won’t work in-line isn’t always clear, but it sure don’t! We got proof of that!

Here is an example showing this off. The very last link, Outdoor Science Displays and Sculptures leads to a category entry possessing an actual article.

Here is the main template:

<h2 class="sidetitle">Categories</h2>

{!-- Sift out parent categories for category_id's --}
{exp:weblog:categories weblog="{master_weblog_name}" parent_only="yes"}

{!-- Print Parent Name --}
<h4>{category_name}</h4>

{!-- Send category_id of parent to sql query in embedded template --}
{embed="base1/_embed_child_query" my_parent="{category_id}"}
{/exp:weblog:categories}

Here is the embedded template, base1/_embed_child_query, with the embed:variable passed into it from the requesting template:(see way to the right parent_id={embed:my_parent} )

{!-- keep in mind there are no quotes or ticks around variables used in a SQL statement - ticks only go around absolutes --}
<ul>
{exp:query sql="SELECT cat_id as category_id, cat_name AS category_name FROM exp_categories WHERE parent_id = {embed:my_parent}"}
<li><a href="{path=science/C{category_id}}">{category_name}</a></li>
{/exp:query} {!-- now you see why I kept wanting to put parent_id={category_id}!!  --}
</ul>

At long last you are paid off for your infinite patience, Sir!

And now I’m going to use this trick on my own pages!!!

[EDIT: I added this bit of code to the original Wiki entry showing the children-only query code:  List Child Categories of a Parent Category., for posterity sake.]

Terry

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: 64470 Total Logged-in Users: 45
Total Topics: 81002 Total Anonymous Users: 23
Total Replies: 435836 Total Guests: 258
Total Posts: 516838    
Members ( View Memberlist )
Newest Members:  tracy16onnayokhengVamediaGabesCiDudecargolseckadanisNogDogLNBCNeli_lao