Forums Forums Search & Filter Pro Group search results by starting letter, number

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #40108

    I want to create a search results layout where they are grouped by starting letter, like in this example:
    example

    Is there a way to accomplish this? I’ve found some solutions that perform this function outside of the loop (solution example), but when I use that, s&f does not produce any results.

    Do you have any idea how I might set this up?

    Ross Moderator
    #40361

    Hi Boris

    I’m afraid this is not possible…

    I had another user try to implement this, and their workaround was to create a custom taxonomy and manually assign their posts to taxonomy terms like A, B, C etc.

    There could be a way to automate this, which is to automatically add your posts (when they are saved/published) to the correct taxonomy terms – but this would be some custom code.

    I can point you in the right direction – this seems like a good starting point:

    http://wordpress.stackexchange.com/questions/126409/automatically-assign-taxonomy-term-if-custom-meta-value-exists

    I guess you would check the starting letter of the post title, and assign taxonomy based on that.

    I hope that helps.

    Thanks

    Anonymous
    #40929

    Hi Ross,

    I’ve experimented quite a lot, but can’t get it the way I want. A major problem is the fact the your results.php renders separate divs for each result, instead of for instance a ul with list items. How can I change it so that a ul with list items for each post is generated?

    Thank you!
    Boris

    Trevor
    #40940

    From the documentation (I think this is what you want):

    Customising the Results

    If you wish to customise the display of your results, you must override the default template that is being used by Search & Filter:

    Create a folder in your theme folder called search-filter.
    Copy the file wp-content\plugins\search-filter\templates\results.php from the templates folder in to the newly created folder in your theme – wp-content\themes\your-theme-name\search-filter\results.php

    From now on, Search & Filter will load this version of the template instead of its own – so you can make any customisations that are necessary.

    Anonymous
    #40941

    Hello Trevor,
    I can find that in the documentation. My problem is that I don’t know how to output a ul with each result as a list item using your custom query. I tried, but the result I get is that each search result is a ul with one li item in it, instead of a single ul with each result as a li item. Ross let me know he could help me get that running. Perhaps you can ask him?

    Cheers!
    Boris

    Trevor
    #40958

    Ah. If you edit the results.php file that you copied to your (child) theme folder, you will find this code in the middle of it (I have edited it a bit to compress it, but it looks somewhat like this):

    <?php
    while ($query->have_posts())
      {
        $query->the_post();
    ?>
    <?php /* echo get_post_mime_type(get_the_ID()); */ ?>
    <div>
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <p><br /><?php the_excerpt(); ?><p>
    <?php 
    if ( has_post_thumbnail() ) {
      echo '<p>';
      the_post_thumbnail("small");
      echo '</p>';
    }
    ?>
      <p><?php the_category(); ?><p>
      <p><?php the_tags(); ?><p>
      <p><small><?php the_date(); ?></small><p>
    </div>
    <hr />
    <?php
    }
    ?>

    Try replacing that with this:

    <ul class="custom-sf-results-list">
    <?php
    while ($query->have_posts())
      {
        $query->the_post();
    ?>
    <?php /* echo get_post_mime_type(get_the_ID()); */ ?>
    <li><div>
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <p><br /><?php the_excerpt(); ?><p>
    <?php 
    if ( has_post_thumbnail() ) {
      echo '<p>';
      the_post_thumbnail("small");
      echo '</p>';
    }
    ?>
      <p><?php the_category(); ?><p>
      <p><?php the_tags(); ?><p>
      <p><small><?php the_date(); ?></small><p>
    </div></li>
    <hr />
    <?php
    }
    ?>
    </ul>

    Not sure if that will work.

Viewing 6 posts - 1 through 6 (of 6 total)