Page 1 of 1
What are the methods for search?
Posted: Sat Aug 27, 2022 3:42 pm
by cobber
Been trying to get search working and want to know what methods exist to output the results of the search.
In
we have
etc.
I have the search page appearing but am unsure how to output the results. I have looked at the plugin code and can't see anything.
For example on the search landing page I would like to output the results of the search. I assume the results will be an object which I can iterate through.
Was hoping for some input
Re: What are the methods for search?
Posted: Mon Aug 29, 2022 9:25 am
by cobber
Anyone have an idea?
Re: What are the methods for search?
Posted: Mon Aug 29, 2022 3:34 pm
by multicolordev
you want search from input and give results title with link yeah?
Re: What are the methods for search?
Posted: Tue Aug 30, 2022 10:07 am
by cobber
For anyone interested in the future. . .
I made a theme for myself and wanted to add the search but for some reason it failed to work. The results either wouldn't appear or would cause an error and break the page.
In my own index.php code, I made a conditional to use particular templates. (this means the user can select a template of choice when creating a new page).
Then in the index, we run the conditional to check if a template is being used. (Notice I made a specific check for search).
Code: Select all
if($WHERE_AM_I == "search"){
include(THEME_DIR_PHP.'search.php');
}
else if ($page->custom('template')) {
// If a custom template is specified
if ($WHERE_AM_I=='page') {
include(THEME_DIR_PHP.$page->custom('template').'.php');
} else {
include(THEME_DIR_PHP.'home.php');
}
} else {
// If not
if ($WHERE_AM_I=='page') {
include(THEME_DIR_PHP.'page.php');
} else {
include(THEME_DIR_PHP.'home.php');
}
}
The solution was so simple, I could kick myself. It was staring me in the face all this time , in plain sight with in the documentation. Within the 'search' template I made, I added the following code to obtain the search results.
Code: Select all
<?php
global $content;
foreach ($content as $page) {
echo "<h2><a href='".$page->permalink()."'>".$page->title()."</a></h2>";
echo "<p>".$page->description()."</p>";
}
?>
Anyway, hope this helps someone in the future.