dqlk31541 2017-03-07 15:57
浏览 112

在WordPress中没有显示分页[关闭]

I have data being displayed from a custom post type and has pagination below it but for some reason the pagination is not getting displayed.

<?php
/**
 * @package Hello_Dolly
 * @version 1.6
 */
/*
Plugin Name: Hello Dolly
Plugin URI: https://wordpress.org/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.6
Author URI: http://ma.tt/
*/
function get_json() {

    $slices = json_decode(file_get_contents('http://pf.tradetracker.net/?aid=1&type=json&encoding=utf8&fid=251713&categoryType=2&additionalType=2&limit=20',true));
    create_posttype();
    if ($slices) { 
        foreach ($slices->products as $slice) {
                $ID = $slice->ID;
                $name = $slice->name;
                $currency = $slice->price->currency;
                $amount = $slice->price->amount;
                $URL = $slice->URL;
                $images = $slice->images;
                $description = $slice->description;
            /*  $categories = $slice->categories; */
            /*  $brand = $slice->properties->brand; */
                $producttype = $slice->properties->producttype;
                $deliveryCosts = $slice->properties->deliveryCosts;
                $SKU = $slice->properties->SKU;
                $brand_and_type = $slice->properties->brand_and_type;
                $thumbnailURL = $slice->properties->thumbnailURL;
                $deliveryTime = $slice->properties->deliveryTime;
                $imageURLlarge = $slice->properties->imageURLlarge;
                $categoryURL = $slice->properties->categoryURL;
                $EAN = $slice->properties->EAN;
                $variations = $slice->variations;
                /* Test to see each of them is correct. 
                if ($brand)
                    echo $brand."<br>";
                else
                    echo "Some error";
                */


                $my_post = array(
                    'post_type' => 'products',
                    'post_title'    =>  $name,
                    'post_content'  => 'This is my content',
                    'post_status'   => 'publish',
                    'post_author'   => 1,
                    /* 'post_category' => array(8,39) */
                );

                // Insert the post into the database and return the new post ID
                $post_id = wp_insert_post( $my_post, $wp_error );



        }

          $temp = $wp_query; 
          $wp_query = null; 
          $wp_query = new WP_Query(); 
          $wp_query->query('showposts=10&post_type=products'.'&paged='.$paged); 

        while ($wp_query->have_posts()) : $wp_query->the_post(); 
        ?>
            <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            <?php the_content(); ?>

        <?php
        endwhile;
        ?>
        <nav>
            <?php previous_posts_link('&laquo; Newer') ?>
            <?php next_posts_link('Older &raquo;') ?>
        </nav>

<?php 
  $wp_query = null; 
  $wp_query = $temp;  // Reset

    } 
}


// Our custom post type function
function create_posttype() {

    register_post_type( 'Products',
    // CPT Options
        array(
            'labels' => array(
                'name' => __( 'Products' ),
                'singular_name' => __( 'Product' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'products'),
        )
    );
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
add_shortcode( 'display_data', 'get_json' );

?>
  • 写回答

1条回答 默认 最新

  • dsomm80482 2017-03-07 17:09
    关注

    use the_posts_pagination which wp provides for pagination. (number of posts to show is defined from the admin panel's given number - posts per page ) example :

    <?php the_posts_pagination( array(
                                                                    'mid_size' => 2,
                                                                    'prev_text' => __( 'Previous page', 'findarch' ),
                                                                    'next_text' => __( 'Next page', 'findarch' ),
                                                                    'screen_reader_text'    => __('navigation','findarch')
                                                                    ) ); ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答