douyimin1083 2011-07-06 13:55
浏览 33
已采纳

表达引擎 - 特定类别的下一个条目?

OK, another problem with Expression Engine. I know it pretty well but i'm sort-of just learning categories!

I've searched around for this answer but can only find the same thing. I need to have a next button on a title_permalink page that goes to the next entry in that category. I know how to manually specify a category but that won't work as it will only ever give me entries from that category! I need a way for ee to know what category the entry is in. My code is very simple at the moment, it's :

{exp:channel:next_entry}<a href="{path='projects-test/view'}" style="color:#fff;">Next Project</a>{/exp:channel:next_entry}

I could add category_id="2" but then what happens whenever the person goes into a category that isn't 2, they are all using the same view template.

My structure is like follows:

Category Selection page - list of categories using category_name tag
Project List page - links here using channel:entries tag
Project View page - linked here by a title_permalink tag

Thanks for any help!

  • 写回答

1条回答 默认 最新

  • duanlang1531 2011-07-06 17:36
    关注

    The default ExpressionEngine Next/Previous Entry Linking Tag Pairs allow you to generate links to the next or previous entry, based on the date of the current entry.

    However, the biggest limitation is that they not as robust when it comes to restricting or filtering entries with multiple categories.

    If your needs are simple, you can use the following code to restrict the Previous/Next links to showing entries within the current entry's category:

    {exp:channel:entries channel="channel_name"}
        ...
    
        {exp:channel:prev_entry category="{categories}{category_id}|{/categories}"}
            &laquo; <a href="{id_path=template_group/template}">Previous</a>
        {/exp:channel:prev_entry}
    
        {exp:channel:next_entry category="{categories}{category_id}|{/categories}"}
            <a href="{id_path=template_group/template}">Next</a> &raquo;
        {/exp:channel:next_entry}
    
        ...
    {/exp:channel:entries}
    

    You'll notice that the {exp:channel:prev_entry} and {exp:channel:next_entry} links are nested inside the {exp:channel:entries} tag and use the {categories} tag pair to restrict the Next/Previous links to the current entry's category.

    Realize, however, that this code works best when entries are classified using a single category.

    Otherwise, when using the {categories} tag pair with an entry having multiple categories, the Previous/Next links will default to the first category output ... which may be different than the next or previous entry's order of categories.

    For a more robust solution, you'll find there are many third-party solutions on Devot-ee for entry linking.

    Two of my favorite plugins for handling linked entries are Nearby Entries by Adam Khan and Entries List by Laisvunas.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度