在WordPress

时间:2017-03-07 15:57:46

标签: php wordpress pagination

我的数据是从自定义帖子类型显示的,并且在其下面有分页,但由于某种原因,分页没有显示。

<?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 个答案:

答案 0 :(得分:1)

使用wp提供分页的the_posts_pagination。 (要显示的帖子数量是从管理面板的给定数字定义的 - 每页的帖子数) 例如:

picturebox.Image = Image.FromFile(@"C:\...\" + label10.text, true);