I have a very simple page which displays a list of articles based on the category, which is present in the URL. The code is here:
{exp:channel:entries channel="news" limit="10" category="{segment_3}" disable="member_data|category_fields" paginate="bottom" orderby="date" dynamic="no"}
<a class="square_block" href="{url_title_path='news/article'}">
<div class="content_block">
<div class="news_block_headline">
{title}
</div>
<div class="news_block_text">
{exp:eehive_hacksaw words="30" append="..."}
{exp:remove_html}
{teaser}
{/exp:remove_html}
{/exp:eehive_hacksaw}
</div>
<div class="square_block_divider"></div>
<div class="news_block_date">
{entry_date format="%d/%m/%y"}
</div>
<div class="square_block_arrow"></div>
</div>
</a>
{/exp:channel:entries}
What I want to do is also display any articles from any child categories that may be related. How would I go about doing this? I have had a look at plugins like GWCode Categories and done some searching but most focus on simply getting child category names rather than actually pulling data from them.
OK so I cracked this using GWCode Categories. I had to use an embedded template due to PHP parsing issues with EE.
I created a template called widgets/news_specific_cats that looks almost identical to the code above, except the exp:channel:entries tag an embedded variable in it so it looks like this:
{exp:channel:entries channel="news" limit="10" category="{embed:childCategories}" disable="member_data|category_fields" paginate="bottom" orderby="date" dynamic="no"}
Then on the main page I have some PHP code to get a list of parent and child categories which are passed as the embedded variable like so:
<div style="display:none;">
{exp:gwcode_categories cat_id="{segment_3}"}
<?php
$childCategories .= "{cat_id}|";
?>
{/exp:gwcode_categories}
</div>
<?php
$childCategories = strip_tags($childCategories);
$childCategories = rtrim($childCategories, "|");
$childCategories = trim($childCategories);
?>
<div id="block_holder">
{embed="widgets/news_specific_cats" cats="<?php echo $childCategories; ?>"}
</div>
I have the GWCode block wrapped in a hidden div because for some reason GWCode insists on outputting data as a formatted list so I have to strip all that stuff out manually. Basically it just gets all the categories into a bar-delimited format that EE uses to denote selecting articles from multiple categories. I doubt this is the best way of accomplishing what I needed, but it works.