Page 1 of 1

Use a PHP include to list Products?

Posted: Thu Feb 17, 2011 11:10 pm
by hbuchel
I am just wondering, there are many parts of the template where a list of products is used. This includes the home modules, category page, search results, etc. Is there any downside to moving the loop of code that calls and lists the products to its own .php page, and just using an include on any template file that needs a product list?

I'm mostly asking because the same exact loop is used for all of those pages, however if you want to fix the presentation of how the list looks, you would have to edit EVERY one of those pages. Simply editing one page, for example product_list.php, would be a lot easier.

I'm not asking how to do it, as I've already done it to test it out and make sure it works. I'm more so asking if there is any reason not to, and if anyone more skilled in PHP could weigh in with their own opinion.

Re: Use a PHP include to list Products?

Posted: Thu Feb 17, 2011 11:45 pm
by Qphoria
What you are describing is right.. we copy/paste too much of the same code over and over when we should use more common files across them all. I am looking into how we can make more things generic

Re: Use a PHP include to list Products?

Posted: Fri Feb 18, 2011 12:30 am
by hbuchel
Excellent! But for now though, if I dump all of my product list code into product_list.php and just do a

Code: Select all

<?php include('product_list.php'); ?>
I should be good to go? I'm not sure if theres a wrong way to do it; but thought I'd get some advice first :S

Re: Use a PHP include to list Products?

Posted: Fri Feb 18, 2011 12:50 am
by Qphoria
yea that could work.. try it and see