2011-07-28 120 views
0

我想爲所有帖子做一個自定義的存檔,但我希望它看起來有點不同於類別特定的存檔。通過將下面的代碼放到我的網站上的一個頁面中,我已經達到了這個目標。頁面內的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

我不明白你想要做的正是,請更具體 –

+1

@adam什麼:你爲什麼不使用查詢後 – Gowri

回答

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

的WP抄本頁面上[wp_reset_postdata()](HTTP://抄本.wordpress.org/Function_Reference/wp_reset_postdata)有一個非常明確的例子。 – yitwail