Pagination buttons are not showing for some reason - any help would be greatly appreciated. Also, there is 8 posts showing unlike 10 as stated in the code.
<?php get_header(); ?>
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<div class="container-fluid p-0 pagewrap pagehead position-relative d-table" id="recent-projects">
<div class="container pageintro">
<div class="row">
<div class="col-12">
<h1>Recent Projects</h1>
<p>View our recent project case studies below</p>
</div>
</div>
</div>
</div>
<div class="container-fluid pt-5 pb-2">
<div class="container">
<div class="row">
<?php $catquery = new WP_Query( 'post_type=>projects&posts_per_page=10'.'&paged='.$paged );?>
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<div class="col-md-6">
<div class="grid">
<figure class="effect-oscar">
<?php the_post_thumbnail('large', array('style' => 'width: 100%; height: 200px; margin: 0px auto 15px auto;')) ?>
<figcaption>
<div class="m-auto">
<h2><span class="post-date"><?php echo get_the_date(); ?></span><?php the_title(); ?></h2>
<p><span><?php the_excerpt(); ?></span></p>
Read Post
</figcaption>
</figure>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<div class="pagination-nav text-center m-auto d-block p-4 mx-auto my-4">
<?php echo paginate_links( array(
'prev_text' => '<span>Previous Page</span>',
'next_text' => '<span>Next Page</span>'
)); ?>
</div>
</div>
<?php get_footer(); ?>
It is a custom post type page also
First of all your WP_Query args are incorrectly set. It should be:
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = [
'post_type' => 'projects',
'posts_per_page' => 10,
'paged' => $paged
];
$catquery = new WP_Query( $args );
?>
This is the preferred way to do it by most developers. However if you wonder what is your mistake... You set the post type with arrow notation but you must use the equal sign only.: post_type=projects
Next your pagination doesn't know about your custom post type. You must explicitly set it:
<?php
// Need a big base number:
$big = 999999999;
// Pagination
paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $catquery->max_num_pages,
'prev_text' => '<span>Previous Page</span>',
'next_text' => '<span>Next Page</span>'
) );
Related
I am using pagination_bar from function.php. I implemented that in custom page called page-blog.php. I restriced pages to only 2 per page and i have 3 blog posts. After I put pagination_bar() function it shows me fatal error.
I saw some soluton already here but none of them helps. I have tried doing some offset.
function.php
function pagination_bar() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => '<i class="fa fa-angle-left"></i>',
'next_text' => '<i class="fa fa-angle-right"></i>'
));
}
}
page-blog.php
<div class="col-xl-8 col-md-12 col-lg-8 col-sm-12 col-xs-12 md-blog-posts">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$homePagePosts = new WP_Query(array(
'posts_per_page' => '2',
'post_type' => 'post',
'has_archive' => true,
'post_status' => 'publish',
'order' => 'DESC',
'paged' => $paged,
));
if($homePagePosts->have_posts()) :
while($homePagePosts->have_posts()) :
$homePagePosts->the_post(); ?>
<div class="col-xs-12 col-md-12 col-lg-12 md-blog-blog">
<div class="md-blog-img">
<div class="img-container">
<div class="positioning">
<span class="md-blogdate-number"><?php the_time('F d, Y.'); ?></span>
<h4 class="md-blog-title"><?php echo get_the_title() ?></h4>
Read More
</div>
<div class="md-blog-img"><?php the_post_thumbnail() ?></div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h1>There is no posts at this moment</h1>
<?php endif; ?>
<div class="md-pagination-holder" style="background: #333; width:50px; height: 50px; color: #fff;">
<?php paginate_bar(); ?>
</div>
</div>
Also you can see the website here - > http://prodenvermovers.wpupkeep.org/blog/
I get fatal error.
EDIT : http://prntscr.com/oij1dr
I chaned paginate_bar to pagination_bar as function is actually called but i get error above when i refresh the page.
Try this to see if you can get the page to work. In this example it just uses the built in WP hooks to generate pagination links. Also, by "still not working" do you mean you are still getting the error, or just not seeing the pagination?
<div class="col-xl-8 col-md-12 col-lg-8 col-sm-12 col-xs-12 md-blog-posts">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$homePagePosts = new WP_Query(array(
'posts_per_page' => '2',
'post_type' => 'post',
'has_archive' => true,
'post_status' => 'publish',
'order' => 'DESC',
'paged' => $paged,
));
if($homePagePosts->have_posts()) :
while($homePagePosts->have_posts()) :
$homePagePosts->the_post(); ?>
<div class="col-xs-12 col-md-12 col-lg-12 md-blog-blog">
<div class="md-blog-img">
<div class="img-container">
<div class="positioning">
<span class="md-blogdate-number"><?php the_time('F d, Y.'); ?></span>
<h4 class="md-blog-title"><?php echo get_the_title() ?></h4>
Read More
</div>
<div class="md-blog-img"><?php the_post_thumbnail() ?></div>
</div>
</div>
</div>
<?php endwhile; ?>
<div class="nav-previous alignleft"><?php previous_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php next_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<h1>There is no posts at this moment</h1>
<?php endif; ?>
</div>
My pagination function shows in my index page , but when call function in a custom Template page (page-news.php) it don't show !!
functions.php
function numbering_pagination() {
global $wp_query;
$all_pages = $wp_query->max_num_pages;
$current_page = max(1,get_query_var('paged'));
if ($all_pages >1) {
return paginate_links(array(
'base' => get_pagenum_link() . '%_%',
'format' => 'page/%#%',
'current' => $current_page,
'mid_size' => 3,
'end_size' => 3,
'prev_text' => 'السابق',
'next_text' =>'التالي'
));
}
}
page-news.php
<?php /* Template Name: news */
get_header(); ?>
<div id="fh5co-blog-section" class="fh5co-section-gray">
<div class="container">
<div>
<div class="text-center heading-section animate-box">
<h3>news</h3>
</div>
</div>
</div>
<div class="container">
<div class="row row-bottom-padded-md">
<?php
$args = array(
'post_type' => 'post',
'category_name'=> 'news'
);
$posts = new WP_Query( $args );
while( $posts->have_posts() ):
$posts->the_post();
?>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="fh5co-blog animate-box">
<img src="<?php the_post_thumbnail_url('full')?>" alt="" />
<div class="blog-text">
<div class="prod-title">
<h3><?php the_title()?></h3>
<span class="posted_by"><?php the_time('F jS, Y'); ?></span>
<p><?php the_content('<span class="read-more"> ... more</span>'); ?></p>
</div>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_query();
?>
</div>
</div>
<!-- ------ pagination ------ -->
<div class="pagination-numbers text-center">
<?php echo numbering_pagination() ?>
</div>
<!-- ------ END News ------ -->
How can I solve this?
From the WordPress codex:
<?php
//Protect against arbitrary paged values
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'posts_per_page' => 5,
'category_name' => 'gallery',
'paged' => $paged,
);
$the_query = new WP_Query( $args );
?>
<!-- the loop etc.. -->
AND:
<?php
$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' => $the_query->max_num_pages
) );
?>
Mind the:
'total' => $the_query->max_num_pages
Also see: https://codex.wordpress.org/Function_Reference/paginate_links
I want to list posts of current logged in author on a custom template page with pagination at the downside which has numbers with link of respective pages and at the upper side a drop down from which we will select how many posts will show on that page(this is working fine) but when i try to go to second page link at down side pagination it is going to page 2 but always shows same posts.
Image view of template page
I have done some searching and implemented below code
form to show dropdown
<form name="frm" class="db_posts_per_page_form" method="post" action="">
<label for="db_posts_per_page">Posts per page</label>
<select onchange="document.frm.submit()" name="db_posts_per_page" id="db_posts_per_page">
<option value="2" <?php selected(2,$_REQUEST['db_posts_per_page']);?>>2</option>
<option value="4" <?php selected(4,$_REQUEST['db_posts_per_page']);?>>4</option>
<option value="6" <?php selected(6,$_REQUEST['db_posts_per_page']);?>>6</option>
<option value="8" <?php selected(8,$_REQUEST['db_posts_per_page']);?>>8</option>
<option value="10" <?php selected(10,$_REQUEST['db_posts_per_page']);?>>10</option>
</select>
</form>
and php for pagination
global $current_user;
if( isset($_POST['db_posts_per_page'] )):
$posts_per_page = $_POST['db_posts_per_page'];
else:
$posts_per_page = 2;
endif;
$author_query = array('posts_per_page' => $posts_per_page,'author' => $current_user->ID, 'post_status' => array('publish', 'pending', 'draft'));
$author_posts = new WP_Query($author_query);
while($author_posts->have_posts()) : $author_posts->the_post();
get_template_part( 'parts/post/content', 'blog-list' );
endwhile;
//global $author_posts;
$big = 999999999;
$paginate_links = paginate_links ( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $author_posts->max_num_pages,
'mid_size' => 5,
'prev_next' => true,
) );
if (!empty($paginate_links)) : ?>
<div class="pagignation"><?php echo $paginate_links;?></div>
<?php endif;
I have changed $author_query to $author_query = new WP_Query( array('posts_per_page'=>$posts_per_page, 'post_type'=>'post', 'author' => $current_user->ID, 'post_status' => array('publish', 'pending', 'draft'), 'paged' => get_query_var('paged') ? get_query_var('paged') : 1)); and by adding wp_reset_postdata(); before echo the $paginate_links
So my whole code for that custom template page is now like below.
<div id="primary" class="content-area">
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-12">
<h1 class="page-title"><?php the_title();?></h1>
</div>
</div>
</div>
<div class="container">
<div class="row add-new">
<div class="col-xs-12 col-md-6">
<form name="frm" class="db_posts_per_page_form" method="get" action="">
<label for="db_posts_per_page">Posts per page</label>
<select onchange="document.frm.submit()" name="db_posts_per_page" id="db_posts_per_page">
<option value="2" <?php selected(2,$_REQUEST['db_posts_per_page']);?>>2</option>
<option value="4" <?php selected(4,$_REQUEST['db_posts_per_page']);?>>4</option>
<option value="6" <?php selected(6,$_REQUEST['db_posts_per_page']);?>>6</option>
<option value="8" <?php selected(8,$_REQUEST['db_posts_per_page']);?>>8</option>
<option value="10" <?php selected(10,$_REQUEST['db_posts_per_page']);?>>10</option>
</select>
</form>
</div>
<div class="col-xs-12 col-md-6">
<div class="pull-right col-xs-12 col-md-3"><a class="btn btn-primary" href="<?php echo esc_url( get_permalink(80) ); ?>">Add New Posts</a></div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-4">
<h5><u>Title</u></h5>
</div>
<div class="col-xs-12 col-md-2">
<h5><u>Author</u></h5>
</div>
<div class="col-xs-12 col-md-2">
<h5><u>Status</u></h5>
</div>
<div class="col-xs-12 col-md-2">
<h5><u>Posted On</u></h5>
</div>
<div class="col-xs-12 col-md-2">
<h5><u>Actions</u></h5>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-12">
<?php if ( is_user_logged_in() ):
global $current_user;
if( isset($_GET['db_posts_per_page'] )):
$posts_per_page = $_GET['db_posts_per_page'];
else:
$posts_per_page = 2;
endif;
//echo $posts_per_page;
$author_query = new WP_Query( array('posts_per_page'=>$posts_per_page,
'post_type'=>'post',
'author' => $current_user->ID,
'post_status' => array('publish', 'pending', 'draft'),
'paged' => get_query_var('paged') ? get_query_var('paged') : 1)
);
//print_r($author_query);
while($author_query->have_posts()) : $author_query->the_post();
get_template_part( 'parts/post/content', 'blog-list' );
endwhile;
$big = 999999999;
$paginate_links = paginate_links ( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $author_query->max_num_pages,
'mid_size' => 5,
'prev_next' => true,
) );
wp_reset_postdata();
if (!empty($paginate_links)) : ?>
<div class="pagignation"><?php echo $paginate_links;?></div>
<?php endif;
else:
echo 'You need to be logged in to see your posts.';
endif;?>
</div>
</div>
</div>
</div>
I am try to put pagination in my custom post in wordpress. my custom post type name is videos. it appears the pagination but when I click on the pagination page it goes to 404 page.
<?php
$videos= new WP_Query(array(
'post_type'=>'videos',
'posts_per_page' => 9,
));?>
<?php if($videos->have_posts()) : ?>
<?php while($videos->have_posts()) : $videos->the_post(); ?>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<div class="video">
<?php the_post_thumbnail(); ?>
<div class="watch">
<i class="fa fa-play"></i>
</div>
</div>
<div class="video-exerpt">
<?php the_title(); ?>
</div>
</div>
<?php endwhile; ?>
<div class="col-xs-12 text-center">
<?php
$GLOBALS['wp_query'] = $videos;
the_posts_pagination(
array(
'mid_size' => '2',
'prev_text' => '<i class="fa fa-hand-o-left"></i> Previous',
'next_text' => 'Next <i class="fa fa-hand-o-right"></i>',
'screen_reader_text' => ' '
)
);
?>
</div>
<?php else :?>
<h3><?php _e('404 Error: Not Found', 'Bangladesh Parjatan'); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>
its shows the pagination bt the links are not working. Please help me.
pass your wp_query arguments like this. You should use paged argument for pagination.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$videos= new WP_Query(array(
'post_type'=>'videos',
'posts_per_page' => 9,
'paged' => $paged,
));
hopfully your pagination will work fine.
Can you please replace below code?
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$videos= new WP_Query(array(
'post_type'=>'videos',
'posts_per_page' => 9,
'paged' => $paged,
)); ?>
<?php if($videos->have_posts()) : ?>
<?php while($videos->have_posts()) : $videos->the_post(); ?>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<div class="video">
<?php the_post_thumbnail(); ?>
<div class="watch">
<i class="fa fa-play"></i>
</div>
</div>
<div class="video-exerpt">
<?php the_title(); ?>
</div>
</div>
<?php endwhile; ?>
<?php
$total_pages = $videos->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
));
}
?>
<?php else :?>
<h3><?php _e('404 Error: Not Found', 'Bangladesh Parjatan'); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>
Try the following code:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$videos= new WP_Query(array(
'post_type'=>'videos',
'posts_per_page' => 9,
'paged' => $paged,
)); ?>
<?php if($videos->have_posts()) : ?>
<?php while($videos->have_posts()) : $videos->the_post(); ?>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<div class="video">
<?php the_post_thumbnail(); ?>
<div class="watch">
<i class="fa fa-play"></i>
</div>
</div>
<div class="video-exerpt">
<?php the_title(); ?>
</div>
<?php endwhile; ?>
<?php else :?>
<h3><?php _e('404 Error: Not Found', 'Bangladesh Parjatan'); ?></h3>
<?php endif; ?>
</div>
<nav>
<ul class="pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
?>
</ul>
</nav>
<?php wp_reset_postdata();?>
This is my code so i tried using jquery html load but nothing happens need help masters so any help from you guyz would be appreciated so it would be easy if you guyz would help me to have ajax pagination in my bootstrap navigation.
<?php
/*
* Template Name: Gallery
*/
get_header(); ?>
<script type="text/javascript" charset="utf-8">
</script>
<div class="about-content">
<div class="container">
<div class="border-bottom">
<!--images-->
<div class="services images">
<div class="container">
<div class="content">
<div class="images-tab" role="tabpanel">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">VIEW ALL</li>
<?php $args = array('hide_empty' => false);
$image_category = get_terms('image_category',$args);
foreach($image_category as $image_categories ) :?>
<li role="presentation"><?php echo $image_categories->name; ?></li>
<?php endforeach;wp_reset_query(); ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php
$args = array('hide_empty' => false);
$image_category = get_terms('image_category',$args);
foreach($image_category as $image_categories ) :?>
<div role="tabpanel" class="tab-pane" id="<?php echo $image_categories->slug; ?>">
<div class="row" id="content">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$arg = array(
'post_type' => 'gallery',
'posts_per_page' =>1,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'image_category',
'field' => 'name',
'terms' => $image_categories
)
)
);
$query = new WP_Query($arg);
while($query->have_posts()) : $query->the_post();
$args1 = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
$category_object = wp_get_object_terms($post->ID,'image_category',$args1); ?>
<div id="content" class="post col-md-4"><?php the_post_thumbnail(); ?></div>
<?php endwhile; wp_reset_postdata();?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
<!--images-->
<div class="pagination-content">
<ul>
<li><i class="fa fa-play fa-rotate-180"></i></li>
<li> <?php
global $wp_query;
$big = 999999999; // need an unlikely integer
//$translated = __( 'Page', 'mytextdomain' ); // Supply translatable string
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'prev_next' => false,
'current' => max( 1, get_query_var('paged') ),
'total' => $query->max_num_pages,
//'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
) );
?></li>
<li class="yellow"><i class="fa fa-play"></i></li>
</ul>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
There are lots of ajax wp pagination plugin you can use those https://www.designmaz.net/best-wordpress-pagination-plugins/