Announcement

Collapse
No announcement yet.

Tip: Search within this category

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tip: Search within this category

    I figured out how to add a "search within this category" box which will only show results from the current category. Example here:
    Front Derailleur Adaptors - AEBike.com - Thousands of bicycle parts and accessories - Shipped Worldwide

    Here is the code I used in my category_0.html template file:

    Code:
    <form method="get" action="search.asp">
    	<input type="hidden" name="catid" value="[catid]">
    	<input type="text" name="keyword">
    	<input type="submit" value="Search">
    </form>

  • #2
    Nice! Thank you.

    Comment


    • #3
      Awesome tip, thank you!
      Chris
      TC Life Safety
      TC Wireless

      Comment


      • #4
        very useful, thank you for sharing
        (¯`v´¯)
        `*.¸.*´

        ¸.•´¸.•*¨) ¸.•*¨)
        (¸.•´ (¸.•´ .•´ ¸¸.•¨¯`•
        * P£†®ª *

        Shadow Trailers
        www.TrailerandTruckParts.com
        www.Trailer-Wheels.com
        www.iTrailerParts.com

        Comment


        • #5
          Thanks for the tip, was looking for something like this.
          - Peace
          www.ifilters.net

          Comment


          • #6
            I tried this and cannot get off of the category page :-(

            I stashed it on one of my lesser-visited category pages so you can see what I mean...

            * Ladies Snakeskin Watch Bands | Womens Straps & Bands for Watches

            You type something in, hit submit and it just sits there. Any suggestions?

            thanks -mimib

            Comment


            • #7
              Two problems.. you have it inside another <form> element that is used by the page to control the sorting of the category. Secondly you did not copy the <form> line from the original code, so all you have is an input field and a button. It needs to be outside the first <form>, either before it or after it.

              Comment


              • #8
                Aha!! The template I use has the entire category html wrapped in the sortbylist form tags! I moved those so they just surrounded the actual sortby form and the new search form works! Yay!
                Thanks for pointing that out for me!

                Comment


                • #9
                  In case anyone needs it, I added this script to hide the search box if there are no products in the category, since the search doesn't reach down into sub-categories:
                  Code:
                  <script type="text/javascript">
                       if ('[numItems]' = 0)
                  	{
                  	     document.getElementById('yourDIVid').style.display = 'none';
                  	     }
                  </script>
                  Note you have to wrap the search box in a div and enter that name where it says 'yourDIVid' in the script.
                  Last edited by tclifesafety; 06-12-2012, 04:13 PM.
                  Chris
                  TC Life Safety
                  TC Wireless

                  Comment


                  • #10
                    Hello all.
                    We just wanted to give this thread a quick BUMP.
                    Thank you so much cbsteven.

                    Our site is now even better.

                    Thanks again.

                    Best regards,
                    papa

                    Comment


                    • #11
                      Originally posted by tclifesafety View Post
                      In case anyone needs it, I added this script to hide the search box if there are no products in the category, since the search doesn't reach down into sub-categories:
                      Code:
                      <script type="text/javascript">
                           if ('[numItems]' = 0)
                      	{
                      	     document.getElementById('yourDIVid').style.display = 'none';
                      	     }
                      </script>
                      Note you have to wrap the search box in a div and enter that name where it says 'yourDIVid' in the script.
                      be sure not to assign 0 to your [numItems], use === when you compare with zero as a good rule of thumb

                      Comment


                      • #12
                        One problem I ran into with this is with Smart Categories. The search function does not work.
                        We use two smart categories for Sale Items, and New Items. The search box causes confusion when no results are returned.

                        I tried adding a couple of if statements to test for the [catid] and hide the search box, but I am really not good with javascript at all and I need help.
                        Code:
                        <script type="text/javascript">
                             if ('[numItems]' === 0)
                        	{
                        	     document.getElementById('yourDIVid').style.display = 'none';
                        	     }
                             if ('[catid]' = '1884')
                        	{
                        	     document.getElementById('SearchInCat').style.display = 'none';
                        	     }
                             if ('[catid]' = '2024')
                        	{
                        	     document.getElementById('SearchInCat').style.display = 'none';
                        	     }
                        </script>

                        Comment


                        • #13
                          Well the obvious problem is you are using a single = symbol when you test your category ID.
                          In Javascript a single = symbol is to assign a variable, so you are saying:
                          If (Set CatID to 1884) returns true then (Hide SearchInCat)

                          You want to use a == or === to test if CatID EQUALS 1884.


                          I don't use this search-within system anymore because I use SearchSpring, but IIRC the way I hid the box when no results was to have it default to hidden, and include code within the <!--START: ITEMS--><!--END: ITEMS-->
                          block which would make it visible.

                          Comment

                          Working...
                          X