issue with ajax pagination in bootstrap tab on wordpress - php

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/

Related

Pagination in Wordpress home.php

Pagination isn't working in a Wordpress blog. I've tracked the specific file responsible, to home.php.
The original blog page displays posts fine (10 at a time), however as mentioned pagination isn't working.
<?php
/**
Category Page
*/
get_header(); ?>
<div class="container-fluid blogs post-section" id="blogs">
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-9 col-lg-8">
<?php echo category_description( $category_id ); ?>
<div class="category-posts">
<?php
$args = array(
"post_type" => "post",
"post_status" => "publish",
"posts_per_page" => "10",
"orderby" => "date",
"order" => "DESC"
);
$query = new WP_Query($args);
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<div class="col-sm-12">
<div class="inner-post">
<?php if ( has_post_thumbnail() ) { ?><div class="thumbnail col-sm-4" style="background:none!important;"><?php the_post_thumbnail(); ?></div><?php } ?>
<div class="abso custom_abso col-sm-8"><div class="inner-box">
<div class="date">
<?php
$archive_year = get_the_time('Y');
$archive_month = get_the_time('M');
$archive_day = get_the_time('d');
?>
<span class="month"><?php echo $archive_month; ?></span> <span class="day"><?php echo $archive_day; ?>,</span><span class="year"><?php echo $archive_year; ?></span>
</div>
<h2 style="margin-top:0;"><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
<p><a href="<?php the_permalink(); ?>" class="readmores">Read More <i class="fa fa-caret-right" aria-hidden="true"></i>
</a></p>
</div>
<?php endwhile; endif;
?></div>
<div class="pagination text-center">
<?php the_posts_pagination( array( 'mid_size' => 2 ) ); ?>
</div>
<?php wp_reset_query(); ?>
</div>
<?php get_sidebar(); ?>
</div></div></div>
<?php get_footer(); ?>
Based on this Wordpress documentation, I've updated the top of the file, to look like the following:
<div class="category-posts">
<?php $args = array(
'posts_per_page' => 10,
'offset' => 0,
'cat' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => 'publish',
'suppress_filters' => true,
'fields' => '',
);
$posts_array = get_posts( $args ); ?>
<div class="col-sm-12">
This has worked, in that the pagination buttons work, however, only one post is displayed per page:
Any advice on how to display 10 posts per page?
Please add the following parameter 'paged'. It sets pagination query variable. The pagination is works as per this parameter.
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
to the $args.

WP Query - Pagination Buttons not showing

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>'
) );

WP my pagination function don't show in my custom Template

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

Custom Pagination in Buddypress

I have a custom buddypress friends list page that displays the friends videos and I've set my per_page to 50. How can I paginate the friends list in the event a user has more than 50 friends?
<div class="dashboard-wrapper">
<h1>My Friends' Videos</h1>
Dashboard<br>
<?php
$user_id = bp_is_user() ? bp_displayed_user_id() : bp_loggedin_user_id();
$args = apply_filters('bp_show_friends_args', array(
'user_id' => $user_id,
'type' => 'active',
'per_page' => 50,
'max' => $limit,
'populate_extra' => 0
)
);
if (bp_has_members($args)) {
?>
<ul class="bpsf-members">
<?php while (bp_members()) : bp_the_member(); ?>
<li class="bpsf-member">
<?php bp_member_name(); ?>
<div class="item-avatar">
<a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name(); ?>">
<?php bp_member_avatar($avatar_args) ?><?php display_friend_colors(bp_get_member_user_id()); ?>
</a>
</div>
<?php do_action('bp_show_friends_after_friend_avatar', bp_get_member_user_id()); ?><div class="cleared"></div>
<div class="videos">
<ul>
<?php
$args = array(
'author' => bp_get_member_user_id(),
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'member_video',
'posts_per_page' => -1 // no limit
);
$current_user_posts = get_posts($args);
foreach ($current_user_posts as $post) : setup_postdata($post);
$thumbnail = get_post_meta(get_the_ID(), 'thumbnail');
//d($thumbnail);
?>
<li>
<img src="<?= $thumbnail[0] ?>" />
<p><?php the_title(); ?></p>
</li>
<?php
endforeach;
wp_reset_postdata();
?>
</ul>
</div>
<div class="cleared"></div>
</li>
<?php endwhile; ?>
</ul>
<?php }
?>
I've looked at buddypress example code online and I cant find any hints
$user_id = bp_is_user() ? bp_displayed_user_id() : bp_loggedin_user_id();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = apply_filters('bp_show_friends_args', array(
'user_id' => $user_id,
'type' => 'active',
'per_page' => 20,
'paged' => $paged,
// 'max' => $limit,
'populate_extra' => 0
)
);
if (bp_has_members($args)) {
?>
<div id="pagination">
<ul class="pagination">
<li id="previous-stories" class="arrow">
<?php bp_members_pagination_links(); ?>
</li>
</ul>
</div><!-- /#pagination -->
.......

Pagination in custom post type in wordpress

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();?>

Categories