Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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
Wordpress分页不适用于wp_pagenavi_Wordpress_Wordpress Theming - Fatal编程技术网

Wordpress分页不适用于wp_pagenavi

Wordpress分页不适用于wp_pagenavi,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我使用短代码显示帖子,它只显示5篇帖子,我使用wp_pagenavi插件进行分页,但分页不显示。下面是我的代码,请帮忙 global $post; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'post', 'cat' => '2', 'paged' => $paged ); $loop = new WP_Query( $args );

我使用短代码显示帖子,它只显示5篇帖子,我使用wp_pagenavi插件进行分页,但分页不显示。下面是我的代码,请帮忙

global $post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'post', 'cat' => '2', 'paged' => $paged );
$loop = new WP_Query( $args );  
if ( $loop->have_posts() ) {
    ob_start();
?>
<div class="clearfix"></div>
<div class="issue-articles-wrap all-articles-wrap">
    <?php
    while ( $loop->have_posts() ) : $loop->the_post();
        $loop->the_post();
        $thumb_url = '';
        $full_width = 'full-width-article';
        if( has_post_thumbnail() ){
            $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
            $thumb_url = $thumb['0'];
            $full_width = '';
        }
        if( $post->ID > 0 ){
        ?>
        <div class="issue-item issue-item-<?php echo $post->ID; ?>">
            <?php if( $thumb_url != '' ){ ?>
            <div class="thumb-article">
                <a href="<?php the_permalink(); ?>"><img src="<?php echo $thumb_url; ?>" alt="<?php the_title(); ?>"></a>
            </div><!--thumb-article-->
            <?php } ?>
            <div class="summary-article <?php echo $full_width; ?>">
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <?php the_excerpt(); ?>
            </div><!--summary-article-->
            <div class="clearfix"></div>
        </div><!--issue-item-->
        <?php
        }   //  end of if( $post->ID > 0 )
    endwhile;
    wp_pagenavi(); 
    wp_reset_query();
    ?>
</div><!--issue-articles-wrap all-articles-wrap-->
<?php   
$rep = ob_get_contents();
ob_end_clean();
}   //  end of if ( $loop->have_posts() )


return $rep;
global$post;
$paged=(获取查询变量('paged'))?获取查询变量('paged'):1;
$args=数组('post_type'=>'post','cat'=>'2','paged'=>$paged);
$loop=新的WP_查询($args);
如果($loop->have_posts()){
ob_start();
?>

我认为您正在使用一个插件来显示分页,最好创建自定义分页。 在function.php中编写以下代码:

if ( ! function_exists( 'your_paging_nav' ) ) :

function your_paging_nav() {
    global $wp_query;

    // Don't print empty markup if there's only one page.
    if ( $wp_query->max_num_pages < 2 )
        return;
    ?>
    <nav>
        <h1><?php _e( 'Posts navigation', 'framwork-translation' ); ?></h1>
        <div>

            <?php if ( get_next_posts_link() ) : ?>
            <div class="nav-previous"><?php next_posts_link( __( 'Older posts', 'framwork-translation' ) ); ?></div>
            <?php endif; ?>

            <?php if ( get_previous_posts_link() ) : ?>
            <div class="nav-next"><?php previous_posts_link( __( 'Newer posts', 'framwork-translation' ) ); ?></div>
            <?php endif; ?>

        </div>
    </nav>
    <?php
}
endif;
如果(!function_存在('your_paging_nav')):
功能您的页面导航(){
全局$wp_查询;
//如果只有一页,请不要打印空标记。
如果($wp\u query->max\u num\u pages<2)
返回;
?>
>

非常感谢您的友好回复,我将WP_Query改为Query_posts,效果很好,我还有另一个分页问题,那就是使用.html扩展名,您能看一下问题吗?
<body <?php body_class(); ?>>
<?php get_header(); ?>

<div class="primary">
  <?php if ( have_posts() ) : ?>

    <!-- The loop -->

    <?php while ( have_posts() ) : the_post(); ?>
      <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; ?>

    <?php your_paging_nav(); ?>

  <?php else : ?>
    <?php get_template_part( 'content', 'none' ); ?>

  <?php endif; ?>
</div>

<?php get_footer(); ?>