• I edit a small family history magazine . I now have index which lists names, dates, subject and the issue number and page number in which they appear. The index is in an Excel file but I can convert that to a comma-separated text file. I want subscribers to our website to be able to search for a given name or topic etc but so far the only way I have found to do this is to put each and every line (and there are >2500 of them) into a separate post: then the search will find the items but every result includes the title of the post, the date and author and under the single line I want the category. So for example:

    ————————
    Armitage Richard
    January 11, 2017 by The Moxon Society

    Armitage Richard 1928-1986 Son of Reginald (Noel Gay) Issue 2 Page 3

    Uncategorized
    ————————

    Armitage Harry
    January 11, 2017 by The Moxon Society

    Armitage Harry Father of Reginald and Cyril Issue 2 Page 3

    Uncategorized

    ————————

    … when all really want is the lines of information in a list. I think it can be solved by modifying the code in the search.php template which is the default which came with the theme (an up-to-date GeneratePress) theme in an up-to-date WordPress self-hosted site) but I’m afraid I don’t understand php code.

    Any help would be much appreciated.

    Trevor Jordan

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Trevor,

    Have a look at these plugin’s. They might be what you need.

    https://www.ads-software.com/plugins/list-site-contributors/screenshots/
    https://www.ads-software.com/plugins/members-list/

    Michelle

    Thread Starter [email protected]

    (@trevorjordan)

    Thank you for the prompt reply, Michelle. I looked at those two plugins but they list contributors and members rather than items found in my search, so my quest continues! I’ve learned a lot on this journey, but not yet enough!

    Best wishes,
    Trevor
    ——

    Moderator bcworkz

    (@bcworkz)

    I think you are correct, that editing the search results template will give you the output you want. If you’re willing to try some trial and error coding, you could pull this off yourself because you are only removing output, not changing or adding code. You can safely remove code by turning parts of it into a comment. Doing so could cause syntax errors when the correct parts are not completely commented out. Learning a few basic syntax rules should prevent much of this.

    You should first create a child theme so your custom template is safe from theme updates. There’s no real coding involved in this part. You need to be able to create a plain text file and upload it to a new folder on your server.

    Open a copy of search.php in a local text editor. Don’t use the built in WP theme editor, it’s dangerous because it makes no backups. When you are done with this file, upload it to your child theme folder, do not replace the original file! Look for “The Loop” on the template file. It usually starts with while ( have_posts() ) : the_post(); and ends with endwhile;. Each theme has its own variations of repeatedly doing something to comprise the loop. while: endwhile; is most common, but you may see something like while ( have_posts() ) { a bunch of code to execute } over several text lines.

    If the code inside the loop includes get_template_part(), you’ll need to locate what template part file gets loaded and copy that into the child. If it comes from a sub-folder, replicate the same structure in your child.

    What you are really looking for is things like the_title(), the_author(), the_category(), etc. that output undesirable output. You will make these into comments. If you comment out the wrong thing or create a syntax error, just undo your last edit. This means working in small increments and checking your work frequently. Keep backups once in a while in case you need to revert. The only thing you really want in the loop is either the_content() or the_excerpt().

    In PHP, every code “line” ends with a semicolon;. This code line may span many lines of text. To avoid syntax errors, you should generally only comment out entire code lines. Comments are created by adding /* at the beginning and */ at the end. You may see another comment style that starts with //. It ends at the end of the text line (not code line) without any other special character. It’s the invisible line feed that terminates this style.

    You’ll see other syntax that involves {curly braces}. If you comment out the beginning of one of these, be sure the matching closing brace} is also commented. It’s safer to leave these alone and comment out code lines within the braces.

    All PHP code occurs inside of <?php ?> tags. Anything outside of this is plain HTML. <!– HTML comments look like this –>. Browsers are tolerant of bad HTML, so correct syntax is less of an issue. Try not to corrupt the HTML syntax if you can.

    A lot of explanation here, but you’ll find execution isn’t nearly as bad as it sounds here. It’s well worth learning a little PHP because it’s very empowering to be able to tweak you site’s output exactly the way you want. You might even find it’s rewarding and even kind of fun ??

    About the 2500 relatives. I think there is a plugin that imports Excel files. Whether the data ends up the way you need it, I don’t know. For someone that can code, importing CSV data into posts is easily done by automated custom code. It may be a bit much for a novice, but a pro can whip up something fairly quickly. They can quickly fix up your search template too. You can find such help a jobs.wordpress.net.

    Thread Starter [email protected]

    (@trevorjordan)

    Thank you for your very detailed and helpful reply. You are absolutely right: I should bite the bullet and learn some PHP rather than rely on the “customise” facility on my themes. I’m also very grateful for the timely reminder to use a child theme for the sake of safety!

    Anyway, I’m very happy to report that following an afternoon of simply playing around with various PHP files in my child theme, I have achieved the result I was looking for! I still need to do some CSS styling to make it look prettier, but I am a very happy chap right now!

    So again, thank you very much indeed for your help which will extend far beyond this particular piece of PHP coding.

    With very best wishes,
    Trevor Jordan

    Moderator bcworkz

    (@bcworkz)

    That is awesome! I’m glad my lengthy post didn’t scare you off.
    May your new found powers serve you well!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying limited search results data’ is closed to new replies.