嘿,在索引中添加以下代码。php文件显示最近的三篇博客文章,如下所示
<?php
query_posts(array(
\'post_type\' => \'post\',
\'posts_per_page\' => 3,
\'order\' => \'ASC\',
));
?>
<?php if ( have_posts() ) :?>
<?php while ( have_posts() ) :the_post(); ?>
<!-- Start BlogItem -->
<article id="post-<?php the_ID();?>" <?php post_class();?>>
<?php the_post_thumbnail( \'large\' );?>
<header class="entry-header">
<h1><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'blog\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<p class="post_date"><?php blog_posted_on(); ?></p>
</header><!-- .entry-header -->
<!-- Start content -->
<div class="content"><?php wp_excerpt(\'post_len\',\'post_readmore\'); ?></div>
<!-- This is used to provide More Links-->
<!-- End content -->
</article>
<!-- End BlogItem -->
<?php endwhile; ?>
<?php endif;?>
并在函数中添加这两个函数。php文件
if ( ! function_exists( \'blog_posted_on\') ):
function blog_posted_on(){
if ( count( get_the_category() ) ) :
printf( __( \'On %2$s \', \'blog\' ), \'entry-utility-prep entry-utility-prep-cat-links\', get_the_category_list( \', \' ) );
printf( __( \'%2$s <span class="%1$s"></span> <span>writing by</span> %3$s\', \'blog\'),
\'meta-prep meta-prep-author\',
sprintf( \'<a href="%1$s" title="%2$s" rel="bookmark"><span>%3$s</span></a>\',
get_permalink(),
esc_attr(get_the_time() ),
get_the_date()
),
sprintf( \'<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>\',
get_author_posts_url( get_the_author_meta( \'ID\' ) ),
sprintf( esc_attr__( \'View all posts by %s\', \'blog\' ), get_the_author() ),
get_the_author()
)
);
endif;
}
endif;
function wp_excerpt($length_callback = \'\', $more_callback = \'\')
{
global $post;
if (function_exists($length_callback)) {
add_filter(\'excerpt_length\', $length_callback);
}
if (function_exists($more_callback)) {
add_filter(\'excerpt_more\', $more_callback);
}
$output = get_the_excerpt();
$output = apply_filters(\'wptexturize\', $output);
$output = apply_filters(\'convert_chars\', $output);
$output = \'<p>\' . $output . \'</p>\';
echo $output;
}
function post_len($length) {
return 41;
}
function post_readmore($more){
global $post;
return \'<span class="post-read-more-color"><a href="\'. get_permalink() . \'">\' . __( \' Read more...\') . \'</a></span>\';
}
它工作得很好。