0

我正在尝试在此页面上显示前 5 个带有自定义缩略图和标题的帖子 ,我只需要显示接下来 5 个帖子的标题,然后是分页。您可以单击此处查看我需要的示例。(见左边的帖子)

下面是我在页面上使用的自定义模板。

<?php
get_header(); ?>
<div id="primary">
<div id="content" role="main">

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($args);
if( have_posts() ) :?>

<?php twentyeleven_content_nav( 'nav-above' );?>
<?php while ( have_posts() ) : the_post(); ?>
            <div class="post-thumb-title">
            <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(632,305));?></a>
            <p class="thumb-title2"><?php the_title(); ?></p>
            <p class="news-date"><?php the_time('F jS, Y') ?></p>
            <div id="post-excerpt">
            <?php the_excerpt(); ?>
            </div>
            </div>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>

<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->

<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

谢谢

4

1 回答 1

0

你可以试试这样的

<?php
// amount of posts shown with thumbnail
// post 6 .. pagesize (wp-admin > settings > reading) will be displayed as link only
$withThumb = 5; 
while ( have_posts() ) : the_post();
    if ($withThumb-- > 0) { ?>
        <div class="post-thumb-title">
            <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(632,305));?></a>
            <p class="thumb-title2"><?php the_title(); ?></p>
            <p class="news-date"><?php the_time('F jS, Y') ?></p>
            <div id="post-excerpt">
                <?php the_excerpt(); ?>
            </div>
        </div>
    <?php } else { ?>
        <div class="post-title">
            <p class="thumb-title2">
                <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
            </p>
        </div>
    <?php } ?>
<?php endwhile; ?>
于 2012-09-26T14:25:44.097 回答