我试图根据自定义的post类型输出不同的文本,但我得到了一个语法错误,我认为这是由于多个if语句造成的。问题是我对PHP的了解非常有限。有什么想法吗?
<?php
if ( 'lettering' == get_post_type() ) {
<?php if( function_exists( 'attachments_get_attachments' ) ) {
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) : ?>
<ul id="process"><span>Process:</span>
</ul>
<br>
<?php endif; ?> <?php } ?>
} elseif ( 'type' == get_post_type() ) {
<?php if( function_exists( 'attachments_get_attachments' ) ) {
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) : ?>
<ul id="process"><span>Additional Shots</span>
</ul>
<br>
<?php endif; ?> <?php } ?>
}
?>发布于 2012-10-08 13:12:28
删除php开头的标签,如: change:
<?php if ( 'lettering' == get_post_type() ) {
this one --> <?php if( function_exists( 'attachments_get_attachments' ) ) { 至
<?php if ( 'lettering' == get_post_type() ) {
if( function_exists( 'attachments_get_attachments' ) ) {
.......在elseif中也是类似的
添加:
<?php
if ( 'lettering' == get_post_type() ) {
if( function_exists( 'attachments_get_attachments' ) ) {
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ):
?>
<ul id="process"><span>Process:</span>
</ul>
<br>
<?php
endif;
}
} else if ( 'type' == get_post_type() ) {
if( function_exists( 'attachments_get_attachments' ) ) {
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ):
?>
<ul id="process"><span>Additional Shots</span>
</ul>
<br>
<?php
endif;
}
}
?>发布于 2012-10-08 13:58:27
像这样弹出MarcB注释是不理想的。如果你正在用一些PHP注入编写一个主要基于HTML的文件,那么另一种语法是很棒的,否则我会使用HEREDOC这样的东西来让事情更容易识别:
<?php
if ( 'lettering' == get_post_type() ) {
if( function_exists( 'attachments_get_attachments' ) ) {
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) {
echo <<<EOSTRING
<ul id="process"><span>Process:</span>
</ul>
<br>
EOSTRING
;
}
}
} elseif ( 'type' == get_post_type() ) {
if( function_exists( 'attachments_get_attachments' ) ) {
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) {
echo <<<EOSTRING
<ul id="process"><span>Additional Shots</span>
</ul>
<br>
EOSTRING
;
}
}
}https://stackoverflow.com/questions/12775634
复制相似问题