在自定义帖子类型单一模板中使用短代码的WordPress分页

时间:2014-10-13 21:39:44

标签: wordpress pagination

我有自定义的帖子类型设置,可以像页面一样运行。我使用短代码功能在其中一个页面中列出自定义帖子类型。

短代码工作并使用WPNavi插件显示帖子下面的分页。指向下一页的链接显示:" / blog / page / 2 /"但是当点击链接时,它会将您带到同一页面,而不是下一页的帖子。是否可以在自定义帖子类型子页面中使用分页?

function rmcc_post_listing_shortcode1( $atts ) {
    ob_start();
    global $post,
           $paged;
    $authorID = $post->post_author;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query = new WP_Query( array(
        'posts_per_page'        =>  '3',
        'post_type'             =>  'custom_type',
        'author'                =>  $authorID,
        'paged'                 => $paged
    ) );

    $thumb = '';    
    $width = (int) apply_filters( 'et_pb_index_blog_image_width', 200 );
    $height = (int) apply_filters( 'et_pb_index_blog_image_height', 130 );
    $titletext = get_the_title();
    $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, true, 'Blogimage' );
    $thumb = $thumbnail["thumb"];
    ?>
        <div class="et_pb_posts portal-posts et_pb_bg_layout_light">

            <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post clearfix' ); ?>>
                <?php if(has_post_thumbnail()) { ?>
                    <a href="<?php the_permalink(); ?>" class="post-thumbnail">
                        <?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
                    </a>
                <?php } ?>
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <?php
                    et_divi_post_meta();

                    if ( 'on' !== et_get_option( 'divi_blog_style', 'false' ) || ( is_search() && ( 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true ) ) ) )
                        truncate_post( 270 );
                    else
                        the_content();
                ?>
            </article>
            <?php endwhile;
            wp_pagenavi( array( 'query' => $query ) );
            endif;
            wp_reset_query();
            ?>
        </div>
    <?php $myvariable = ob_get_clean();
    return $myvariable;
}
add_shortcode( 'list-posts', 'rmcc_post_listing_shortcode1' );

0 个答案:

没有答案