atmmultimedia Posted June 27, 2010 Share Posted June 27, 2010 Hello there, I am struggling with a PHP function, I am modifying WordPress I am not a coder. But I've looked at tutorials. Here is my PHP code, I am trying to attach CSS to this line of code. When I try it in WordPress the system crashes and dies. This is my html: <div id="block-1" class="content-box"> <!--<h2>Block #1</h2>--> <div class="entry"> <?php getCustomField('Block #1'); ?> </div> </div> This is the function for the PHP: #----------------------------------------------------------------- # Field Templates #----------------------------------------------------------------- // Get Custom Field Template Values function getCustomField($theField) { global $post; $block = get_post_meta($post->ID, $theField); if($block){ foreach(($block) as $blocks) { echo $blocks; } } } The CSS for: <div id="block-1" class="content-box"> /* Disposable Styles */ *.content-box { /*text-align:center; padding:22px; */ margin-left:80px; margin-top:30px; background:#fff; width:768px; height:432px; margin-bottom:35px;float: left; border: 1px solid #D3D3D3; padding: 5px; background: #fff; } I would like that CSS to work the function. Because in WordPress my client wants to apply video in this box but not on every page. The current code is saying load the box up on every page. I am grateful for any help. Many thanks Link to comment https://forums.phpfreaks.com/topic/205990-attached-css-to-a-php-function/ Share on other sites More sharing options...
Mchl Posted June 27, 2010 Share Posted June 27, 2010 Please put your code in tags You seem to be having anextra pair of () in your foreach // Get Custom Field Template Values function getCustomField($theField) { global $post; $block = get_post_meta($post->ID, $theField); if($block){ foreach($block as $blocks) { echo $blocks; } } } Link to comment https://forums.phpfreaks.com/topic/205990-attached-css-to-a-php-function/#findComment-1077857 Share on other sites More sharing options...
atmmultimedia Posted June 27, 2010 Author Share Posted June 27, 2010 // Get Custom Field Template Values function getCustomField($theField) { global $post; $block = get_post_meta($post->ID, $theField); if($block){ foreach($block as $blocks) { echo $blocks; } } } I am sorry, I don't understand the code, because I was learning from a tutorial. Link to comment https://forums.phpfreaks.com/topic/205990-attached-css-to-a-php-function/#findComment-1077858 Share on other sites More sharing options...
Mchl Posted June 27, 2010 Share Posted June 27, 2010 Your code had this line foreach(($block) as $blocks) { where there are extra pair of parentheses () around $block you should remove it foreach($block as $blocks) { Link to comment https://forums.phpfreaks.com/topic/205990-attached-css-to-a-php-function/#findComment-1077875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.