How To Handle Search Results

A search results page as well as other archive pages, will bind a “$posts” object to the page. That means that you can simply iterate through the different posts contained in the collection. Below is an example that show how to render this collection:

 

<div class="row">
	<div class="col-md-12">
	    {{if count( $posts.data) eq 0}}
	    <div class="row no-results">
            <h2 class="aligncenter">No Results Found</h2>
            <p class="aligncenter">We could not find the any page associated with the term <i>"{{$smarty.get.s}}"</i>
            </p>
        </div>
        {{/if}}
	    
        {{foreach $posts.data as $post}} 
        {{author user_id="{{$post.post_author}}" assign_to="author"}} 
        {{meta post_id="{{$post.ID}}" assign_to="meta"}} 
        {{post show="categories" assign_to="post_categories" post_id="{{$post.ID}}"}}
		<article>
		<div class="row">
			<div class="span8">
				<div class="post-image">
					<div class="post-heading">
						<h3><a href="{{$post.post_permalink}}">{{$post.post_title}}</a></h3>						
					</div>
					{{if $post.post_thumbnail}}
					<img src="{{$post.post_thumbnail}}" alt="{{$post.post_title}}" />
					{{/if}}
				</div>
				<p>
				{{$post.post_content|strip_tags|truncate:400}}
				</p>
				<div class="bottom-article">
					<ul class="meta-post">
						<li><i class="icon-calendar"></i><a href="#"> {{date when="{{$post.post_modified}}" format="F j, Y"}}</a></li>
						<li><i class="icon-user"></i><a href="#"> {{$author.data.fullname}}</a></li>
						<li><i class="icon-folder-open"></i>
                            {{foreach $post_categories.data as $cat}}
                                <a style="float: none;" rel="category tag" title="{{$cat.name}}" href="{{$cat.cat_permalink}}">{{$cat.name}}</a>{{if !$cat@last}}, {{/if}}
                            {{/foreach}}
						</li>
					</ul>
					<a href="{{$post.post_permalink}}" class="pull-right">Continue reading <i class="icon-angle-right"></i></a>
				</div>
			</div>
		</div>
		</article>
		{{/foreach}}
		
        
        
        {{paginate type="array" assign_to="pagination"}} 
        {{if $pagination.total > 1}}
		<div id="pagination">	
            <ul style="list-style: none;">
                {{foreach $pagination.data as $page}}
                <li>{{$page}}</li>
                {{/foreach}}
            </ul>
		</div>
        {{/if}}	
	</div>	
</div>

 

Leave a Reply

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