dongyu5104 2014-06-18 18:10
浏览 20

从ExpressionEngine中的父类别获取子类别数据

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.

  • 写回答

1条回答 默认 最新

  • dsg435665475 2014-06-19 13:52
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来