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.