You are here:  » Locate Articles by search term


Locate Articles by search term

Submitted by webie on Thu, 2008-02-14 01:23 in

Hi Dave,

Is it possible to have articles in a directory named by product name and then display link on search results to view article.

I thought of the idea based on how you wrote the code to match and display merchant logos.

Example would be say someone searches for digital camera and we get a list of results and lets say the first result was sony slr digital camera and we had a article named sony-slr-digital-camera.html and if the code matched the name with an article in articles directory to display link read article along side the product results?.

Many thanks

Darren

Submitted by support on Thu, 2008-02-14 12:09

Hi Darren,

Yes - it's very easy to do that sort of thing.

Just make a directory called "articles". Then, in html/searchresults.php, if you want to display the content of your article file beneath the description, look for the following code:

<p><?php print substr($product["description"],0,250); ?></p>

...and then add the following code on the next line. This assumes that you are naming your articles with "-" instead of SPACEs, as per your example filename.

<?php
$articleFilename 
"articles/".str_replace(" ","-",$product["name"]).".html";
if (
file_exists($articleFilename))
{
  require(
$articleFilename);
}
?>

That should be all there is to it!

Cheers,
David.

Submitted by webie on Thu, 2008-02-14 12:38

Hi Dave

Big thank you again support is fantastic

cheers all the best

Darren

Submitted by webie on Thu, 2008-02-14 12:46

Hi Dave

just give it a test works great loads the artice in the search results can just show a article link instead of loading in to search results so when user clicks the link it opens up the article.

cheers

Darren

Submitted by support on Thu, 2008-02-14 12:48

No probs - something like this should do the trick:

<?php
$articleFilename 
"articles/".str_replace(" ","-",$product["name"]).".html";
if (
file_exists($articleFilename))
{
  print 
"<p><a href='".$articleFilename."'>Click here to read more about ".$product["name"]."</a></p>";
}
?>

Cheers,
David.

Submitted by webie on Fri, 2008-02-15 12:06

Hi Dave,

Hope you are well I just thought of a small problem which will surface with my idea of displaying articles with search results is there a way that we can modify the code to display articles matched against merchant name.

Example

If we had two product named articles Indesit WIDL126W Washer Dryer from multipull merchants then the code would not know from what merchant. can we modify the code to match article per product name and merchant name.

Indesit-WIDL126W-Washer-Dryer-merchant-name1.html
Indesit-WIDL126W-Washer-Dryer-merchant-name2.html

many thanks

Darren

Submitted by support on Fri, 2008-02-15 12:08

Hi Darren,

Sure - that's straight forward enough; just need to add $product["merchant"] to the filename:

<?php
$articleFilename 
"articles/".str_replace(" ","-",$product["name"])."-".str_replace(" ","-",$product["merchant"]).".html";
if (
file_exists($articleFilename))
{
  require(
$articleFilename);
}
?>

Again, this will have "-" instead of SPACES in the filename....

Cheers!
David.

Submitted by Rocket32 on Sat, 2020-08-15 01:59

Hello David, I would like to do something a little different. I want to add an article directory to the site, but keep look & feel of the pt product site similar to adding a blank page. I want to create or add articles to site for additional content inside an article directory. Maybe use the blankpage.php page add an article to it & later add more articles. Also get article individual pages to end in .html just as the product site. First page of article can use a-z function similar to the category & merchant page.

Submitted by support on Tue, 2020-08-18 08:23

Hi,

Here's a very basic Articles container; creating the path

articles/ (index)
articles/Article-Title.html

First add the following to .htaccess

RewriteRule ^articles/$ articles.php
RewriteRule ^articles/(.*).html$ articles.php?t=$1 [B,L]

Next, create your article files as .html in a new articles/ sub-directory of the Price Tapestry installation with filename being the title (including spaces) and ending in .html e.g.

articles/This Is Article 1.html
articles/This Is Article 2.html

(make sure only to use characters used in clean URLs as the value will be normalised and hyphens used in places of spaces)

And then create the following new file articles.php

<?php
  
require("includes/common.php");
  
$t = (isset($_GET["t"])?tapestry_normalise($_GET["t"]):"");
  
$banner["breadcrumbs"] = array();
  
$banner["breadcrumbs"][] = array("title"=>"Articles","href"=>$config_baseHREF."articles/");
  if (
$t)
  {
    
$filename "articles/".$t.".html";
    if (!
file_exists($filename))
    {
      
header("HTTP/1.0 404 Not Found");
      exit();
    }
    
$header["title"] = $t;
    
$banner["breadcrumbs"][] = array("title"=>$t,"href"=>"#");
  }
  else
  {
    
$header["title"] = "Articles";
  }
  require(
"html/header.php");
  require(
"html/menu.php");
  require(
"html/searchform.php");
  require(
"html/banner.php");
  print 
"<div class='row'>";
    print 
"<div class='small-12 columns'>";
      if (
$t)
      {
        require(
$filename);
      }
      else
      {
        
$articles = array();
        
$dh opendir("articles");
        while ((
$filename readdir($dh)) !== FALSE)
        {
          if (!
strpos($filename,".html")) continue;
          
$articles[] = str_replace(".html","",$filename);
        }
        
closedir($dh);
        
sort($articles);
        print 
"<ul>";
        foreach(
$articles as $title)
        {
          print 
"<li><a href='".$config_baseHREF."articles/".tapestry_hyphenate($title).".html'>".$title."</a></li>";
        }
        print 
"</ul>";
      }
    print 
"</div>";
  print 
"</div>";
  require(
"html/footer.php");
?>

Cheers,
David.
--
PriceTapestry.com