2017-03-07 40 views
-1

我的數據是從自定義文章類型顯示的,並且在其下面有分頁,但由於某種原因,分頁沒有顯示。在WordPress中未顯示分頁

<?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

使用wp提供分頁的the_posts_pagination。 (要顯示的帖子數量是從管理面板的給定數量定義的 - 每頁帖子數) 示例:

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