Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 博客列表的自定义页面模板中的Wordpress循环无效_Php_Wordpress - Fatal编程技术网

Php 博客列表的自定义页面模板中的Wordpress循环无效

Php 博客列表的自定义页面模板中的Wordpress循环无效,php,wordpress,Php,Wordpress,我已经通过wordpress自定义页面模板创建了一个博客列表,并通过创建博客页面分配了相同的列表 但我想知道循环是否正确,但它没有显示任何结果 怎么办。我的代码 <?php /* Template Name: Blog */ get_header(); ?> <!-- #primary --> <div role="main" class="main"> <section class="page-top">

我已经通过wordpress自定义页面模板创建了一个博客列表,并通过创建博客页面分配了相同的列表

但我想知道循环是否正确,但它没有显示任何结果

怎么办。我的代码

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

  • /
博客 通过 ,

  • 找不到

    抱歉,您正在寻找不在这里的东西


    使用这个,一定要让我知道

    <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>
    
    
    通过
    ,