You are here:  » Multiple Featured Pages?

Active Forum Topics


Multiple Featured Pages?

Submitted by stonecold111 on Tue, 2013-08-20 16:16 in

Hi,

Is it possible to have additional featured pages specially for assigned categories in single PT installation? Like when I feature a product from a specific category it'll go to a specific featured page.

Submitted by support on Tue, 2013-08-20 17:20

Hi,

Sure - you can use the Featured Products shortcode with a section prefix, e.g.

[pto featured="section"]

And this will display Featured Products configured in the Featured Products area of your Price Tapestry area but prefixed with the category "section".

So let's say you want to create a page about logic games, in Featured Products admin create your product list e.g.

logic/Featured Logic Problem Game 1
logic/Featured Logic Problem Game 2
logic/Featured Logic Problem Game 3

And then on your page, add the shortcode:

[pto featured="logic"]

Cheers,
David.
--
PriceTapestry.com

Submitted by stonecold111 on Tue, 2013-08-20 18:38

It works!
Is it possible to combine a few categories? e.g: [pto featured="logic","puzzle","family game"]

Submitted by support on Wed, 2013-08-21 07:54

Hi,

You could do that easily with a small mod. In pto_featured.php look for the following code at line 27:

  $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."featured` WHERE name LIKE '".$wpdb->escape($section)."/%' ORDER BY sequence";

...and REPLACE with:

  $sections = explode(",",$section);
  $wheres = array();
  foreach($sections as $section)
  {
    $wheres[] = "name LIKE '".$wpdb->escape($section)."/%'";
  }
  $where = implode(" OR ",$wheres);
  $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."featured` WHERE ".$where." ORDER BY sequence";

And then use as your shortcode:

[pto featured="logic,puzzle,family game"]

Cheers,
David.
--
PriceTapestry.com

Submitted by stonecold111 on Wed, 2013-08-21 11:42

Thank you. I'll try it tonight. Does this shortcode allow a mix of categories, brands and merchants in one section?

Submitted by support on Wed, 2013-08-21 12:02

Hi,

Featured Products are configured independently of any Merchant, Category or Brand - however many people use mods to show `n` random "Featured Products" from a given merchant, category, or brand - if that's what you wanted to do just let me know...

Cheers,
David.
--
PriceTapestry.com

Submitted by stonecold111 on Wed, 2013-08-21 15:24

Thank you. I'll email you when I need the feature. I know how the shortcode works now. It's just like a tag - You can name it whatever you want. All you need to do is preface "XXX/" to the featured products in the featured admin.

Submitted by ChrisNBC on Tue, 2013-10-01 15:45

Hi David,

I would like to implement something similar to what's explained above on one of my sites. Ideally, I would like to create 3 or 4 separate featured pages within the same PT installation but I think what's explained above is for a Wordpress install?...please could you tell me if there is a simple way to achieve the same result but for a NON WP PT install?

Thanks in advance.

Regards

Submitted by support on Wed, 2013-10-02 11:12

Hi Chris,

Yes - the above is regarding the plugin but it's based on the same method for standalone which is documented in this thread...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2013-10-02 12:13

Hi David,

Thanks for your quick response. I had a look at the thread you mention which I think I have used before when I created multiple categories within a single page. I wondered if you had a chance to review the post I made today on the same subject with an alternative solution I was considering where I would create multiple featured pages and then filter the products displayed by testing the data using the logic below which I already use on my products page:

<?php
  
foreach($prices["products"] as $product)
  {
    if (
$product["field1"]=="yes")
    {
      
$type 1;
    }
    elseif (
$product["field2"]=="yes")
    {
      
$type 2;
    }
    elseif (
$product["field3"]=="yes")
    {
      
$type 3;
    }
    
$prices[$type][] = $product;
  }
?>

Using this method, I would negate the need to constantly maintain the featured categories, since the selector would effectively be in the feed. Do you think this would work?
Thanks in advance.
Regards
Chris

Submitted by support on Wed, 2013-10-02 12:57

Hi Chris,

Sure - you could implement the "random" featured products limited by type. If you started with the code from node 3243 but instead of the SQL to select from the featured products table:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY sequence";

...REPLACE with:

    switch($featuredType)
    {
      case "1":
        $where = " field1='yes' ";
        break;
      case "2":
        $where = " field2='yes' ";
        break;
      case "3":
        $where = " field3='yes' ";
        break;
    }
    $sql = "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." LIMIT 3";

And then to create a page with 3 random type 2 products, use the following outline:

type2.php (use a more appropriate name of course!)

<?php
  
require("includes/common.php");
  
$header["title"] = "Page Title";
  
$header["meta"]["description"] = "Meta Description";
  
$header["meta"]["keywords"] = "meta, keywords";
  require(
"html/header.php");
  
$featuredType 2;
  require(
"featuredproducts.php");
  require(
"html/footer.php");
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Fri, 2013-10-04 10:03

Hi David,

Thanks for the code above which I have implemented. It's nearly there (and maybe it was my initial explanation) but what I need to do is have multiple versions of the featured page containing only items I have added as featured products which are then filtered into the three types. So for example the first version of the page will contain items in featured products which are also 'case 1'. I think the above code selects from the whole 'products' table? I wondered if you could suggest what I would need to alter in the code to select items from the featured products table instead? I experimented with a few variations of the code but the results were not quite right.

The code I have currently is:

<?php
  
unset($featured);switch($featuredType)
    {
      case 
"1":
        
$where " paymonthly='yes' ";
        break;
      case 
"2":
        
$where " payg='yes' ";
        break;
      case 
"3":
        
$where " simo='yes' ";
        break;
    }
   
$sql "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." LIMIT 200";
  if (
database_querySelect($sql,$rows))
  {
    
$sqlNames = array();
    
$sqlCase "CASE normalised_name";
    foreach(
$rows as $featured)
    {
      
$featured["name"] = str_replace($featuredproducts_category."/","",$featured["name"]);
      
$featured["name"] = tapestry_normalise($featured["name"]);
      
$sqlNames[] = "'".$featured["name"]."'";
      
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
    }
    
$sqlCase .= " END AS sequence";
    
$sqlIn implode(",",$sqlNames);
    
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
    
database_querySelect($sql,$rows);
    
$featured["products"] = $rows;
    foreach(
$featured["products"] as $k => $product)
    {
      
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
      
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
    }
  }
  if (isset(
$featured)) require("html/featured.php");
?>

Thanks in advance.
Regards
Chris

Submitted by support on Fri, 2013-10-04 11:51

Hi Chris,

Ah - i'm with you - in that case, we just need to add an additional WHERE clause with a
sub-select to limit the results to only those listed in Featured Products. In place of
this line:

   $sql = "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." LIMIT 200";

...have a go with:

   $sql = "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND name IN (SELECT name FROM `".$config_databaseTablePrefix."featured`)";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Fri, 2013-10-04 12:09

Hi David,

Thanks as always for your quick response. I updated the code as you suggest above but no results are now returned at all (when I know there are results which should appear). The code now looks like:

<?php
  
unset($featured);switch($featuredType)
    {
      case 
"1":
        
$where " paymonthly='yes' ";
        break;
      case 
"2":
        
$where " payg='yes' ";
        break;
      case 
"3":
        
$where " simo='yes' ";
        break;
    } 
$sql "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND name IN (SELECT name FROM `".$config_databaseTablePrefix."featured`)";
  if (
database_querySelect($sql,$rows))
  {
    
$sqlNames = array();
    
$sqlCase "CASE normalised_name";
    foreach(
$rows as $featured)
    {
      
$featured["name"] = str_replace($featuredproducts_category."/","",$featured["name"]);
      
$featured["name"] = tapestry_normalise($featured["name"]);
      
$sqlNames[] = "'".$featured["name"]."'";
      
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
    }
    
$sqlCase .= " END AS sequence";
    
$sqlIn implode(",",$sqlNames);
    
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
    
database_querySelect($sql,$rows);
    
$featured["products"] = $rows;
    foreach(
$featured["products"] as $k => $product)
    {
      
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
      
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
    }
  }
  if (isset(
$featured)) require("html/featured.php");
?>

I wondered if you could suggest what might be going wrong? Also, I notice there is now no LIMIT clause to specify number of results displayed...would be grateful if you could advise if this could be added back in.

Thanks in advance.
Regards
Chris

Submitted by support on Fri, 2013-10-04 12:41

Hi Chris,

Are the products listed in Featured Products without any section prefixes, e.g. just

Product 1
Product 2
etc.

...and not

payg/Product 1
payg/Product 2

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Fri, 2013-10-04 14:34

Hi David,

The products in the 'featured' list have prefixes as the main index.php
pages uses them. Ideally, I would like to use the prefixes in the other
featured pages too. Do you think the prefixes are the cause of the
current problem?

Regards
Chris

Submitted by support on Fri, 2013-10-04 14:50

Hi Chris,

Just to clarify then, you have sections that are not related to type 1/2/3
products, but for the above code you want to select featured products of
type 1,2 or 3 from all featured products listed regardless of section?

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Fri, 2013-10-04 15:18

Hi David,

My aim is to have four index pages...

Index.php - is already created and contains all types 1/2 and 3.
It also contains a number of sections, e.g smart phones,
4G Compatible phones, latest models etc

For the other three index pages I plan to create one for PAYG, one for PAY Monthly and one for SIM only.

The products on the 3 new index pages will be filtered by type 1/2/3
and these 'types' represent PAYG, PAY Monthly and SIM only.

Within the three new index pages I plan to create sections and for ease,
I will probably use the same section headings for each page that are
already used on index.php (probably creating new sections for the SIM
only index page).

In answer to your closing question, I want to select featured products
of types 1,2 or 3 from featured products listed in sections as they
are already on the existing index.php page. I hope this clarifies
what I'm trying to achieve?

Thanks in advance.

Regards
Chris

Submitted by support on Fri, 2013-10-04 17:06

Hi Chris,

Got it - will need to manually construct the list of existing featured products
(regardless of section/ prefix) instead of using a sub-query, but no problem -
based on the your last full version posted above, have a go with;

<?php
  
unset($featured);
  switch(
$featuredType)
  {
    case 
"1":
      
$where " paymonthly='yes' ";
      break;
    case 
"2":
      
$where " payg='yes' ";
      break;
    case 
"3":
      
$where " simo='yes' ";
      break;
  }
  
$sql "SELECT name FROM `".$config_databaseTablePrefix."featured`";
  
$ins = array();
  if (
database_querySelect($sql,$rows))
  {
    foreach(
$rows as $row)
    {
      if (
strpos($row["name"],"/"))
      {
        
$parts explode("/",$row["name"]);
        
$name $parts[0];
      }
      else
      {
        
$name $row["name"];
      }
      
$ins[] = "'".database_safe($name)."'";
    }
  }
  
$in implode(",",$ins);
  
$sql "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND name IN (".$in.")";
  if (
database_querySelect($sql,$rows))
  {
    
$sqlNames = array();
    
$sqlCase "CASE normalised_name";
    foreach(
$rows as $featured)
    {
      
$featured["name"] = str_replace($featuredproducts_category."/","",$featured["name"]);
      
$featured["name"] = tapestry_normalise($featured["name"]);
      
$sqlNames[] = "'".$featured["name"]."'";
      
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
    }
    
$sqlCase .= " END AS sequence";
    
$sqlIn implode(",",$sqlNames);
    
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
    
database_querySelect($sql,$rows);
    
$featured["products"] = $rows;
    foreach(
$featured["products"] as $k => $product)
    {
      
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
      
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
    }
  }
  if (isset(
$featured)) require("html/featured.php");
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Mon, 2013-10-07 10:51

Hi David,

Hope you had a good weekend.

Thanks for the attached which I have implemented. However, all that's displayed
are the three models I added to 'featured products' which do not have a section
prefix. Also, I noticed that although the filter is set to 'type 2' I also get
results from 'type 1' displayed.

I'm not quite sure what you mean when you say above "will need to manually
construct the list of existing featured products (regardless of section/ prefix)
instead of using a sub-query"?

I added categories to index2.php to try to get 'sections' to appear but all I
got was the three products I added to 'featured products' which do not have a
'section' prefixes.

Would be grateful if you could point me in the right direction re setting up
the 'sections' for the extra index pages. Also, I wondered if you might have
any ideas how I could resolve types 1 and 2 being displayed when the filter
is set to 2?

Thanks in advance.
Regards
Chris

Submitted by support on Mon, 2013-10-07 11:21

Hi Chris,

Regarding "will need to manually construct the list of existing featured products
(regardless of section/ prefix) instead of using a sub-query"

...I had implemented this in the above so if you could perhaps add some debug code and
let me know the SQL being generated by the code that will help. In your latest version,
where you have this line:

  $sql = "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND name IN (".$in.")";

...REPLACE with:

  $sql = "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE
".$where." AND name IN (".$in.")";
  print "[".$sql."]";

This will display the SQL being generated - if you could copy what is displayed into a
reply I'll check that out...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Mon, 2013-10-07 12:30

Hi David,

Thanks for the quick reply. I've changed the code and the sql message reads:

{code saved}

Regards
Chris

Submitted by support on Mon, 2013-10-07 13:47

Hi Chris,

Thanks for that - mistake spotted - in the mod, after removing the debug code if you
look for this line:

        $name = $parts[0];

...which should be:

        $name = $parts[1];

- it was looking for the name in the prefix part not the actual name part!

If still no joy - if you could email me the entire file
containing the above mod I'll set-up a simulation of your database mods on my
test server to check it out further...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Mon, 2013-10-07 14:02

Hi David,

Thanks for the mod which I have applied. The display result has changed,
now quite a number of 'featured products' are displayed but without any
'sections'. I just wondered if there is anything else I need to do to
get the sections to appear? Also, please could you tell me where the
control is for regulating the number of items returned?

Thanks in advance.
Regards
Chris

Submitted by support on Mon, 2013-10-07 14:41

Hi Chris,

Sounds like it's basically working now - to apply a limit, in place of the
existing SELECT SQL:

  $sql = "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND name IN (".$in.")";

...for a limit of 3, use:

  $sql = "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND name IN (".$in.") LIMIT 3";

There's no concept of section in terms of display - that's a "behind the scenes" thing
for you to control which set of Featured Products are displayed, but in this case, it's
entirely down to your "type" derivation by way of a WHERE clause.

The tidiest thing to do would be to combine the 2, here's a complete featuredproducts.php

<?php
  
unset($featured);
  if (isset(
$featuredType))
  {
    switch(
$featuredType)
    {
      case 
"1":
        
$where " paymonthly='yes' ";
        break;
      case 
"2":
        
$where " payg='yes' ";
        break;
      case 
"3":
        
$where " simo='yes' ";
        break;
    }
    
$sql "SELECT name FROM `".$config_databaseTablePrefix."featured`";
    
$ins = array();
    if (
database_querySelect($sql,$rows))
    {
      foreach(
$rows as $row)
      {
        if (
strpos($row["name"],"/"))
        {
          
$parts explode("/",$row["name"]);
          
$name $parts[0];
        }
        else
        {
          
$name $row["name"];
        }
        
$ins[] = "'".database_safe($name)."'";
      }
    }
    
$in implode(",",$ins);
    
$sql "SELECT name, 1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND name IN (".$in.")";
  }
  elseif (isset(
$featuredSection))
  {
    
$sql "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".database_safe($featuredSection)."/%'";
  }
  if (
database_querySelect($sql,$rows))
  {
    
$sqlNames = array();
    
$sqlCase "CASE normalised_name";
    foreach(
$rows as $featured)
    {
      
$featured["name"] = str_replace($featuredproducts_category."/","",$featured["name"]);
      
$featured["name"] = tapestry_normalise($featured["name"]);
      
$sqlNames[] = "'".$featured["name"]."'";
      
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
    }
    
$sqlCase .= " END AS sequence";
    
$sqlIn implode(",",$sqlNames);
    
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
    
database_querySelect($sql,$rows);
    
$featured["products"] = $rows;
    foreach(
$featured["products"] as $k => $product)
    {
      
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
      
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
    }
  }
  if (isset(
$featured)) require("html/featured.php");
  unset(
$featuredType);
  unset(
$featuredSection);
?>

And now you can call either by section, or by section, e.g.

  $featuredSection = "apple";
  require("featuredproducts.php");

Or by type:

  $featuredType = "2";
  require("featuredproducts.php");

Cheers,
David.
--
PriceTapestry.com