WordPress Post Format If语句?

时间:2011-09-14 作者:AndrettiMilas

现在,当我使用post格式时,我的摘录翻了一番。我希望在未选择帖子格式时有一个默认摘录。签出示例:http://themeforward.com/demo2/

对于我的摘录,要调用post格式,我使用以下代码:

<?php
if ( has_post_format( \'aside\' )) {
    ?>
    <span class="icon-aside"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'thmb-index\' ); } ?>
    </a>
    <span class="sub-title">Posted <?php the_time("F j, Y"); ?> by <?php the_author_posts_link(); ?> in <?php the_category(\', \') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_excerpt();
}
if ( has_post_format( \'chat\' )) {
    ?>
    <span class="icon-chat"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'thmb-index\' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(\', \') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_excerpt();
}
if ( has_post_format( \'gallery\' )) {
    ?>
    <span class="icon-gallery"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'thmb-index\' ); } ?>
    </a>
    <span class="sub-title">
    <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(\', \') ?> &nbsp;/&nbsp; <?php the_time("F j, Y"); ?>
    </span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_content(); ?>
    <?php comments_number( \'no responses\', \'one response\', \'% responses\' );
}
if ( has_post_format( \'image\' )) {
    ?>
    <span class="icon-image"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'thmb-index\' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(\', \') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_excerpt();
}
if ( has_post_format( \'link\' )) {
    ?>
    <span class="icon-link"></span>
    <h1><a href="<?php  echo $first_link = catch_that_link(); ?>"><?php the_title(); ?></a></h1>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'thmb-index\' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(\', \') ?></span>
    <?php comments_number( \'no responses\', \'one response\', \'% responses\' );
}
if ( has_post_format( \'quote\' )) {
    ?>
    <span class="icon-quote"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'thmb-index\' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(\', \') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_content();
}
if ( has_post_format( \'status\' )) {
    ?>
    <span class="icon-status"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'thmb-index\' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(\', \') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_excerpt();
}
if ( has_post_format( \'video\' )) {
    ?>
    <span class="icon-video"></span>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(\', \') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_content();
}
if ( has_post_format( \'audio\' )) {
    ?>
    <span class="icon-audio"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( \'thmb-index\' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(\', \') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_content();
}
?>
。。。如果未选择帖子格式,我想获取以下内容:

<!-- Begin excerpt wrap -->
<div class="excerpt_wrap">
<div class="excerpt_inside">

    <?php if ( has_post_thumbnail() ) { ?>   

    <a href="<?php the_permalink() ?>">
    <?php the_post_thumbnail( \'thmb-index\' ); ?>
    </a>

    <?php } ?>
    <div class="excerpt_content<?php if ( has_post_thumbnail() ) echo \' with-thumbnail\'; ?>">
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
<span class="sub-title">By <?php the_author_posts_link( ); ?> <span class="sub-title-divider">|</span> <?php the_time(\'F j, Y\'); ?> <span class="sub-title-divider">|</span> <a href="<?php the_permalink(); ?>/#commentlist"><?php comments_number( \'No comments\', \'One comment\', \'% comments\' ); ?></a></span>

    <?php the_excerpt(); ?>

    </div>

<!-- End excerpt wrap -->
</div>
</div>

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

我认为您只需要在php中添加一些“ELSE”,如下所示:

if ( has_post_format( \'aside\' )) { 
    // do some stuff
} elseif ( has_post_format( \'chat\' )) {
    // do some other stuff
} elseif ( has_post_format( \'gallery\' )) {
    // do some other stuff
} else {
   // this isn\'t a post format, so do your final stuff
}
希望这有帮助-祝你好运!

结束

相关推荐

如何从自定义循环获取对_excerpt()的引用

我存档了一个脚本。php位于循环之外,它调用函数get\\u blog\\u links()列出属于当前类别(我的“博客”类别)的所有帖子。我试图在“get\\u blog\\u extract()函数中进行一些跟踪测试,以便写出每篇文章的内容节选或(如果没有出现节选)前55个单词(节选)。但是,我无法在函数中获取对\\u摘录的引用。非常感谢您的帮助。//Blog Listing function get_blog_links(){ $myposts = get_posts();&