You are here:  » Featured Page - Displayed Product Selection


Featured Page - Displayed Product Selection

Submitted by ChrisNBC on Tue, 2017-05-23 10:29 in

Hi David,

Hope all is going well. Quite a while ago you helped me implement some code to set the products appearing on the ‘featured pages by gender and also by brand. If possible, I would like to add further criteria with the addition of ‘category’. The inclusion of ‘category’ would allow me to feature seasonal products on the homepage. I thought I may be able to modify the code myself but the featured sections code has got quite complex and I wondered if you might possibly be able to suggest what the changes/additions would be to add a further criteria.

Thank in advance.

Best regards
Chris

Submitted by support on Tue, 2017-05-23 11:01

Hi Chris,

I just looked back at the code I helped you with - it looks like a $featured_category variable is already in use but in the context of a Featured Products "section" e.g.

section1/Product 1
section1/Product 2
etc.

...so just in case that is still in place, I would suggest using a new variable $featured_dbcategory, so in your calling code (e.g. in index.php) where you would currently have for example:

$featuredproducts_gender = "MENS";

...use:

$featuredproducts_gender = "MENS";
$featuredproducts_dbcategory = "Category Name";

And then in your custom file featuredproducts.php it looks like you have two instances of the following code:

    if ($featuredproducts_gender)
    {
      $where .= " AND gender='".database_safe($featuredproducts_gender)."'";
    }

...REPLACE each with:

    if ($featuredproducts_gender)
    {
      $where .= " AND gender='".database_safe($featuredproducts_gender)."'";
    }
    if ($featuredproducts_dbcategory)
    {
      $where .= " AND category='".database_safe($featuredproducts_dbcategory)."'";
    }

And then towards the end of the script where the variables are reset;

  $featuredproducts_gender = "";

...REPLACE with;

  $featuredproducts_gender = "";
  $featuredproducts_dbcategory = "";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2017-05-24 11:39

Hi David,

Thanks as always for your quick reply. I tested the above code but nothing is displayed for the section with the category selection added. I think maybe there is something wrong with the code replacement below..

if ($featuredproducts_gender)
{
$where .= " AND gender='".database_safe($featuredproducts_gender)."'";
}
...REPLACE each with:

if ($featuredproducts_dbcategory)
{
$where .= " AND category='".database_safe($featuredproducts_dbcategory)."'";
}

Is the replacement complete? I'm wondering if the replacement should include code for the 'gender' also?

Thanks in advance.

Best regards
Chris

Submitted by support on Wed, 2017-05-24 11:46

Hi Chris,

Spot on - the replacement should have included the gender code, corrected above. However, with the gender WHERE clause removed that query would in fact be relaxed rather than be more specific so I was wondering if you were using Category Hierarchy Mapping on this installation - if that's the case let me know and I'll describe the changes to the above required...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2017-05-24 11:55

Thanks David,

Yes, I am using Category Hierarchy Mapping on this installation..

Best regards
Chris

Submitted by support on Wed, 2017-05-24 12:15

Hi Chris,

Ah ok - in that case, the first replacement (both instances) would need to be as follows;

    if ($featuredproducts_gender)
    {
      $where .= " AND gender='".database_safe($featuredproducts_gender)."'";
    }
    if ($featuredproducts_dbcategory)
    {
      $where .= " AND categoryid='".database_safe($featuredproducts_dbcategory)."'";
    }

And in your calling code, the value for $featuredproducts_dbcategory needs to be a sub-category ID value e.g.

$featuredproducts_dbcategory = "123";

In order to determine the ID value, from your /admin/ area, go to Category Hierarchy Mapping and click Configure next to the sub-category required - you will then be able to see the ID value in the URL, for example:

http://example.com/admin/categories_hierarchy_configure.php?id=123

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2017-05-24 13:40

Thanks David,

The above works perfectly.

Best regards
Chris