wordpress类别分页不再有效

时间:2016-04-01 17:11:41

标签: php wordpress

我的导航停止工作在我的custompost类别...我有这个:

    投资组合      

<?php $loop = new WP_Query( array( 'post_type' => 'portfolios', 'posts_per_page' => 8, 'offset'=> 0 ,'paged' => $paged,  ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <li class="list_c">  


<a href="<?php the_permalink(); ?>"><div><div id="over2"><p>+info</p></div></div>
<div id="read"> <span>ler mais </span></div>


<div id="ptxL" class="filldiv">

<div id="thumbL" class="grow "><?php the_post_thumbnail('featuredImageCropped3');?></div> 

<div id="infoL">

<div id="titled" class="tt">

<h2><?php the_title();?></h2></div>

<div id="contentL"><h3><?php the_excerpt(); ?> </h3></div></div><div id="color"></div>

<!-- You have not associated any custom fields with this post-type. Be sure to add any desired custom fields to this post-type by clicking on the "Manage Custom Fields" link under the Custom Content Type menu and checking the fields that you want. -->

</div></a></li>




<?php endwhile; wp_reset_query(); ?>



<?php wpbeginner_numeric_posts_nav(); ?>


<?php get_footer(); ?> 

和我的functions.php:

function wpbeginner_numeric_posts_nav() {

    if( is_singular() )
        return;

    global $wp_query;

    /** Stop execution if there's only 1 page */
    if( $wp_query->max_num_pages <= 1 )
        return;

    $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
    $max   = intval( $wp_query->max_num_pages );

    /** Add current page to the array */
    if ( $paged >= 1 )
        $links[] = $paged;

    /** Add the pages around the current page to the array */
    if ( $paged >= 3 ) {
        $links[] = $paged - 1;
        $links[] = $paged - 2;
    }

    if ( ( $paged + 2 ) <= $max ) {
        $links[] = $paged + 2;
        $links[] = $paged + 1;
    }

    echo '<div class="navigation"><ul>' . "\n";

    /** Previous Post Link */
    if ( get_previous_posts_link() )
        printf( '<li class="pre">%s</li>' . "\n", get_previous_posts_link() );

    /** Link to first page, plus ellipses if necessary */
    if ( ! in_array( 1, $links ) ) {
        $class = 1 == $paged ? ' class="active"' : '';

        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );

        if ( ! in_array( 2, $links ) )
            echo '<li>…</li>';
    }

    /** Link to current page, plus 2 pages in either direction if necessary */
    sort( $links );
    foreach ( (array) $links as $link ) {
        $class = $paged == $link ? ' class="active"' : '';
        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
    }

    /** Link to last page, plus ellipses if necessary */
    if ( ! in_array( $max, $links ) ) {
        if ( ! in_array( $max - 1, $links ) )
            echo '<li>…</li>' . "\n";

        $class = $paged == $max ? ' class="active"' : '';
        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
    }

    /** Next Post Link */
    if ( get_next_posts_link() )
        printf( '<li>%s</li>' . "\n", get_next_posts_link() );

    echo '</ul></div>' . "\n";

}

我改变了服务器也许就是这个问题......但是我可以让它工作......我的调试没有发现错误...

1 个答案:

答案 0 :(得分:0)

请尝试此代码。我认为您在分页参数中有错误。

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'portfolios', 'posts_per_page' => 8, 'offset'=> 0 ,'paged'=>$paged  ) ); ?>
query_posts($args);
 if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li class="list_c">  
<a href="<?php the_permalink(); ?>"><div><div id="over2"><p>+info</p></div></div>
<div id="read"> <span>ler mais </span></div>


<div id="ptxL" class="filldiv">

<div id="thumbL" class="grow "><?php the_post_thumbnail('featuredImageCropped3');?></div> 

<div id="infoL">

<div id="titled" class="tt">

<h2><?php the_title();?></h2></div>

<div id="contentL"><h3><?php the_excerpt(); ?> </h3></div></div><div id="color"></div>

<!-- You have not associated any custom fields with this post-type. Be sure to add any desired custom fields to this post-type by clicking on the "Manage Custom Fields" link under the Custom Content Type menu and checking the fields that you want. -->

</div></a></li>
<?php endwhile;endif; ?>
<?php wpbeginner_numeric_posts_nav(); ?>
<?php wp_reset_query(); ?>

我希望这对你有用。 感谢