2

例如(在我的情况下)这里有一些代码,

<?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_meta();

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

如果我必须从字面上显示它,代码将是这样的:

<?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();
?>

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

4

4 回答 4

8

只需一组标签:

<?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();
?>
于 2012-04-04T18:13:06.737 回答
2

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

<?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(); ?>
于 2012-04-04T18:14:28.103 回答
1

这将做你想要的(未经测试):

<?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();
?>

http://www.w3schools.com/php/php_if_else.asp?output=print

于 2012-04-04T18:16:57.400 回答
0

你可以做

<?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=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();
?>
于 2012-04-04T18:13:30.863 回答