You are here:  » Featured Products


Featured Products

Submitted by babyuniverse on Thu, 2012-12-13 10:02 in

Hi,

I have changed the featured products to show 21 random products, on the front page at {link saved}
Now when I add my Featured widget I also get 21 products on the side page where I only want 2 or 3.

Can I run two different versions of pto.featured.php, one or frontpage and one for widget.

Thanks
Richard

Submitted by support on Thu, 2012-12-13 10:12

Hi Richard,

It's straight forward to create a special "section" name that will return n random featured products. In pto_featured.php you should still have the following code beginning at line 25:

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

(your mod for random Featured Products I think will be in the ELSE statement immediately after that point)

If you then REPLACE the above section as folllows:

  if ($section)
  {
    $parts = explode(":",$section);
    switch($parts[0])
    {
      case "random":
        $sql = "SELECT name,1 AS sequence FROM `".$pto_config_databaseTablePrefix."products` ORDER BY RAND() LIMIT ".$parts[1];
        break;
      default:
        $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."featured` WHERE name LIKE '".$wpdb->escape($section)."/%' ORDER BY sequence";
        break;
     }
  }

Then in the Widget settings for your Featured Products widget, enter

random:3

...in the Section box for 3 random products rather than your default random code...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by babyuniverse on Sun, 2012-12-23 09:53

Hi David,

That section currently looks like this

if ($section)
{
$sql = "SELECT name,1 AS sequence FROM `".$pto_config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 15";
}
else
{
$sql = "SELECT name,1 AS sequence FROM `".$pto_config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 15";
}

I have tried to add your code but received a few errors.

Thanks
Richard

Submitted by support on Sun, 2012-12-23 10:15

Hi Richard,

Have a go with the following as a complete replacement of the section you included in your last reply above; this restores the default section handling, as well as your existing RAND() LIMIT 15 (which will be your default if no section supplied) and the new

[pto featured="random:5"]

...where a different number of random products is required:

if ($section)
{
  $parts = explode(":",$section);
  switch($parts[0])
  {
    case "random":
      $sql = "SELECT name,1 AS sequence FROM `".$pto_config_databaseTablePrefix."products` ORDER BY RAND() LIMIT ".$parts[1];
      break;
    default:
      $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."featured` WHERE name LIKE '".$wpdb->escape($section)."/%' ORDER BY sequence";
      break;
  }
}
else
{
  $sql = "SELECT name,1 AS sequence FROM `".$pto_config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 15";
}

Cheers,
David.
--
PriceTapestry.com

Submitted by babyuniverse on Thu, 2012-12-27 10:28

Thanks David,

That is working fine, any idea on different CSS styles.
You can see it in action at {link saved}

The top products on the front page need to be smaller, it is currently designed in accordance with the random section on {link saved}

Regards
Richard

Submitted by support on Thu, 2012-12-27 11:03

Hi Richard,

The best thing to do I think would be to derive a CSS class from the section name. I see that your template is already pure CSS rather than using a table, and that you have a pto_featuredProduct class in place, so leaving that as the default, if you edit pto_featured.php and look for the following code at line 75:

  $each = str_replace("\n"," ",$each);

...and REPLACE with:

  $each = str_replace("\n"," ",$each);
  if ($section)
  {
    $class = "pto_featured".str_replace(":","",$section);
    $each = str_replace("pto_featuredProduct",$class,$each);
  }

This will derive a class name pto_featured<section> where <section> is the section name passed in the shortcode but _without_ the ":" character, so [pto featured="random:5"] would replace in the Featured Products / Each template, pto_featuredProduct with pto_featuredrandom5 so you can then add suitable class definitions for that to modify the layout as required...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by twdesigns on Sat, 2014-06-07 19:02

I tired to use the last block of code for creating the random product but it gives me
Parse error: syntax error, unexpected T_ELSE in /wp-content/plugins/pto/pto_featured.php on line 42

Any idea what I'm doing wrong. Using PTO 2.0 plugin.

Submitted by support on Mon, 2014-06-09 08:38

Hi,

I just checked the replacement and it looks fine - double check that it's replacing the whole of the original code as follows beginning at line 25:

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

If it's still causing the error, email me your modified version and I'll check it out right away for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by Selector84 on Mon, 2016-03-07 08:00

David,

Regarding having separate featured items in the widget, my issue is nearly similar.

I have a product carousel that relies on a unique id to be different for every carousel on the page. Since the widget uses the same code only 1 carousel displays.

If you view the page l source over at an example page at {link saved} you will notice the unique id codes.
Working version of the carousel below the search form at {link saved}

Is there a way around this so the featured products below the search form and the widget can have a Separate id to make both carousels work?

Is there not a way to add custom html to the widget? Would also be good mod if this was available in the price tapestry WP settings.

Thanks as always,
Sean.

Submitted by support on Mon, 2016-03-07 09:25

Hello Sean,

One way would be to support a placeholder say %UID% that swaps out with an increasing value each time the Featured Products HTML is generated. To implement this, edit pto_product.php and look for the following code at line 178:

  return $html;

...and REPLACE with:

  global $pto_featuredUID;
  if (!isset($pto_featuredUID))
  {
    $pto_featuredUID = 1;
  }
  else
  {
    $pto_featuredUID++;
  }
  $html = str_replace("%UID%",$pto_featuredUID,$html);
  return $html;

Use the new placeholder throughout Featured Products / Before / Each etc. templates as required, for example:

id="vina-carousel-jshopping%UID%"

The first instance of Featured Products HTML will render the above as id="vina-carousel-jshopping1", the second id="vina-carousel-jshopping2" and so on...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Selector84 on Tue, 2016-03-08 01:13

Hi David,

Had a go where pto_product.php as below:

<?php
$html 
.= $pto_html_prices_after;
  global 
$pto_featuredUID;
  if (!isset(
$pto_featuredUID))
  {
    
$pto_featuredUID 1;
  }
  else
  {
    
$pto_featuredUID++;
  }
  
$html str_replace("%UID%",$pto_featuredUID,$html);
  return 
$html;
}
function 
pto_product_related($product)
?>

and the %UID% place holder is being ignored for some reason?

Thanks,
Sean

Submitted by support on Tue, 2016-03-08 10:07

Hi Sean,

It's pto_featured.php that should be modified rather than pto_product.php - the code does all look very similar as all works in the same way - from looking at the position inserted your mod would have added the same functionality to the price comparison table (so can remain in place if you wanted to use similar functionality there of course...)

Cheers,
David.
--
PriceTapestry.com

Submitted by Selector84 on Thu, 2016-03-10 08:35

Hi David,

Managed to get this to work, but have run into trouble applying CSS styles as the placeholder value depends on the number of carousels on the page. Is there a way if there is only 1 carousel the UID placeholder is 2, but when there is more than 1 carousel the UID placeholder works normally? (Would resolve a 2 carousel page instance)

Final request :) trying to find the post, but it related to adding a clicks count to products via the jump.php page and a DB mod, with this could the featured products be automatically populated by selecting top 10 products by clicks from the db rather than specifying so its an automated process? Wouldn't be bothered if the widget and normal page show the same products. As part of the select command to the DB could this be also selected by category etc.?

Thanks,
Sean

Submitted by support on Thu, 2016-03-10 09:04

Hello Sean,

Rather than attempt to style the carousels by way of #id { ... } which of course will be different with this mod in place, it's probably best instead to assign a custom class to the carousel elements and style via .className { ... } - apologies if mis-understood, let me know if you're still not sure of course.

Here's a thread regarding adding a clicks count - it's quite a comprehensive mod as persisting the clicks value across an import (which by default is a DELETE / INSERT) requires modification to an INSERT / UPDATE method instead;

http://www.pricetapestry.com/node/4584

With that in place, to show Featured Products as most-clicked, edit pto_featured.php and look for the following code at line 31:

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

...and REPLACE with:

    $sql = "SELECT DISTINCT(name),1 AS sequence FROM `".$pto_config_databaseTablePrefix."products` ORDER BY clicks DESC LIMIT 4";

...or to further restrict by category;

    $sql = "SELECT DISTINCT(name),1 AS sequence FROM `".$pto_config_databaseTablePrefix."products` WHERE category='Category Name' ORDER BY clicks DESC LIMIT 4";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Selector84 on Mon, 2016-08-29 16:20

Hi David,

Following on from the above, i'm trying to get the carousel to display on no search results as well. I'v tried to get it working by modifying pto_search.php with the below around line 439:

      $html .= pto_search_navigation();
    }
  }
  else
  {
    $html .= $pto_html_search_noresults;
    //Show related on no results
    $html .= pto_featured($v);
  }
  if ($pto_config_apiSearch)
  {
    $html .= pto_api($pto_config_apiSearch);
  }
  return $html;

it works but the place holder is not working as well as the html for the widget as seen here {link saved}

Any ideas to rectify?

Thanks Sean

Submitted by support on Tue, 2016-08-30 08:10

Hello Sean,

There's no $v variable in context at that point in the code, so as it stands that would show the default Featured Products - if you wanted a section you could use e.g;

     $html .= pto_featured("noresults");

...and that would show Featured Products with the noresults/ prefix, or alternatively, if you have implemented random:n as per the above, then e.g;

     $html .= pto_featured("random:4");

Apologies if i've mis-understood, let me know if you're still not sure of course...

Cheers,
David.
--
PriceTapestry.com