页面内的WordPress帖子分页

时间:2011-07-28 04:37:15

标签: wordpress

我正在尝试为所有帖子执行自定义存档,但我希望它看起来与特定于类别的存档略有不同。到目前为止,我通过将下面的代码放入我网站上的页面来实现这一目标。

是否有可能为这样的事情添加分页?我以为'paged'=> $ paged行可能会这样做,但没有这样的运气。

这是我的代码:(如果您想知道它的含义,我会使用自定义缩略图大小。)

<?php
global $post;
$args = array(
    'posts_per_page' => 3,
    'offset' => 0,
    'paged' => $paged
    ); 
$thumbnails = get_posts($args);
foreach ($thumbnails as $post)
{
    setup_postdata($post);
        ?>
    <div class="featuredarticle">
    <h4 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
        <div class="featuredimage">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('featured'); ?></a><br />
            </div>
    </div>
<p><?php the_excerpt(); ?></p>
<div class="entry-utility">
<span class="read-more"><a href="<?php the_permalink(); ?>">Read More</a></span>
    </div>

    <?php 
    }
?>

1 个答案:

答案 0 :(得分:0)

此代码在查询帖子和使用分页的页面中非常有用。

<?php
/**
 * Template Name: Page of Books
 *
 * Selectable from a dropdown menu on the edit page screen.
 */
?>

<?php get_header();
    if ( have_posts() ) while ( have_posts() ) : the_post();
the_content(); 
endwhile; wp_reset_query(); 
?>
        <div id="container">
            <div id="content">
<?php 
$type = 'book';
$args=array(
  'post_type' => $type,
  'post_status' => 'publish',
  'paged' => $paged,
  'posts_per_page' => 2,
  'caller_get_posts'=> 1
);
$temp = $wp_query;  // assign orginal query to temp variable for later use   
$wp_query = null;
$wp_query = new WP_Query($args); 
?>

<?php

 get_template_part( 'loop', 'index' );?>
            </div><!-- #content -->
        </div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>