Wordpress(PHP)上的自定义博客页面 - 分页

时间:2012-09-26 14:16:03

标签: php html wordpress loops pagination

我正在尝试在this page上显示自定义缩略图和标题的前5个帖子,我只需要显示下5个帖子的标题,然后再显示分页。您可以看到我需要的示例by clicking here。 (见左侧的帖子)

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

<?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(); ?>

由于

1 个答案:

答案 0 :(得分: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; ?>