what to Creating a Search Page?

A Search Page is a WordPress Page with a custom Page template to give users more information for searching your site.

Things You Need to Know 

Diverse WordPress Subjects highlight distinctive layout records. Some incorporate a search.php format record. This isn’t a Pursuit Page, it is just a format that shows the list items. There is likewise a format record called searchform.php. This is a format record that is regularly remembered for the sidebar of numerous topics and produces the pursuit box structure. In case there isn’t one in your subject, you can without much of a stretch duplicate it from the Default topic.

To make your own custom Pursuit Page, you should make a Page format to incorporate your inquiry structure and the data you need your clients to see before they search your site. WordPress Support

Check your WordPress Topic to check whether it incorporates a page.php format record. The Default WordPress Subject incorporates this layout, however many don’t. In the event that it does, adhere to these directions. In the event that it doesn’t, we have the data you need to make your own.

Creating a Search Page Template 

  1. Utilizing a content manager, open the page.php and save as searchpage.php. On the off chance that you don’t have a page.php, you can make one dependent on your Topic’s index.php layout document.

2. After saving it, edit the file:

  • Delete The Loop (i.e. basically everything within your content div), leaving the div tags intact.
  • Add a heading such as “Search Posts” or something similar. You can use an existing class from your CSS stylesheet, or create a new one.
  • Copy the following into the content div or any other div that contains the content of your Page:
<?php get_search_form(); ?> 

At the top of your searchpage.php, before anything else, add this to give your Search Page a heading WordPress will recognize in the Administration Screens:
<?php 
/**
 * Template Name: Search Page
 */
?> 

3. Save the file.
4. Upload the file to your theme directory (if you made changes to your style.css style sheet file, upload that, too).

If you create searchpage.php from page.php in Twenty Seventeen, it would be as like as followings:

<?php
/**
 * Template Name: Search Page
 */

?>
<?php get_header(); ?>

<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
        <?php get_search_form(); ?>
        </main><!-- #main -->
    </div><!-- #primary -->
</div><!-- .wrap -->

<?php get_footer(); 

Creating a Search Page 
Based on the Search Page Template, we will create the search page.

1. In the Administration Screen go to Pages > Add New.
2. In the title field enter Search.
   Do not write anything in the content area.
3. While still on the same page, look for Page Attributes on right side menu.
4. Select the drop-down menu in Template, and select Search Page.
5. Click the Publish button.

Linking to Your Search Page 

You can now make a link to your custom Search Page in several ways.

Using the Page ID 

Whether or not you use permalinks, you can link to your new Search Page by using Page ID number of the Page. Insert the next line into your any posts, pages or templates

<a href=”index.php?page_id=17″ title=”Search Page”>Search Page</a>

OR you may insert the next line into templates

<a href=”<?php echo home_url(); ?>/?page_id=17″>Search Page</a>

Using the Page Slug 

The Page slug is set in the Edit Page screen. It is the name of the page if you are using Permalinks. You can manually change this. An example of a Page slug link would be:

<a href=”/wordpress/search-page/” title=”Search Page”>Search Page</a>

for any posts, pages or templates when slug is ‘search-page’. OR you may insert the next line into templates

<a href=”<?php echo home_url(); ?>/wordpress/search-page/” title=”Search Page”>Search Page</a>

Using wp_list_pages() 

If you are using the wp_list_pages() template tag, the page name would be automatically generated in your Pages list.

Customizing Your Search Page 

Since you have made your custom Hunt Page, you can modify the presentation. Open your searchpage.php in a content manager and alter it there.

Above the get_search_form() function for your searchform.php within the content div, you can add text to help visitors search your site.

<p>My Site features articles about <a title=”WordPress Articles” href=”/category/wordpress/”>WordPress</a>, <a title=”Web Design Articles” href=”/category/web-design/”>web page design</a>, <a title=”Development Articles” href=”/category/website-development/”>website development</a> and <a title=”CSS Articles” href=”/category/css/”>CSS</a>.</p> <p>To search my website, please use the form below.</p>

You might want to include a list of keywords or other information, images, or details to customize your custom Search Page.

Preserving Search Page Results and Pagination 

Indexed lists and Pagination may quit working while applying customization to the pursuit layout. To keep away from these issues the main thing any engineer needs to do is add the accompanying code to the beginning of their Hunt layout to guarantee that the first WordPress inquiry is safeguarded. To modify the inquiry affix extra contentions to (exhibit) $search_query. Execute the $search_query through another $wp_query object, more data on the WP_Query item can be found at WP_Query.

12<br>&lt;?php <br> global$query_string;</p> <p>$query_args= explode("&amp;", $query_string);<br> $search_query= array();</p> <p>if( strlen($query_string) &gt; 0 ) {<br> foreach($query_argsas$key=&gt; $string) {<br> $query_split= explode("=", $string);<br> $search_query[$query_split[0]] = urldecode($query_split[1]);<br> } // foreach<br> } //if</p> <p>$search = new WP_Query($search_query);<br> ?&gt; <br>

Additional customization arguments can be found at WP_Query.

Display Total Results 

To access the total number of search results from search.php, a search result page, you should retrieve the total number of posts found using the wp_query object.

<?php global $wp_query; $total_results = $wp_query->found_posts; ?>

More information on WP_Query can be found at WP_Query.

Leave a Reply

Your email address will not be published.

Gdpr compliency website analytics