Forums / General Questions / Using php next to Category descriptions

Using php next to Category descriptions

Locked

Views: 2,725

Results 1 to 20 of 21
This thread is locked. New replies are disabled.
17 Sep 2010, 7:15 PM
#1
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Using php next to Category descriptions

I'm trying to run a block of PHP code on the category descriptions page. I set this to be the categories description but it doesn't seem to execute, it just displays it instead. Can anyone help? Here is the code:

<?php  
 if ($featured_products->RecordCount() > 0) {
   for ($i = 0; $i < $featured_products->RecordCount(); $i++) {
   echo '<div class="categoryListBoxContents" style="width:33%;">';
   echo '<a href="' . zen_href_link(FILENAME_DEFAULT, 'main_page=product_info&products_id=' . $featured_products->fields['products_id']) . '">';
   echo zen_get_products_image($featured_products->fields['products_id']);
   echo '</A></div>';     
} 
} ?> 
17 Sep 2010, 7:35 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Using php next to Category descriptions

I'm trying to run a block of PHP code on the category descriptions page.
I believe that only html is allowed in the description block

Zen-Venom Get Bitten

17 Sep 2010, 7:42 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Using php next to Category descriptions

I don't understand what you're trying to do with the code you posted.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

17 Sep 2010, 9:06 PM
#4
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Using php next to Category descriptions

DrByte:

I don't understand what you're trying to do with the code you posted.

I forgot to post up the MySQL coding that I put in header.php

   $featured_products_query = "SELECT feature.products_id, product_info.products_image, product_info.products_price, product_desc.products_name FROM " . TABLE_FEATURED . " as feature, " . TABLE_PRODUCTS . " as product_info, " .  TABLE_PRODUCTS_DESCRIPTION . " as product_desc, " . TABLE_PRODUCTS_TO_CATEGORIES . " as ptc WHERE feature.products_id = product_info.products_id AND feature.products_id = product_desc.products_id and feature.products_id = ptc.products_id AND ptc.categories_id = :categoriesID ORDER BY rand() LIMIT 3";
   $featured_products_query = $db->bindVars($featured_products_query, ':categoriesID', $current_category_id, 'integer');

   $featured_products = $db->Execute($featured_products_query);

Essentially, look at featured products for all products within a given category (the category that the user is looking at). Select three at random and return the row values as defined above. (Product ID, image, price, and name).

The code in the original post, generally cycles through the data and returns the row values for it.

17 Sep 2010, 10:45 PM
#5
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,680
Plugin Contributions:
0

Re: Using php next to Category descriptions

Doesn't the Featured Products block already do that?

Please do not PM for support issues: a private solution doesn't benefit the community.

Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

17 Sep 2010, 10:46 PM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Using php next to Category descriptions

So essentially, an additional featured centerbox but inside the description. Why don't you want to use the regular featured centerbox (set to three products)?

17 Sep 2010, 10:55 PM
#7
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Using php next to Category descriptions

gjh42:

So essentially, an additional featured centerbox but inside the description. Why don't you want to use the regular featured centerbox (set to three products)?

I actually forgot that was there but wanted to embed it in the description along with some other stuff.

17 Sep 2010, 11:09 PM
#8
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Using php next to Category descriptions

gjh42:

So essentially, an additional featured centerbox but inside the description. Why don't you want to use the regular featured centerbox (set to three products)?

To further:

  • I used the center box but it doesn't randomly select three products, it just selects the first three available.
  • The parent category is show for the header, not the child where it's located.
  • The configuration places the center box below the product listing, not above where I'm trying to get it to show. (I know how to fix this one but was hoping on something not involving me ripping into ZenCart too much).

Is an example: http://www.justuptowngames.com/index.php?main_page=index&cPath=1_2_61

19 Sep 2010, 10:25 AM
#9
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Using php next to Category descriptions

I too am also looking to use PHP in my categories description but for different reason. Can this be done?

19 Sep 2010, 10:32 AM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Using php next to Category descriptions

What retched is doing is not actually including PHP in the category descriptions, but rather including additional content to be displayed via the template directly above/below the category description when the category description is displayed.

You can do the same simply by altering your template files as needed.

However, embedding PHP code into the actual HTML of the category description via your admin is NOT supported in Zen Cart.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

19 Sep 2010, 2:59 PM
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Using php next to Category descriptions

You could use a version of swguy's boilerplate code to evaluate some PHP and substitute its output for a placeholder in the description output.

19 Sep 2010, 3:26 PM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Using php next to Category descriptions

Adapted from swguy's boilerplate tips on his site (referenced in http://www.zen-cart.com/forum/showthread.php?t=120888%29:

/includes/templates/custom/templates/tpl_product_info_display.php

Change

 <!--bof Product description -->
<?php if ($products_description != '') { ?>
<div id="productDescription" class="productGeneral biggerText"><?php echo stripslashes($products_description); ?></div>
<?php } ?>
<!--eof Product description -->

to

 <!--bof Product description -->
<?php if ($products_description != '') { ?>
<?php 
$php_content = '';//build content to be substituted for PHP_SUB in description
if ($featured_products->RecordCount() > 0) {
  for ($i = 0; $i < $featured_products->RecordCount(); $i++) {
    $php_content .= '<div class="categoryListBoxContents" style="width:33%;">';
    $php_content .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'main_page=product_info&products_id=' . $featured_products->fields['products_id']) . '">';
    $php_content .= zen_get_products_image($featured_products->fields['products_id']);
    $php_content .= '</a></div>';     
  } 
}
$products_description = str_replace('PHP_SUB', $php_content, $products_description);

?>
<div id="productDescription" class="productGeneral biggerText"><?php echo stripslashes($products_description); ?></div>
<?php echo stripslashes($stripped_products_description); ?></div>
<?php } ?>
<!--eof Product description -->
19 Sep 2010, 3:37 PM
#13
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Using php next to Category descriptions

The above follows from the boilerplate discussion for the product info page; it would be a different file and slightly different code for the category listing page, but the same principle applies.

25 Sep 2010, 10:25 PM
#14
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Using php next to Category descriptions

Thanks for the reply, I am not that great with PHP and got a little confused trying it

26 Sep 2010, 7:54 PM
#15
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Using php next to Category descriptions

/includes/templates/your_template/templates/tpl_index_categories.php```php

<?php // **********insert boilerplate code here to substitute in description********** // categories_description if ($current_categories_description != '') { ?> <div id="categoryDescription" class="catDescContent"><?php echo $current_categories_description; ?></div> <?php } // categories_description ?> <!-- BOF: Display grid of available sub-categories, if any --> ```
26 Sep 2010, 8:13 PM
#16
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Using php next to Category descriptions

Better description of method:```php

<?php // categories_description if ($current_categories_description != '') { $php_content = '';//build content to be substituted for PHP_SUB in description $php_content .= 'whatever code you need to determine the substituted content for this category'; $current_categories_description = str_replace('PHP_SUB', $php_content, $current_categories_description); ?> <div id="categoryDescription" class="catDescContent"><?php echo $current_categories_description; ?></div> <?php } // categories_description ?> ```
27 Sep 2010, 6:20 AM
#17
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Using php next to Category descriptions

This looks really useful but what if I just wanted it to pull the actual content from the database that doesn't have php?

27 Sep 2010, 7:50 AM
#18
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Using php next to Category descriptions

You need some PHP code to run a SQL query or otherwise determine the information that is going to be added. What content do you want to fetch from the db?

27 Sep 2010, 9:51 AM
#19
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Using php next to Category descriptions

wow, i spent at least 6 hours playing around with the coding (should prob start learning PHP) but that worked great.

As always, thanks for the help.

27 Sep 2010, 6:05 PM
#20
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Using php next to Category descriptions

gjh42:

You need some PHP code to run a SQL query or otherwise determine the information that is going to be added. What content do you want to fetch from the db?

I already have the mysql coding setup in the header.php file of the file. Pretty much I want take the results of that query and output it as displayed in post 1.