2016-04-04 2 views
0

Я создаю пользовательский шаблон страницы, и я не могу заставить страницы постранично работать. Он продолжает показывать те же сообщения, что и на домашней/первой странице. Я пробовал много разных кодов, но получал одинаковые проблемы с каждым результатом.WordPress статический шаблон страницы не работает

Это текущий запрос я использую:

<?php 
global $paged; 
global $wp_query; 
$temp = $wp_query; 
$wp_query = null; 
$wp_query = new WP_Query(); 
$wp_query->query('posts_per_page=2&post_type=post'.'&paged='.$paged); 
while ($wp_query->have_posts()) : $wp_query->the_post(); 
?> 

<div class="news-item"> 
    <?php 
    $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ''); 
    $url = $thumb['0']; 
    ?> 
    <div class="news-item-bg" style="background-image:url(<?=$url?>);"></div> 

    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> 
    <h2><?php the_title(); ?></h2></a> 
    <div class="entry-meta"> 
     <div class="meta-date"><?php the_time('d.m.Y'); ?> </div><div class="meta-seperator"> | </div><div class="meta-author">Auteur: <?php the_author(); ?></div> 
    </div><!-- .entry-meta --> 
    <div class="excerpt"><?php the_excerpt(); ?></div> 
    </div> 

<?php endwhile; ?> 

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

<?php 
$wp_query = null; 
$wp_query = $temp; 
?> 

Найдено решение, этот код работал:

<?php 
if (get_query_var('paged')) { 
    $paged = get_query_var('paged'); 
} elseif (get_query_var('page')) { // 'page' is used instead of 'paged' on Static Front Page 
$paged = get_query_var('page'); 
} else { 
    $paged = 1; 
} 

$custom_query_args = array(
    'post_type' => 'post', 
    'posts_per_page' => '2', 
    'paged' => $paged, 
    'post_status' => 'publish', 
    'ignore_sticky_posts' => true, 
    //'category_name' => 'custom-cat', 
    'order' => 'DESC', // 'ASC' 
    'orderby' => 'date' // modified | title | name | ID | rand 
    ); 
$custom_query = new WP_Query($custom_query_args); 

if ($custom_query->have_posts()) : 
    while($custom_query->have_posts()) : $custom_query->the_post(); ?> 


<div class="news-item"> 


    <?php 

    if (has_post_thumbnail()) { 
     $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ''); 
     $url = $thumb['0']; 

     echo '<div class="news-item-bg" style="background-image:url(<?=$url?>);"></div>';   
    } 
    else { 

    } 
    ;?> 

    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> 
     <h2><?php the_title(); ?></h2></a> 
     <div class="entry-meta"> 
      <div class="meta-date"><?php the_time('d.m.Y'); ?> </div><div class="meta-seperator"> | </div><div class="meta-author">Auteur: <?php the_author(); ?></div> 
     </div><!-- .entry-meta --> 
     <div class="excerpt"><?php the_excerpt(); ?></div> 
     <div id="single-post-container"></div> 
     <a class="button-1 load-more" href="<?php echo get_permalink(); ?>">Lees meer</a> 
     <a class="ajax-close button-1" href="#">X</a> 
    </div> 

    <?php 
    endwhile; 
    ?> 

    <?php if ($custom_query->max_num_pages > 1) : // custom pagination ?> 
     <?php 
     $orig_query = $wp_query; // fix for pagination to work 
     $wp_query = $custom_query; 
     ?> 
     <nav class="prev-next-posts"> 
      <div class="prev-posts-link"> 
       <?php echo get_next_posts_link('Older Entries', $custom_query->max_num_pages); ?> 
      </div> 
      <div class="next-posts-link"> 
       <?php echo get_previous_posts_link('Newer Entries'); ?> 
      </div> 
     </nav> 
     <?php 
     $wp_query = $orig_query; // fix for pagination to work 
     ?> 
    <?php endif; ?> 

    <?php 
    wp_reset_postdata(); // reset the query 
    else: 
     echo '<p>'.__('Sorry, no posts matched your criteria.').'</p>'; 
    endif; 
    ?> 

ответ

0

Попробуйте этот код просто скопировать Pase

 <?php 
     $args = array(
     'post_type'=> 'post', 
     //'category_name' => 'blog', 
      'orderby' => 'post_date', 
      //'posts_per_page'=>'1' 
     'paged' => get_query_var('paged') 
     ); 
     query_posts($args); 
     while (have_posts()) : the_post(); ?> 

     <?php the_title(); ?> 

     <?php endwhile; ?> 

<?php // Wordpress Pagination 
       $big = 999999999; // need an unlikely integer 
       $links = 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, 
        'prev_text' => '<', 
        'next_text' => '>', 
        'type' => 'array' 
       )); 
       if(!empty($links)){ ?> 
       <ul class="pagination"> 
         <?php 

         foreach($links as $link){ 
          ?> 
          <li><?php echo $link; ?></li> 
          <?php 
         } 
         wp_reset_query(); ?> 
        </ul> 
        <?php } ?> 
+0

Спасибо , Я пробовал ваш код и все еще получаю те же 2 результата, которые я получаю на первой/домашней странице. – elw

+0

Убедитесь, что вы установили 2 сообщения в настройках wp-admin>> Чтение> Страницы блога не более –

+0

Я пробовал, но это либо показывает все сообщения, либо когда я использую «post_per_page», разбиение на страницы ничего не делает. – elw