2014-03-29 36 views
0

我已經通過wordpress自定義頁面模板創建了一個博客列表,並通過創建博客頁面來分配它。Wordpress循環在博客列表的自定義頁面模板中不起作用

但我想知道循環是正確的,但它沒有顯示任何結果。

http://projects.dev2d.com/msleximus/blog/

怎麼辦。我的代碼....

<?php 
    /* 
    Template Name: Blog 
    */ 

get_header(); ?> 
<!-- #primary --> 
<div role="main" class="main"> 
    <section class="page-top"> 
    <div class="container"> 
     <div class="row"> 
     <div class="span12"> 
      <ul class="breadcrumb"> 
      <li><a href="<?php bloginfo('url'); ?>">Home</a> <span class="divider">/</span></li> 
      <li class="active"> 
       <?php wp_title(); ?> 
      </li> 
      </ul> 
     </div> 
     </div> 
     <div class="row"> 
     <div class="span12"> 
      <h2> Blog </h2> 
     </div> 
     </div> 
    </div> 
    </section> 
    <div class="container"> 
    <div class="row"> 
     <div class="span9"> 
     <?php 
      if (is_page()) { 
      $category = get_post_meta($posts[0]->ID, 'category', true); 
      $cat = get_cat_ID($category); 
      } 
      if ($cat) : 
      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
      $post_per_page = 4; // -1 shows all posts 
      $do_not_show_stickies = 1; // 0 to show stickies 
      $args=array (
       'category__in' => array($cat), 
       'post_type'=> 'post', 
       'orderby' => 'date', 
       'order' => 'DESC', 
       'paged' => $paged, 
       'posts_per_page' => $post_per_page, 
       'ignore_sticky_posts' => $do_not_show_stickies 
      ); 
      $temp = $wp_query; // assign original query to temp variable for later use 
      global $wp_query; 
      $wp_query = null; 
      $wp_query = new WP_Query($args); 

      if ($wp_query->have_posts()) : 
       while ($wp_query->have_posts()) : $wp_query->the_post(); 
      ?> 
     <div class="blog-posts"> 
      <article <?php post_class() ?> id="post-<?php the_ID(); ?>class="post post-medium-image"> 
      <div class="row"> 
       <div class="span4"> 
       <div class="post-image"> 
        <div class="flexslider flexslider-center-mobile flexslider-simple" data-plugin-options='{"controlNav":false, "animation":"slide", "slideshow": false, "maxVisibleItems": 1}'> 
        <ul class="slides"> 
         <li> <img class="img-rounded" src="<?php the_post_thumbnail('medium'); ?>" alt="featured image"></li> 
        </ul> 
        </div> 
       </div> 
       </div> 
       <div class="span5"> 
       <div class="post-content"> 
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> 
        <?php the_title(); ?> 
        </a></h2> 
        <?php the_content('read more »'); ?> 
       </div> 
       </div> 
      </div> 
      <div class="row"> 
       <div class="span9"> 
       <div class="post-meta"> <span><i class="icon-calendar"></i> 
        <?php the_time('F jS, Y') ?> 
        </span> <span><i class="icon-user"></i> By <a href="#"> 
        <?php the_author() ?> 
        </a> </span> <span><i class="icon-tag"></i> 
        <?php the_tags('Tags: ', ', ', '<br />'); ?> 
        ,</span> <span><i class="icon-comments"></i> 
        <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> 
        <a href="<?php the_permalink() ?>" class="btn btn-mini btn-primary pull-right">Read more...</a> </div> 
       </div> 
      </div> 
      </article> 
      <?php endwhile; ?> 
      <div class="pagination pagination-large pull-right"> 
      <div class="alignleft"> 
       <?php next_posts_link('« Older Entries') ?> 
      </div> 
      <div class="alignright"> 
       <?php previous_posts_link('Newer Entries »') ?> 
      </div> 
      </div> 
     </div> 
     </div> 
     <?php endif; // if ($wp_query->have_posts()) ?> 
     <?php $wp_query = $temp; //reset back to original query ?> 
     <div class="span3"> 
     <aside class="sidebar"> 
      <?php get_search_form(); ?> 
      <?php get_sidebar(); ?> 
      <div class="tabs"> 
      <ul class="nav nav-tabs"> 
       <li class="active"><a href="#popularPosts" data-toggle="tab"><i class="icon-star"></i> Popular</a></li> 
       <li><a href="#recentPosts" data-toggle="tab">Recent</a></li> 
      </ul> 
      <div class="tab-content"> 
       <div class="tab-pane active" id="popularPosts"> 
       <?php fanciedmedia_popular_posts(5); ?> 
       </div> 
       <div class="tab-pane" id="recentPosts"> 

       </div> 
      </div> 
      </div> 
      <hr /> 
     </aside> 
     </div> 
     <?php else : ?> 
     <div class="row"> 
     <div class="span12"> 
      <div class="post-content"> 
      <h2 class="center">Not Found</h2> 
      <p class="center">Sorry, but you are looking for something that isn't here.</p> 
      </div> 
     </div> 
     </div> 
     <?php endif; // if ($cat) ?> 
    </div> 
    </div> 
</div> 
<?php get_footer(); ?> 

回答

0

使用該之一,不要讓我知道..

<div class="container"> 
<div class="row"> 
    <div class="span9"> 
    <div class="blog-posts"> 
     <?php query_posts('category_name = Category&showposts=10'); ?> 
     <?php while (have_posts()) : the_post() ?> 
     <article <?php post_class() ?> id="post-<?php the_ID(); ?>class="post post-medium-image"> 
     <div class="row"> 
      <div class="span4"> 
      <div class="post-image"> 
       <div class="flexslider flexslider-center-mobile flexslider-simple" data-plugin-options='{"controlNav":false, "animation":"slide", "slideshow": false, "maxVisibleItems": 1}'> 
       <?php if (has_post_thumbnail()) { 
            the_post_thumbnail('medium');  
       } ?> 
       </div> 
      </div> 
      </div> 
      <div class="span5"> 
      <div class="post-content"> 
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> 
       <?php the_title(); ?> 
       </a></h2> 
       <?php the_excerpt(); ?> 
       <a href="<?php the_permalink() ?>" class="btn btn-mini btn-primary pull-right">Read more...</a> </div> 
      </div> 
     </div> 
     <div class="row"> 
      <div class="span9"> 
      <div class="post-meta"> <span><i class="icon-calendar"></i> 
       <?php the_time('F jS, Y') ?> 
       </span> <span><i class="icon-user"></i> By <a href="#"> 
       <?php the_author() ?> 
       </a> </span> <span><i class="icon-tag"></i> 
       <?php the_tags('Tags: ', ', ', '<br />'); ?> 
       ,</span> <span><i class="icon-comments"></i> 
       <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> 
      </div> 
      </div> 
     </div> 
     </article> 
     <?php endwhile; ?> 
     <?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ($total_pages > 1) { ?> 
     <div class="pagination pagination-large pull-right"> 
     <div class="alignleft"> 
      <div class="nav-next alignright"> 
      <?php previous_posts_link('Newer posts'); ?> 
      </div> 
     </div> 
     <div class="alignright"> 
      <div class="nav-previous alignleft"> 
      <?php next_posts_link('Older posts'); ?> 
      </div> 
     </div> 
     </div> 
     <?php } ?> 
    </div> 
    </div> 
相關問題