2017-08-08 16 views
1

thisページで、ページ番号をクリックすると404が見つかりません。ここで改ページコードがループの後、私がやっていることであるのfunctions.phpから 、WordPressページングにページが見つかりません

<?php 

/*------------------------------------*\ 

    Custom Post Types 

\*------------------------------------*/ 



// Create 1 Custom Post type for a Demo, called HTML5-Blank 

function create_post_type_html5() 

{ 

    register_taxonomy_for_object_type('category', 'html5-blank'); // Register Taxonomies for Category 

    register_taxonomy_for_object_type('post_tag', 'html5-blank'); 

    register_post_type('html5-blank', // Register Custom Post Type 

     array(

     'labels' => array(

      'name' => __('News', 'html5blank'), // Rename these to suit 

      'singular_name' => __('News', 'html5blank'), 

      'add_new' => __('Add New', 'html5blank'), 

      'add_new_item' => __('News', 'html5blank'), 

      'edit' => __('Edit', 'html5blank'), 

      'edit_item' => __('Edit HTML5 Blank Custom Post', 'html5blank'), 

      'new_item' => __('New News', 'html5blank'), 

      'view' => __('View News', 'html5blank'), 

      'view_item' => __('View News', 'html5blank'), 

      'search_items' => __('Search News', 'html5blank'), 

      'not_found' => __('No News found', 'html5blank'), 

      'not_found_in_trash' => __('No News found in Trash', 'html5blank') 

     ), 

     'public' => true, 

     'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages 

     'has_archive' => true, 

     'supports' => array(

      'title', 

      'editor', 

      'excerpt', 

      'thumbnail' 

     ), // Go to Dashboard Custom HTML5 Blank post for supports 

     'can_export' => true, // Allows export in Tools > Export 

     'taxonomies' => array(

      'post_tag', 

      'category' 

     ) // Add Category and Post Tags support 

    )); 

} 



/*------------------------------------*\ 

    ShortCode Functions 

\*------------------------------------*/ 



// Shortcode Demo with Nested Capability 

function html5_shortcode_demo($atts, $content = null) 

{ 

    return '<div class="shortcode-demo">' . do_shortcode($content) . '</div>'; // do_shortcode allows for nested Shortcodes 

} 



// Shortcode Demo with simple <h2> tag 

function html5_shortcode_demo_2($atts, $content = null) // Demo Heading H2 shortcode, allows for nesting within above element. Fully expandable. 

{ 

    return '<h2>' . $content . '</h2>'; 

} 

function wpse120407_pre_get_posts($query) { 

    // Test for category archive index 

    // and ensure that the query is the main query 

    // and not a secondary query (such as a nav menu 

    // or recent posts widget output, etc. 

    if (is_category() && $query->is_main_query()) { 

     // Modify posts per page 

     $query->set('posts_per_page', 10); 

    } 

} 

add_action('pre_get_posts', 'wpse120407_pre_get_posts'); 

function my_post_count_queries($query) { 

    if (!is_admin() && $query->is_main_query()){ 

     $query->set('posts_per_page', 10); 

    } 

} 

add_action('pre_get_posts', 'my_post_count_queries'); 

?> 

<ul class="pager"> 

    <?php 

    global $wp_query; 



    $big = 999999999; // need an unlikely integer 

    $translated = __('', 'mytextdomain'); // Supply translatable string 



    echo paginate_links(array(

     'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 

     'format' => '?paged=%#%', 

     'current' => max(1, get_query_var('paged')), 

     'total' => $wp_query->max_num_pages, 

     'before_page_number' => '<li class=""><span>', 

     'after_page_number' => '</span> </li>' 

    )); 

    ?> 

    </ul> 

答えて

1

は、一番下にあるwhileループ

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

$post_query = query_posts(array(
    'post_type'  => 'cover', // You can add a custom post type if you like 
    'paged'   => $paged, 
    'posts_per_page' => 1 
)); 



?> 

の上にこれを書きます

global $wp_query; 



$big = 999999999; // need an unlikely integer 

    echo paginate_links(array(
     'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 
     'format' => '?paged=%#%', 
     'current' => max(1, get_query_var('paged')), 
     'total' => $wp_query->max_num_pages 
    )); 

    ?> 
+0

コード内にカスタムポストタイプの領域はありますか? –

+1

'post_type' => 'cover'、//あなたが好きな場合はカスタム投稿タイプを追加できます –

+0

このコードを追加しました。それは私のコードと違っているようです。 –

0
global $paged; 

if(empty($paged)) $paged = 1; 

$args = array (
'paged' => $paged, 
'posts_per_page' => '3', 
'post_type' => 'post', 
'post_status' => 'publish', 
); 

$Qvar = new WP_Query($args); 
.................. 
....... 

<?php if ($Qvar->max_num_pages > 1) { ?> 
     <div class="pager-prev"> 
      <?php 
       if (!empty(get_previous_posts_link(' Previous'))) { 
        echo '<span></span>'.get_previous_posts_link(' Previous'); 
       } 
      ?> 
     </div> 
     <div class="pager-next"> 
      <?php 
       if (!empty(get_next_posts_link('Next', $Qvar->max_num_pages))) { 
        echo get_next_posts_link('Next', $Qvar->max_num_pages).'<span></span>'; 
       } 
      ?> 
     </div> 
    <?php } ?> 
関連する問題