Forums › Forums › Search & Filter Pro › How Restrict Search & Filter Widget
- This topic has 7 replies, 3 voices, and was last updated 9 years, 4 months ago by Ross.
-
Anonymous(Private) June 23, 2014 at 7:04 am #1802
Hi,
When reading this forum I noticed that Search & Filter does not work when any of “restrict widget” plugins are enabled. I tried some of them (Widget Logic, Widget Logic By Path, Display Widget, Restrict Widget, Widgets Controller, Widget Context), but with none of them AJAX search seems to work.
Is there any way how to restrict Search & Filter widget to specific page AND to use AJAX search?
Also do you have any suggestions what custom search template should I use (or create) to display search results in the same way as on your Woocommerce demo site? I am using Divi theme.
Thanks!
PetrRoss Moderator(Private) June 23, 2014 at 8:55 am #1807Hey Petr
Yes, basically you need to create your own template, and create a widget area specifically for this page…
1) Make sure custom template is ticked in admin
2) Make sure you enter a slug (ieproduct-search
)
3) Create your custom templateNow that you are using a slug you can access your search results like:
yoursite.com/product-search
and if you are using a custom template then you can restrict S&F to only appear on this template.Now the tricky part…. I had to do quite a lot of modification to get it working with the mystile theme exactly how I wanted.
First I duplicated the
archive-product.php
from the woocommerce templates folder and called thisproducts-search.php
and put this in my theme folder.Then I create and register a sidebar, so…. Add this code to functions.php of your theme:
register_sidebar(array( 'name'=> 'Search & Filter Form Widgets', 'id' => 'search_filter_form_widget', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ));
Now you will find a new widget area to add S&F widget.
We need to include this in our
products-search.php
though so we must create a sidebar first…Create a new file in your theme folder called
sidebar-search-form.php
and add the code:<?php /** * Sidebar Template * * If a <code>primary</code> widget area is active and has widgets, display the sidebar. * * @package WooFramework * @subpackage Template */ global $woo_options; if ( isset( $woo_options['woo_layout'] ) && ( $woo_options['woo_layout'] != 'layout-full' ) ) { ?> <aside id="sidebar" class="col-right"> <?php dynamic_sidebar( 'search_filter_form_widget' ); ?> </aside><!-- /#sidebar --> <?php } // End IF Statement ?>
Now we have a sidebar that loads our custom widget area…. but this is still not in our template… so in the template
product-search.php
add:<?php get_sidebar('search-form'); ?>
And there you have it! A new widget area just for your custom template 🙂
Anonymous(Private) June 24, 2014 at 9:40 am #1833Hi Ross,
Thanks a lot for narrowing this down. The only issue I have is that when the sidebar is generated using the template, it generates the default sidebar, not the custom one.
It seems that the file
sidebar-search-form.php
is for some reason not processed.Also when I use this code:
<?php get_sidebar('search-form'); ?>
it does not generate anything.When I switch it to:
<?php get_sidebar('sidebar-search-form'); ?>
It generates the sidebar, but only the default one.
Petr
Ross Moderator(Private) June 24, 2014 at 2:35 pm #1856Hey Petr no worries glad its working ok now 🙂
Anonymous(Private) June 18, 2015 at 12:20 am #19780I’ve followed these instructions, but the sidebar search widget appears in the footer on search result pages. If I move the location of the following:
<?php get_sidebar(‘sidebar-search-form’); ?>
I can get the sidebar widget to move to the header and body, but never over to the right hand side of the page. Any idea what I’m doing wrong?
Ross Moderator(Private) June 18, 2015 at 12:46 pm #19798Hey Scott, can you open a new ticket?
Thanks
-
AuthorPosts