You are here:  » Create a page with my text then search reults below.

Support Forum



Create a page with my text then search reults below.

Submitted by mally on Wed, 2007-12-12 21:57 in

Hello David

I'm working on my Magazine Subscription website. (spent a bit of time on it, its getting how I want it!)

Is it possible for me to create a page for example about Car Magazines.

I would create a page carmagazines.php

In that I would add a paragraph about the theme.

I would then like to add search results for products with the search string "cars"

Another page could be a particular price like 3 issues for £1

So instead of showing search results for "cars" I could put "1.00" (being the price)

I know how to create pages, just not to sure on the coding to get the search results there?

thanks

Mally

Submitted by support on Thu, 2007-12-13 08:27

Hi Mal,

Yes - this can be done. To save you having to replicate lots of search code everywhere, here's what I suggest you do:

1) Create a new file called searchcode.php

2) Into that file; copy all the PHP from search.php right down to but NOT including the following line:

require("html/header.php");

Having done this, and assuming that you want to reuse the standard header and footer files in your custom pages; your example carmagazines.php could look something like this:

<?php
  
require("html/header.php");
  print 
"<p>Here is your paragraph or 2 all about car magazines...</p>";
  print 
"<p>You could even break out of PHP of course if you want...</p>";
  
// now preload $_GET["q"] to be the query you want to display search results for
  
$_GET["q"] = "cars";
  
// now bring in the search code
  
require("searchcode.php");
  
// now use Price Tapestry's search results HTML module to display the results
  
require("html/searchresults.php");
  
// and finally the common footer, although you could always add more content first
  
require("html/header.php");
?>

Hope this helps!
Cheers,
David.

Submitted by mally on Thu, 2007-12-13 21:08

Hi David

I've followed the post above and have got it to work, thanks

( I take it you mean footer in the 2nd of last line in the code)

Is it possible to add the searchform at the top under the header? I've tried just inserting it but it came back with the following error

<input class='searchbutton' type='submit' value='
Fatal error: Call to undefined function: translate() in /home/magsub/public_html/html/searchform.php on line 5

Submitted by mally on Thu, 2007-12-13 21:13

I worked it out, I just moved the code around a bit.

<?php
  
require("html/header3.php");
  
// now preload $_GET["q"] to be the query you want to display search results for
  
$_GET["q"] = "car";
  
// now bring in the search code
  
require("searchcode.php");
  require(
"html/searchform.php");
  print 
"<p>Here is your paragraph or 2 all about car magazines...</p>";
  print 
"<p>You could even break out of PHP of course if you want...</p>";
  
// now use Price Tapestry's search results HTML module to display the results
  
require("html/searchresults1.php");
  
// and finally the common footer, although you could always add more content first
  
require("html/footer.php");
?>

working at Car
Magazines
- thanks.

Is there a way I could do something similar from a different website, so basically pull the data accross?

cheers

Mally

Submitted by mally on Thu, 2007-12-13 23:30

Also is there any way to order the results.

For example q=men&page=1&sort=priceAsc

I tried just adding the above in the $_GET["q"] = "men&page=1&sort=priceAsc"; however it didn't work.

thanks

MAlly

Submitted by support on Fri, 2007-12-14 08:48

Hi Mally,

You can do that - they just need to be loaded into the appropriate $_GET variables; for example:

  $_GET["q"] = "men";
  $_GET["sort"] = "priceAsc";

Cheers,
David

Submitted by mally on Fri, 2007-12-14 23:06

great, that worked..

two more questions

1 - It only shows 10 results, when a normal search shows about 3 pages of 10. is it possible to get the full search?
2 - Is there a way I could do something similar from a different website, so basically pull the data accross?

Submitted by support on Sat, 2007-12-15 10:39

Hi Mal,

Yes - to get the full search results, look for the following line in your new searchcode.php file:

$sql .= " LIMIT ".$offset.",".$config_resultsPerPage;

Simply delete or comment out this line to get the full search results.

Regarding your second query about getting results onto a different site (presumably on a different web server so without access to the Price Tapestry scripts?), I have had a couple of enquiries about this recently so I will have a look at ways to do it and post a separate thread on this shortly...

Cheers,
David.

Submitted by mally on Sun, 2007-12-16 18:58

Hi David,

thanks very much. Did you get a chance to look at how to do this from another website and include the results?

Thanks

Mally

Submitted by support on Mon, 2007-12-17 11:38

Hi Mally,

Not yet - there's quite a lot involved in doing that, but i'll post a new thread once I have something for people to use.

Cheers,
David.

Submitted by clickspace on Thu, 2008-02-21 16:01

Hi David,

I am trying to create a custom page containing search results as detailed on this thread.

I have made a copy of search.php down to

require("html/header.php");

...then removed the rest and called this file searchcode.php

My custom page looks something like this:

<?php
  require("html/header.php");
  require("html/leftnav.php");
  require("html/breadcrumb-index.php");
  print "<p>Here is your paragraph or 2...</p>";
  print "<p>You could even break out of PHP of course if you want...</p>";
  // now preload $_GET["q"] to be the query you want to display search results for
  $_GET["q"] = "electronics";
  // now bring in the search code
  require("searchcode.php");
  // now use Price Tapestry's search results HTML module to display the results
  require("html/searchresults.php");
  // and finally the common footer, although you could always add more content first
  require("html/footer.php");
?>

I am receiving the following error:

Warning: Cannot modify header information - headers already sent by (output started at /home/compared/public_html/shop/html/header.php:13) in /home/compared/public_html/shop/searchcode.php on line 27

Which seems to point to this section of searchcode.php

// modified to do this http://www.pricetapestry.com/node/1727
   if (!$rewrite)
  {
     $location = $config_baseHREF."search/".$sort."/".tapestry_hyphenate($q)."/";
     if ($page > 1)
     {
       $location .= $page.".html";
     }
     header("Location: ".$location);
     exit();
  }
// end mod

Any ideas?

Cheers,
Steven

Submitted by support on Thu, 2008-02-21 16:48

Hi Steven,

With the redirect mod you will need to remove that section of code from searchcode.php - that should be all it is...!

Cheers,
David.

Submitted by clickspace on Thu, 2008-02-21 16:54

Spot on! Thanks David

Submitted by mally on Thu, 2008-03-06 18:07

Hi David

is it possible to have multiple search terms such as below so they are all shown if they exist?

$_GET["q"] = "men|mens|male";

thanks

Mally
Magazine Subscriptions

Submitted by support on Thu, 2008-03-06 18:21

Hello Mally,

Try it just with the words you want but with spaces between the words rather than "|". However with this particular example the search code might need to be modified to use the non-full text index using an OR comparison in the case where words < 4 characters are in the query.

If you don't get the results you want, if you could email me your searchcode.php file as an attachment, I'll modify the query as required...

Cheers,
David.

Submitted by discountdriven on Thu, 2008-03-06 20:40

Is there a way to get the full results, but have them listed 10 per page, as they would be in a regular search? Removing this line seems to list all the results on one page.

Submitted by support on Fri, 2008-03-07 08:44

Hi Stacy,

Paging should work but it depends a bit on how you have set it up. If you email me a link to one of your fixed search pages i'll take a look for you (and let me know if it's OK to FTP in)...

Cheers,
David.

Submitted by mally on Fri, 2008-06-06 18:24

Hello David

I've added this to 3 issues for £1

can I ask how to get it to sort it into alphabetical order by name?

Thank

Mally

Submitted by support on Fri, 2008-06-06 19:17

Hi Mally,

Easily done, but search.php needs to be modified first to support an alphabetic sort. In search.php, look for the following code (line 16 in the distribution):

$orderByDefault["rating"] = "rating DESC";

...and ADD the following line immediately after that line:

$orderByDefault["name"] = "name ASC";

Then, in the code you have inserted per the instructions in this thread, where you have pre-loaded the $_GET["q"] variable using:

  $_GET["q"] = "electronics";

...also preload the $_GET["sort"] variable as follows:

  $_GET["sort"] = "name";

That should do the trick!

Cheers,
David.

Submitted by mally on Fri, 2008-06-06 22:57

Hi David

I've done the above but it still out of order http://www.magazinesubscription.co.uk/3issuesfor1.php

Mally

Submitted by support on Sat, 2008-06-07 07:30

Hi Mal,

Could you email me over your modified search.php and 3issuesfor1.php and i'll take a look...(zipped if possible) - and at the same time sitemapquery.php in relation to your other post and I'll take a look at that also...

Cheers,
David.

Submitted by mally on Mon, 2008-08-25 17:52

Hello David

Ref my question above

1 - It only shows 10 results, when a normal search shows about 3 pages of 10. is it possible to get the full search?

if theres more than 10 items, there no option to see page 2, 3 and so on.

Can you check?

Thanks

MAlly

Submitted by support on Tue, 2008-08-26 07:36

Hi Mally,

Is this still an issue - I notice from your 3 issues for £1 that you are now showing all results (which can be achieved by changing $config_resultsPerPage in the special pages after config.php has been included)...

If not, if you could send me over your 3issuesfor1.php i'll check it out for you...

Cheers,
David.