• Resolved tariqaltaf

    (@tariqaltaf)


    i have a search form which uses RELEVANSSI plugin to perform search and display Search Results. On my Search Results page there is pagination and Search Filters(hyperlinks) which allows user to show 10, 20 or 30 records on screen.

    The Issue:
    In my website I have some internal pages which have different HEADER AND FOOTER and a Search BOX. By adding some checks If user performs search from these internal pages then it will load relevant and correct header and footer. But if I click on Pagination Filter or Search Filters (Show 10 Records, show 20 records) then it will load main website header and footer.

    I need a way to pass some variable which recognizes that from which page user come and according to that variable it will load header and footer.

    Here is my sample code:

    
    <?php
    $ref_url = $_SERVER['HTTP_REFERER'];//getting referral url
    $ref_url_final =substr_replace($ref_url ,"",-1); //removed last slash from url
    $page_slug_val = substr($ref_url_final, strrpos($ref_url_final, '/') + 1); //Get characters after last / in url
    
    print "eliab=";
    if($page_slug_val=='custom-template')
    {
    	get_header('custom');
    	get_template_part('page-templates/page','search');
    	get_footer('custom');
    }
    
    else
    {
    	get_header();
    	get_template_part('page-templates/page','search');
    	get_footer();
    	
    }
    ?>
    

    And here is the code of Page-Search.php

    
    <?php
    <?php 
    						/// For Filters ///
    	$query_string = $_SERVER['QUERY_STRING'];
    	$posts_10=add_query_arg( 'posts_per_page', 10, $query_string );
    	$posts_20=add_query_arg( 'posts_per_page', 20, $query_string );
    	$posts_30=add_query_arg( 'posts_per_page', 30, $query_string );	
    ?>
    </header>
    	
    <div class="container">
    	<div class="row">
    		<div class="col-lg-12">
    			<div class="ps19-content">
    				<div class="ps19-search-content">
    					<?php
    					if(have_posts()):	
    												// Calling Custom Search Form //
    						add_filter( 'get_search_form', 'custom_search_form_2' );
    						get_search_form();
    						remove_filter( 'get_search_form', 'custom_search_form_2' );
    					?>
    					<div class="ps19-search-result-controls">
    						<div class="ps19-search-total-result">
    						<?php
    													/// Getting Current Page ///
    							$current_page_id = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    							echo " ".$wp_query->found_posts." results for <strong>". get_search_query()."</strong> ";
    						?>
    						</div>
    						<div class="ps19-result-per-page">
    							<span>View:</span>
    				<a <?php if($_GET['posts_per_page']=="10" OR $_GET['posts_per_page']=="" ){ echo "class=\"active\"";} ?>
    								 href="<?php echo '?'.$posts_10;?>">10</a>
    				<a <?php if ($_GET['posts_per_page']=="20"){ echo "class=\"active\"";}  ?>
    								 href="<?php echo '?'.$posts_20;?>">20</a>
    				<a <?php if ($_GET['posts_per_page']=="30"){ echo "class=\"active\"";}  ?>
    								href="<?php echo '?'.$posts_30;?>">30</a>
    						</div>
    					</div>
    					<?php
    						while(have_posts()): 		
    						the_post();
    					?>
    					<article class="ps19-search-result">
    						<h2 class="ps19-search-result-title">
    							<a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a>
    						</h2>
    						<a class="ps19-search-result-link" href="<?php esc_url( the_permalink() ); ?>"  title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_permalink(); ?></a>
    						<div class="ps19-search-result-desc"><?php the_excerpt();?></div>
    					</article>
    					
    	   
    					<?php
    					endwhile;
    					
    					wp_pagenavi(); //calling pagination
    						else: 
    						echo "<h4 class='alert alert-danger' >No Result Found</h4>";
    					endif;
    ?>
    					
    <?php 
    
    if (isset($wp_query->query_vars['parvar']))
    {
    print "P=====".$invoiceno = $wp_query->query_vars['parvar'];
    }
    
    					
    
    ?>
    

    Kindly guide how to fix this issue.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    You can add an extra parameter in the internal search form:

    <input type="hidden" name="custom" value="1" />

    and then check for that:

    if ( $_GET['custom'] == '1' ) {

    Thread Starter tariqaltaf

    (@tariqaltaf)

    ok fine

    Thread Starter tariqaltaf

    (@tariqaltaf)

    Great. Works perfectly. Now one little issue is arising.

    In my search result page I have also added a Custom text page which allows the user to perform a search.

    This search result page textbox is common for template1, template2 and template 3. So how can i distinguish that from which template it is calling from.

    Need some guidance.

    Thanks

    Plugin Author Mikko Saari

    (@msaari)

    I don’t know, and that’s not really a Relevanssi question anymore, so it’s probably better idea to ask about it on more general WP support forums.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to load page template according to the Searched Page’ is closed to new replies.