我怎么能把这个PHP放入这个HTML?

时间:2015-05-11 18:33:33

标签: php html wordpress-plugin

所以我有以下php:

    $latest_cpt = get_posts("post_type=event&numberposts=1"); 
$theidone =$latest_cpt[0]->ID;
$this_post_id =  $theidone; //get_the_ID();
$key_2_value =  get_post_meta( $this_post_id, 'custom_select', true );
if( ! empty( $key_2_value )) {
$thisisworking =   $key_2_value ;
 ;}

我需要将所有的PHP代码放在'.$thisisworking.'下面的地方。当我尝试时,我不断得到半冒号意外的php错误。

div id="indent">
 <span style="font-size:0.2em">
    <h2><?php echo $EM_Category->output('#_CATEGORYNAME'); ?></h2>
    </span>
    <?php echo $EM_Category->output('#_CATEGORYNOTES'); ?></p>
    <p> <?php //echo $EM_Category->output('#_CATEGORYALLEVENTS'); ?>  </p>


    <?php echo EM_Events::Output( array('format'=>
'
<li>
<br />
<span style="color: #ed834e; clear:both;  display:block"> '.$thisisworking.'#_EVENTNAME </span> 
 </li>
<br />
<b> 
<li>

有人可以告诉我这是如何实现的吗?

echo EM_Events::Output( array('format'=>是wordpress插件的作者,他说修改wordpress插件的模板应该被编码。有人可以帮忙吗?

更新:我尝试了这一点,但似乎没有任何区别:

function letsmakethiswork()  { 
    $latest_cpt = get_posts("post_type=event"); 
    foreach ( $latest_cpt as $cpt_post ) {
        $theidone =$cpt_post->ID;
        $this_post_id =  $theidone; //get_the_ID();
        $key_2_value =  get_post_meta( $this_post_id, 'custom_select', true );
        if( ! empty( $key_2_value )) {
            $thisisworking =   $key_2_value ;
        }
        return $key_2_value;
    }
}
    // END OF NEW CATEGORY SYSTEM 
?>

<div id="indent">
 <span style="font-size:0.2em">
    <h2><?php echo $EM_Category->output('#_CATEGORYNAME'); ?></h2>
    </span>
    <?php echo $EM_Category->output('#_CATEGORYNOTES'); ?></p>
    <p> <?php //echo $EM_Category->output('#_CATEGORYALLEVENTS'); ?>  </p>


    <?php echo EM_Events::Output( array('format'=>
'
<li>
<br />
<span style="color: #ed834e; clear:both;  display:block"> '.letsmakethiswork().'#_EVENTNAME </span> 
 </li>
<br />
<b> 
<li>

1 个答案:

答案 0 :(得分:1)

把它变成一个功能?

function foo() { 
   ... your mangled code ...
   return $whatever_you_built;
}

$string = "foo bar " . foo() . " baz qux";