search en Drupal 7: How to add a custom CSS class to the last search result item on the search page <span>Drupal 7: How to add a custom CSS class to the last search result item on the search page</span> <span><span>admin</span></span> <span>Wed, 11/14/2012 - 13:53</span> <ul class="links inline"><li class="comment-add"><a href="/drupal-7-how-add-custom-css-class-last-search-result-item-search-page#comment-form" title="Share your thoughts and opinions." hreflang="und">Add new comment</a></li></ul> <div><p>This is a small tidbit of information in the event that you wanted to alter the Drupal search results page. You can add a custom CSS class to the last search result item (for whatever reason you may have). In my case, I wanted to remove the border-bottom from the last result, so I had to add a special CSS class to do this. Just follow these simple steps:</p> <ol> <li>Override <a href="!search!" rel="nofollow">template_preprocess_search_results</a> Here is how to alter the code. This goes in your template.php: <code> function yourthemename_preprocess_search_results(&amp;$variables) { $variables['search_results'] = ''; if (!empty($variables['module'])) { $variables['module'] = check_plain($variables['module']); } //checking the total number of results $num_results = count($variables['results']); $counter = 0; foreach ($variables['results'] as $result) { $counter++; if ($num_results == $counter) { //means we have the last result so we add the class $variables['search_results'] .= theme('search_result', array('result' =&gt; $result, 'module' =&gt; $variables['module'], 'last' =&gt; 'last')); } else { $variables['search_results'] .= theme('search_result', array('result' =&gt; $result, 'module' =&gt; $variables['module'])); } } $variables['pager'] = theme('pager', array('tags' =&gt; NULL)); $variables['theme_hook_suggestions'][] = 'search_results__' . $variables['module']; } </code></li> <li>Now we override <a href="!search!search-result.tpl.php/7" rel="nofollow">search-result.tpl.php</a> Create this file and put it in your custom theme folder.</li> <li><code>"&lt;?php print $attributes; ?&gt;&gt; &lt;?php print render($title_prefix); ?&gt; </code> <p><code>&gt; <a rel="nofollow">"&gt;&lt;?php print $title; ?&gt;</a> </code></p> <p> <code> &lt;?php print render($title_suffix); ?&gt; </code><code>&lt;?php if ($snippet): ?&gt; </code></p> <p><code>&gt;&lt;?php print $snippet; ?&gt;</code></p> <p> <code> &lt;?php endif; ?&gt; &lt;?php if ($info): ?&gt; </code></p> <p><code>&lt;?php print $info; ?&gt;</code></p> <p> <code> &lt;?php endif; ?&gt; </code><code> </code></p></li> <li>Clear your cache</li> </ol> <p>Now if you search for something, you will notice that your very last search result has the CSS class of "last". This also works for search results that have a pager. That is, the last result on every page will have the class of "last".</p> </div> <div> <div>Tags</div> <div> <div><a href="/tag/drupal" hreflang="en">Drupal</a></div> <div><a href="/tag/drupal-7" hreflang="en">Drupal 7</a></div> <div><a href="/tag/search" hreflang="en">search</a></div> <div><a href="/tag/tutorial" hreflang="en">tutorial</a></div> <div><a href="/tag/drupal-planet" hreflang="en">Drupal Planet</a></div> </div> </div> <section class="comments" > <article data-comment-user-id="0" id="comment-1607" class="js-comment comment"> <mark class="hidden" data-comment-timestamp="1567354953"></mark> <div class="comment-side"> <img src="/themes/custom/likable_subtheme/images/avatar.png" /> <div class="comment-submitted"> <p class="comment-name"> <span>johnybravo123 (not verified)</span> </p> <p class="comment-time"> Sun, 09/01/2019 - 12:07 </p> <p class="comment-permalink"> <a href="/comment/1607#comment-1607" hreflang="en">Permalink</a> </p> </div> </div> <div class="comment-text"> <div class="comment-arrow"></div> <h3><a href="/comment/1607#comment-1607" class="permalink" rel="bookmark" hreflang="en">Thanks for Sharing....!!</a></h3> <div class="content"> <div><p>Thanks for Sharing....!!</p> </div> <div class="sharethis-wrapper"> <span st_url="" class="st_facebook"></span> <span st_url="" class="st_email"></span> <span st_url="" st_title="" class="st_twitter"></span> <span st_url="" st_title="" class="st_sharethis"></span> <span st_url="" st_title="" class="st_print"></span> <span st_url="" st_title="" class="st_fblike"></span> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=1607&amp;1=default&amp;2=en&amp;3=" token="_YNqD4JBYkBZ2GmpdVsqxjJhgo4b7CsLHrzlGeA5eqQ"></drupal-render-placeholder> </div> </div> </article> <h2>Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=50&amp;2=comment_node_page&amp;3=comment_node_page" token="ApDbkPDuzm4sAIjju5T7a0FpK23QAQ3xpyKXVp7CfGo"></drupal-render-placeholder> </section> <div id="field-language-display"><div class="js-form-item form-item js-form-type-item form-item- js-form-item-"> <label>Language</label> Not specified </div> </div> Wed, 14 Nov 2012 17:53:23 +0000 admin 50 at