I have a problem , my code is make pagination post_meta , its work , but link to paginate still use https://yourweb.com/post-title/2 not use paginate link https://yourweb.com/post-title/page/2 , and if i type this link https://yourweb.com/post-title/page/2 this will return to https://yourweb.com/post-title/ , and nav pagination not show
this my code
$paged = (get_query_var('paged')) ? absint( get_query_var('paged')) : 1 ;
$ids = get_the_ID();
$args = array('paged' => $paged , 'post__in' => array($ids));
$the_query = new WP_Query($args);
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post();
$metas = get_post_meta(get_the_ID(),'value_gallery',false);
foreach ($metas as $meta) {
$key_val = explode(",", $meta);
$image_chunk = array_chunk($key_val, 3);
$page = get_query_var('page');
$page = $page > 1 ? $page - 1 : 0 ;
if (isset($key_val[$page])) {
foreach ($image_chunk[$page] as $image) {
echo "<div class='col-lg-4'>".
wp_get_attachment_image($image,"cherry-thumb-a") ."</div>";
}
}
}
endwhile;
the_posts_pagination( array(
'mid_size' => 2,
'prev_text' => __( '<', 'textdomain' ),
'next_text' => __( '>', 'textdomain' ),
) );
wp_reset_postdata();
endif;
i will happy if anyone can help me :) ,many thanks for attention
Related
Completely confused with this one.
If I add the nonpaging => true to the query, I get all the results. However, I wish to only have 4 displayed in this particular loop. If I use the post_per_page => 4, I only get one.
Worse, if I add in orderby => 'rand' I will get some number between 1-5.
What the hell is going on?!?!?
// WP_Query arguments
$args = array (
'post_type' => array( 'bottin' ),
'posts_per_page' => 4,
);
// The Query
$bottin = new WP_Query( $args );
// The Loop
if ( $bottin->have_posts() ) {
while ( $bottin->have_posts() ) {
$bottin->the_post();
$voir_plus = get_field('voir_plus');
if ( !empty($voir_plus) ) {
// Vars
$link = get_the_permalink();
$image_url = get_the_post_thumbnail_url();
$name = get_the_title();
$posttags = get_the_tags();
echo '<a href="' . $link . '"><div class="elementor-row"><div class="elementor-col-50"><img src="' . $image_url . '" class="img-responsive" width="300"></div><div class="elementor-col-50 intervenant-info"><h6>' . $name . '</h6><p>';
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
echo '</p></div></div></a>';
}
}
} else {
// no posts found
}
I think you need this, "paged" and you might need to check this out https://codex.wordpress.org/Pagination
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'bottin'
'posts_per_page' => 4,
'paged' => $paged
);
$bottin = new WP_Query( $args );
?>
I am trying to make a pagination from meta_post (meta_key,meta_value) ==> (name_student,array(john,mike,natasha,joan,buck)) but i dont know how to make it, from codex just make pagination post , not a meta_post , and my meta_post in 1 array , i was find a similar question 1 , 2 , but I still haven't found the answer for my problem , if anyone can help me to find sollution for my problem I will be greatly helped , thankyou for read my problem , hopefully can help me
this my code :
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$ids = get_the_ID();
$args = array('paged' => $paged , 'post__in' => array($ids));
$the_query = new WP_Query($args);
if (have_posts()) :
while (have_posts()) : the_post();
$metas = get_post_meta(get_the_ID(),'name_student',false);
foreach ($metas as $meta) {
$key_val = explode(",", $meta);
$image_chunk = array_chunk($key_val, 3);
$page = get_query_var('page');
$page = $page > 1 ? $page - 1 : 0 ;
if (isset($key_val[$page])) {
foreach ($image_chunk[$page] as $image) {
echo "<div class='col-lg-4'>".
wp_get_attachment_image($image,"thumbnail") ."</div>";
}
}
}
endwhile;
$big = 9999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
wp_reset_postdata();
endif;
I want to show the category name and category thumbnail, it need to show the 5 category per page and rest of in other respective pages. please any one have solution for this.
here is the code:
<?php
$posts_per_page = 4;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$offset = ( $paged - 1 );
global $paged;
$curpage = $paged ? $paged : 1;
$args = array(
'child_of' => 4,
'order_by' => 'name',
'paged' => $paged
);
$categories = get_categories( $args );
foreach($categories as $category) {
echo '' . $category->name.'';
if(has_category_thumbnail($category->cat_ID)) {
the_category_thumbnail($category->cat_ID);
}
}
echo '
<div id="wp_pagination">
<a class="previous page button" href="'.get_pagenum_link(($curpage-1 > 0 ? $curpage-1 : 1)).'">‹</a>';
for($i=1;$i<=$categories->max_num_pages;$i++)
echo '<a class="'.($i == $curpage ? 'active ' : '').'page button" href="'.get_pagenum_link($i).'">'.$i.'</a>';
echo '<a class="next page button" href="'.get_pagenum_link(($curpage+1 <= $categories->max_num_pages ? $curpage+1 : $categories->max_num_pages)).'">›</a>
</div>
';
Finally I got the solution for the above problem. I hope it helpful for all others having a same problem.
Try this code:
<?php
$args = array(
'child_of' => 4,
'orderby' =>'date',
'order' =>'ASC'
);
$categories = get_categories($args);
$numOfItems = 4;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$to = $page * $numOfItems ;
$current = $to - $numOfItems;
$total = sizeof($categories);
?>
<div id="ns-main">
<?php
for ($i=$current; $i<$to; ++$i) {
$category = $categories[$i];
?>
<div class="ns-wrap">
<?php
if ($category->name) {
if(has_category_thumbnail($category->cat_ID)) {
the_category_thumbnail($category->cat_ID);
}
echo '' . $category->name.'';
}
?>
</div>
<?php
}
?>
</div>
<div id="wp_pagination">
<?php
unset($category);
echo paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => ceil($total / $numOfItems),
'current' => $page
));
?>
</div>
I have the following loop, which is suppose to pull all taxonomy called series and the post under it. It works fine but the problem is it is not not showing Older posts link. I manually go to second page Newer post links shows up. Any idea what am I missing?
<?php
$page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
$per_page = 5;
$offset = ( $page-1 ) * $per_page;
$args = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 0,'paged' => $page);
$terms = get_terms('series',$args);
foreach ($terms as $term) {
$wpq = array ('taxonomy'=>'series','term'=>$term->slug);
$myquery = new WP_Query ($wpq);
$article_count = $myquery->post_count;
echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">";
echo $term->name;
echo "</h3>";
if ($article_count) {
echo "<ul>";
while ($myquery->have_posts()) : $myquery->the_post();
echo "<li>".$post->post_title."</li>";
endwhile;
echo "</ul>";
} } ?>
<div class="clear"></div>
<p class="previous"><?php next_posts_link( __( '← Older posts', 'ari' ) ); ?></p>
<p class="next"><?php previous_posts_link( __( 'Newer posts →', 'ari' ) ); ?></p>
</div>
try this (I've tested), paged is not working good with offset, which is better for get_terms() (but still useful to get_query_var('paged')), also change "category" to your desired term.
<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$per_page = 4;
$offset = ( $page-1 ) * $per_page;
$args = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 0);
$terms = get_terms('category', $args);
foreach ($terms as $term){
$wpq = array ('taxonomy'=>'category','term'=>$term->slug);
$myquery = new WP_Query ($wpq);
$article_count = $myquery->post_count;
echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">";
echo $term->name;
echo "</h3>";
if ($article_count){
echo "<ul>";
while ($myquery->have_posts()) : $myquery->the_post();
echo "<li>".$post->post_title."</li>";
endwhile;
echo "</ul>";
}
} ?>
I need to add pagination to archive page. Show 10 months per page.
wp_get_archives('type=monthly&show_post_count=1');
Try this
<?php
$catnam = '1';
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// the total of registers to show on each page
$showp = 4;
wp_get_archives("type=monthly&showposts=$showp&paged=$paged");
while (have_posts() ) : the_post();?>
<h4><?php the_title();?></h4>
<?php endwhile;?>
<?php
global $wp_rewrite;
$paginate_base = get_pagenum_link(1);
if (strpos($paginate_base, '?') || ! $wp_rewrite->using_permalinks()) {
$paginate_format = '';
$paginate_base = add_query_arg('paged', '%#%');
} else {
$paginate_format = (substr($paginate_base, -1 ,1) == '/' ? '' : '/') .
user_trailingslashit('page/%#%/', 'paged');;
$paginate_base .= '%_%';
}
echo '<div id="pagination">';
echo paginate_links( array(
'base' => $paginate_base,
'format' => $paginate_format,
'total' => $wp_query->max_num_pages,
'mid_size' => 10,
'current' => ($paged ? $paged : 1),
'type' => '',
'prev_text' => __('<p class="readmore">« Previous</p>', 'default'),
'next_text' => __('<p class="readmore">Next »</p>', 'default'),
));
echo "</div>";
?>