0
Özel bir sayfa şablonu yapıyorum ve çalışmanın sayfalandırılmasını göremiyorum. Ev/ilk sayfada olduğu gibi aynı mesajları göstermeye devam eder. Çok fazla farklı kod denedim, ancak her bir sonuçta aynı problemi çözdüm.Wordpress statik sayfa şablonu sayfalandırma çalışmıyor
Bu kullanıyorum geçerli sorgu geçerli:
<?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('« Newer') ?>
<?php next_posts_link('Older »') ?>
<?php
$wp_query = null;
$wp_query = $temp;
?>
çözüm bulundu, bu kod çalıştı:
<?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;
?>
Teşekkür Pase kopya bu kodu deneyin , Kodunuzu denedim ve hala ilk/ana sayfada aldığım aynı 2 sonucu aldım. – elw
Wp-admin'de 2 gönderi ayarladığınızdan emin olun> ayar -> Okuma> Blog sayfaları en fazla –
denemeyi denedim, ancak bu ya tüm mesajları gösterir, ya da "post_per_page" kullandığımda, sayfalandırma hiçbir şey yapmaz. – elw