Displaying Search Results in a Theme

When modifying a theme, one easy to overlook element is the search function.  The search function populates the $posts (list) standard chalk item for the search page.  Thus, all that is needed is to simply loop through the $posts list using the foreach syntax to display each post.  

However, some themes may not want to display a list of all posts, on the home page, for example.   The conditional logic for the search would then look something like the following:

#if($where == "search")

    #foreach($post in $posts)
           <h2>
                     <a href="$post.Url" title="$post.Title" rel="bookmark">$post.Title</a>
           </h2>
            <p>
                     $post.Body
            </p>
    #end

#else

     #set($post = $data.Featured())

     $post.Title
      <p>
                $post.Body
      </p>

#end

No Comments