Forums Forums Search & Filter Pro Custom Search Results Page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Anonymous
    #34580

    Hey Ross:
    I’m stuck in my attempt to create a custom search results page that displays only the title for the post(s) that are queried. I also want the “title” of the results page to state the number of results and the search query. Hoping you (or someone) can help?

    I created a custom search.php file -> “searchpage.php”
    I utilized the following code:

    <?php if (have_posts()) : ?>
    <h2 class="search-title">
    <?php echo $wp_query->found_posts; ?> <?php _e( 'Search Results Found For Your Location' ); ?>: "<?php the_search_query(); ?>"
    </h2>
    <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?>>
    <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    </div>
    <?php endwhile; ?>
    <?php else : ?>
    <h2 class="center">No posts found. Try a different search?</h2>
    <?php get_search_form(); ?>
    <?php endif; ?>

    ** First – The results page title is not showing the query name – only the number of results.
    Q: Do I need to use something other than “the_search_query” to display the title?

    ** Second – The results page is not showing the header, menu, or results navigation. It is a plain white page that displays only the title, and post titles (hyperlinked).
    Q: Any idea what is missing so the normal layout displays?

    Thanks

    Ross Moderator
    #34656

    Hi Scott

    To answer your questions:

    1) To get data from the current search you can use:
    http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    So, from that link, the code would be

    <?php
    	//Get the search term
    	//replace '1526' with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(1526)->current_query();
    	echo $sf_current_query->get_search_term();
    ?>

    2) Which display method are you using? If you are using archive then it sounds like you have set your template up wrong (a little). This really depends on your theme, so go into your theme and take a look at other template files such as archive.php or search.php.

    Usually you should at least be starting with a get_header() and finishing with a get_footer() – but this is really theme dependent – https://codex.wordpress.org/Include_Tags

    Thanks

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