Forums › Forums › Search & Filter Pro › Group search results by starting letter, number
Tagged: group search results by letter, number
- This topic has 5 replies, 3 voices, and was last updated 8 years, 9 months ago by Trevor.
-
Anonymous(Private) March 22, 2016 at 8:59 am #40108
I want to create a search results layout where they are grouped by starting letter, like in this example:
exampleIs 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(Private) March 23, 2016 at 12:09 pm #40361Hi 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:
I guess you would check the starting letter of the post title, and assign taxonomy based on that.
I hope that helps.
Thanks
Anonymous(Private) March 30, 2016 at 7:58 am #40929Hi 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!
BorisTrevor(Private) March 30, 2016 at 8:48 am #40940From 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.phpFrom 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(Private) March 30, 2016 at 8:51 am #40941Hello 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!
BorisTrevor(Private) March 30, 2016 at 10:19 am #40958Ah. 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.
-
AuthorPosts