Forum

Thread tagged as: Question

Featured Product on homepage from List/Detail product page.

Hi There

I have a product list on products.php but I'd like to show selected products on the homepage

Can I do that? and what would be the best way to bring those in and select which ones should appear there?

Currently using this code on my products.php page...

<?php

     perch_content_create('Products', array(
          'template'  => 'product-detail.html',
          'multiple'  => true,
          'edit-mode' => 'listdetail',
     ));


     if (perch_get('s')) {

          // Detail mode
          perch_content_custom('Products', array(
               'template' => 'product-detail.html',
               'filter'   => 'slug',
               'match'    => 'eq',
               'value'    => perch_get('s'),
               'count'    => 1,
          )); 

     } else {

          // List mode
          perch_content_custom('Product', array(
               'template' => 'product-listing.html',
          )); 
     }

?>      

Many thanks in advance

Nik

Nik Gill

Nik Gill 1 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Add a field to the product to indicate that it should be featured.

Use perch_content_custom() to put the product on the listing page, and add a filter that matches only products with the new featured field set.

Ok, so dealing with the pulling the products in to the homepage.

I'm putting this on my homepage... it's not working though (I've not done anything before pulling in data from another page that's been put together like this... only news articles.

    <?php 
        perch_content_custom('Products', array(
               'template' => 'featured-product.html',
               'filter'   => 'slug',
               'match'    => 'eq',
               'value'    => perch_get('s'),
               'count'    => 1,
          )); 
?>  

Actually, this is probably better... I think... though it's still not displaying anything

<?php
perch_content_custom('Products', array(
    'page'=>'/products.php',
    'filter'=>'featured',
    'match'=>'gte',
    'value'=>'featured',
    'template'=>'featured-product.html'
));
?>

Actually scratch that, I've got it working... I didn't re-save the product item (so the existing entries didn't have the filter applied) clicking save on all the products made it show up!

Cheers for the pointers