我真的很感激你能帮我做这个,我已经做了一段时间了,我很快就可以尝到了。
我需要每个帖子格式的摘录都具有与默认摘录相同的摘录代码(不使用帖子格式),默认摘录作为“代码1”提供。其中必须包含extract\\u wrap和experpt\\u以及条件div类。基本上,这段代码中的所有内容。。。只要弄清楚如何将其集成到第二个代码中,只要它说“这里有代码”。。。
代码1:
<!-- Begin excerpt wrap -->
<div class="excerpt_wrap">
<div class="excerpt_inside">
<!-- No post format -->
<?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>
代码2:
<?php get_header(); ?>
<div id="container">
<div id="post_content2">
<div id="main_index">
<div class="main_adjust">
<!-- Grab posts -->
<?php while (have_posts()) : the_post(); ?>
<!-- Post formats -->
<?php
if ( has_post_format( \'aside\' )) {
CODE GOES HERE
}
elseif ( has_post_format( \'chat\' )) {
CODE GOES HERE
}
elseif ( has_post_format( \'gallery\' )) {
CODE GOES HERE
}
elseif ( has_post_format( \'image\' )) {
CODE GOES HERE
}
elseif ( has_post_format( \'link\' )) {
CODE GOES HERE
}
elseif ( has_post_format( \'quote\' )) {
CODE GOES HERE
}
elseif ( has_post_format( \'status\' )) {
CODE GOES HERE
}
elseif ( has_post_format( \'video\' )) {
CODE GOES HERE
}
elseif ( has_post_format( \'audio\' )) {
CODE GOES HERE
}
else {
$format = get_post_format();
if ( false === $format ) {
?>
<!-- Begin excerpt wrap -->
<div class="excerpt_wrap">
<div class="excerpt_inside">
<!-- No post format -->
<?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>
<?php } // ending the if ( false === $format ) ...
} // end else
?>
<?php endwhile; ?>
<!-- Next/Previous entries -->
<div class="mp_archive">
<div id="more_posts">
<div class="oe">
<?php next_posts_link(\'« Older\') ?>
</div>
<div class="re">
<?php previous_posts_link (\'Newer »\') ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>
最合适的回答,由SO网友:Brian Fegter 整理而成
您可以使用Wordpress函数get\\u template\\u part();
在主题目录中创建几个名为content-POST\\u FORMAT\\u TYPE的模板文件。php-示例:内容库。php和内容聊天。php
if(has_post_format(\'gallery\'))
get_template_part(\'content\', \'gallery\');
elseif(has_post_format(\'chat\')
get_template_part(\'content\', \'chat\');
else
the_content();
这种方法使代码块可以在多个模板中重用。希望这对你有所帮助。