Jump to content

Attached CSS to a PHP function


atmmultimedia

Recommended Posts

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

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;

      }

   }

}

 

 

// 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.