This is a curious thing.
Deron Sizemore was trying to show parent categories without links yet have their children with links. I came up with a method that didn’t work, though it seemed logical, of combining a weblog:categories tag pair set to parent_only=“yes” to filter out parents (which then just displayed category names between heading tags), and then used a query module SQL-call found in the Wiki with parent_id={category_id} to extract the children.
It didn’t work. The query simply returned the parent id as many times as there were children.
I put the query part into an embedded template, however, and passed the {category_id} to it via an embed variable, and it worked just fine! Was the {category_id} variable in the first case above not parsing to update itself between passes in the loop when used in-line, but was forced to parse when being passed to the embedded template?
Here’s the two versions of the code over at this forum thread:
Version 1 in-line that doesn’t work:
<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>
{!-- get child categories and link them --}
<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}
</ul>
{/exp:weblog:categories}
Version 2 embedded template that does work:
<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}
Embedded query:
{!-- get child categories and link them --}
<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}
</ul>
Terry
