Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP代码中添加PHP代码?_Php_Wordpress - Fatal编程技术网

如何在PHP代码中添加PHP代码?

如何在PHP代码中添加PHP代码?,php,wordpress,Php,Wordpress,例如(在我的例子中)这里有一些代码 <?php woo_post_inside_before(); if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() ) woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thu

例如(在我的例子中)这里有一些代码

<?php
    woo_post_inside_before();   
    if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
        woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
    the_title( $title_before, $title_after );
    woo_post_meta();
?>
如果我必须逐字显示,代码如下:

<?php
    woo_post_inside_before();   
    if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
        woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
    the_title( $title_before, $title_after );

    <?php if (is_single()) : ?>
    <div class="testthisad"><img src="http://whatthenerd.com/what/wp-content/themes/canvas/300.jpg" alt="test Ad" /></div>
    <?php endif; ?>

    woo_post_meta();
?>

woo_post_meta();
?>

显然这不是正确的做法。那么,我该怎么做呢?

只有一组标签:

<?php
    woo_post_inside_before();   
    if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
        woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
    the_title( $title_before, $title_after );

    if (is_single()){
?>
    <div class="testthisad"><img src="http://whatthenerd.com/what/wp-content/themes/canvas/300.jpg" alt="test Ad" /></div>
<?php
    }

    woo_post_meta();
?>

您可以这样做

<?php
// Code...
eval('my code as a string');

有很多方法可以做到这一点。这里有一个

<?php
woo_post_inside_before();   
if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
{
     woo_image(   'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbna il '.$woo_options['woo_thumb_align'] );
}
the_title( $title_before, $title_after );
?>
<?php if (is_single()) : ?>
    <div class="testthisad"><img src="http://whatthenerd.com/what/wp-     content/themes/canvas/300.jpg" alt="test Ad" /></div>
    <?php endif; ?>

<?php  woo_post_meta(); ?>

这将执行您想要的操作(未测试):



哇,这很简单,也很清楚。完美的例子!谢谢。@AahanKrish这是更好的方法。@HansZ谢谢你的提醒。将其标记为答案。:)谢谢你的密码。但是你能不能把它和我问题中的示例代码一起使用?(这里没有。)
^^原来你可以用“[code]”而不是“这就是我的意思,我没有删掉lol。我也为你编辑了你的帖子。干杯。。。。。
<?php
    woo_post_inside_before();   
    if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
        woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
    the_title( $title_before, $title_after );

    if (is_single()) : ?>
    <div class="testthisad"><img src="http://whatthenerd.com/what/wp-content/themes/canvas/300.jpg" alt="test Ad" /></div>
    <?php endif; 
    woo_post_meta();
?>
<?php
woo_post_inside_before();   
if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
{
     woo_image(   'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbna il '.$woo_options['woo_thumb_align'] );
}
the_title( $title_before, $title_after );
?>
<?php if (is_single()) : ?>
    <div class="testthisad"><img src="http://whatthenerd.com/what/wp-     content/themes/canvas/300.jpg" alt="test Ad" /></div>
    <?php endif; ?>

<?php  woo_post_meta(); ?>
<?php
    woo_post_inside_before();   
    if ( $woo_options['woo_post_content'] != 'content' AND !is_singular() )
        woo_image( 'width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align'] );
    the_title( $title_before, $title_after );

    if (is_single()) : ? echo "[HTML code handling slashes]" /></div>;

    woo_post_meta();
?>