2017-08-08 84 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

寫這篇文章的上方,而循環

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