如果.。在Meta秀之后...条件标记帮助...?

时间:2011-09-23 作者:Jezthomp

我有下面的条件标签,一个朋友帮我做的。。。

目前正在进行。。

1) 如果有一张特色图片,就显示出来。

2) 如果附加图像显示附加图像链接中的特色图像。。

会有第三个吗?

3) 如果元数据只是一个文本输入字段rw\\u post-vimeo,那么它就是一个vimeo链接。。get\\u post\\u meta($post->ID,\'rw\\u post-vimeo\',true)

我在下面做了一次尝试,但它打破了它,这可能吗?

<ul id="post-list">

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>


<?php
$featured = get_post_meta($post->ID,\'_thumbnail_id\',true);
$attachments = get_children( \'post_type=attachment&orderby=menu_order&exclude=\'.$featured.\'&post_mime_type=image&post_parent=\'.$post->ID );
 ?>
 <li class="post">

 <span class="entry-published">
 <time datetime="<?php the_time(\'Y-m-d\')?>"><?php the_time(\'F jS, Y\') ?></time>
 </span>

 <?php if ( !empty($attachments) ) : ?>
 <div class="entry-specific-content">

<a href="<?php echo get_bloginfo(\'template_directory\').\'/gallery.php?id=\'.$post->ID; ?>">

<?php if (has_post_thumbnail()): the_post_thumbnail();else: $first_img = wp_get_attachment_image_src($attachments[0]->ID, \'thumbnail-size\');  ?>

<img src="<?php echo $first_img[0]; ?>" width="<?php echo $first_img[1]; ?>" height="<?php echo $first_img[2]; ?>" />
<?php endif; ?>
</a>
</div>
<div class="yes-gallery">
<a href="<?php echo get_bloginfo(\'template_directory\').\'/gallery.php?id=\'.$post->ID; ?>">See Rest Of Images</a>
</div>

<?php else: ?>
<div class="entry-specific-content">
<?php the_post_thumbnail(); ?>
</div>
<div class="no-gallery"></div>


<?php else: ?>
<div class="entry-specific-content">
<?php echo do_shortcode(\'[iframe_loader src="http://player.vimeo.com/video/\'. get_post_meta($post->ID, \'rw_post-vimeo\',true) .\'?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff&autoplay=1" width="640" height="360" frameborder="0""]\');?>

</div>
<div class="no-gallery"></div>

<?php endif; ?>


<h2 class="entry-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

<div class="entry-content">
<?php the_content(); ?>
</div>


</li>

<?php endwhile; endif; ?>
</ul>
这是可能的还是不可能的,另一种方法?

感谢您的帮助:)

1 个回复
最合适的回答,由SO网友:Chip Bennett 整理而成

因此,我将对其进行一些重构:

<?php
$featured = ( has_post_thumbnail() ? get_post_thumbnail() : false );
$first_img = false;
$custom = false;

if ( ! $featured ) {
    // No featured image; look for attached images and get the first one
    $attachments = get_children( \'post_type=attachment&orderby=menu_order&post_mime_type=image&post_parent=\'.$post->ID ); 
    $first_img = ( $attachments ? wp_get_attachment_image_src($attachments[0]->ID, \'thumbnail-size\') : false );
    // No attached images; look for custom-field image
    if ( ! $first_img ) {
        $custom_meta = ( get_post_custom($post->ID) ? get_post_custom($post->ID) : false );
        $custom = ( isset( $custom_meta[\'custom_field_name\'][0] ) ? $custom[\'custom_field_name\'][0] : "false" );
    }
}
?>
所以,现在,你可以一步一步地浏览每个来源;e、 g.:

<?php
if ( $featured ) {
    // Post has a featured image; do something with it
} else if ( $first_img ) {
    // Post has attached image; do something with the first one
} else if ( $custom ) {
    // Post has image attached via custom field; do something with it
} else {
    // Otherwise, there\'s no featured image,
    // no attached images, and no image 
    // defined in post custom meta. Do something.
}
?>
您只需要相应地加入标记。

结束

相关推荐