How To Get The First Post Category In Post List

TODO:

 

Pulling Post Category Data:

{{post show="categories" assign_to="item_categories" post_id="{{$item.ID}}"}}
<div class="post-category">
    {{if $item_categories.data[0]}} 
    <a href="{{$item_categories.data[0].cat_permalink}}" class="cat-item-{{$item_categories.data[0].cat_ID}}" rel="category tag" title="{{$cat.name}}">{{$item_categories.data[0].name}}</a>
    {{/if}}
</div>

 

 

Full Example:

<!--appc-related-->
<ul class="primary-bg appc-dynamic" id="appc-related">
    {{posts show="all" size="4" assign_to="rel_posts"}}
    {{foreach $rel_posts.data as $item}}
        <li>
            <div class="popular-post-img">
                <a href="#"> <img src="{{$item.post_thumbnail}}" alt="{{$item.post_title}}"></a>
            </div>
            <div class="popular-post-content">
                {{post show="categories" assign_to="item_categories" post_id="{{$item.ID}}"}}
                <div class="post-category">
                    {{if $item_categories.data[0]}} 
                    <a href="{{$item_categories.data[0].cat_permalink}}" class="cat-item-{{$item_categories.data[0].cat_ID}}" rel="category tag" title="{{$cat.name}}">{{$item_categories.data[0].name}}</a>
                    {{/if}}
                </div>
                <h4><a href="{{$item.post_permalink}}">{{$item.post_title}}</a></h4>
                <span>{{date when="{{$post.post_date}}" format="F j, Y"}}</span>
            </div>
        </li>
    {{foreachelse}}
     	<p>No posts.</p>
    {{/foreach}}
</ul><!--./appc-related-->

 

Leave a Reply

Your email address will not be published. Required fields are marked *