Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 6 of 6
How do I use PHP in CMS pages
 
biophonc
Jr. Member
 
Total Posts:  2
Joined:  2009-10-20
 

me too - I just want to say: Thanks a lot, that was exactly what I’ve been looking for.

/biophonc

 
Magento Community Magento Community
Magento Community
Magento Community
 
sjackson
Jr. Member
 
Total Posts:  28
Joined:  2009-11-19
 

I’m also having the issue of the code just stopped working.

Have it working fine on my local machine but as soon as I upload it stops working. The files are the same and I’ve checked and cache is disabled.

Any ideas? It’s very frustrating

 
Magento Community Magento Community
Magento Community
Magento Community
 
cormiston
Jr. Member
 
Total Posts:  4
Joined:  2009-01-19
 

Thanks mayerwin this worked like a charm!

 
Magento Community Magento Community
Magento Community
Magento Community
 
jetsetter
Member
 
Total Posts:  33
Joined:  2008-06-29
 

I’ve got it working in 1.4.  Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan B
Jr. Member
 
Total Posts:  5
Joined:  2010-03-25
 

This was great, I was able to get straight PHP to work just fine through here, but for some reason using PHP to return a MySQL result is breaking the block. Can anyone tell me what I may be doing wrong here? Thanks a lot!

app/code/local/CustTestimonials/Custom/Block/Test.php

<?php
  
class CustTestimonial_Custom_Block_Test extends Mage_Core_Block_Abstract
  {
    
protected function _toHtml()
    
{
      
// put here your custom PHP code with output in $html;
      // use arguments like $this->getMyParam1() , $this->getAnotherParam()

      
$testquery "SELECT * FROM testimonials ORDER BY RAND() LIMIT 1";
      
$testresult mysql_query($testquery);

      
$row mysql_fetch_row($testresult);
      
$htmlstripslashes($row[1]);

      return 
$html;
    
}
  }
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan B
Jr. Member
 
Total Posts:  5
Joined:  2010-03-25
 

Just figured it out! turns out I was just assuming that Magento automatically connected to the database when it doesn’t. Added the code to connect to the database, and now I’m up and running. Thanks a lot!

 
Magento Community Magento Community
Magento Community
Magento Community
 
lisali
Enthusiast
 
Avatar
Total Posts:  889
Joined:  2008-04-28
London, UK
 

Hi,

How do you get the PHP code to be parsed in the MIDDLE of the page? It seems to ALWAYS be parsed on TOP of the page where the custom block is called. Confused!

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
jemoon
Sr. Member
 
Avatar
Total Posts:  128
Joined:  2008-09-30
Gdansk, Poland
 

Hi,
<b>lisali</b> Looks like I have the same problem… does anyone know what can be done to wrap custom block into divs?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 6 of 6