I coded a wordpress-site and since some time the pagination worked fine. Then it stopped working.
I tried different plugins, but no one works. I want to put the pagination in a special place within a self-coded loop. Therefore the plugin of bestwebsoft seemed to be the best, since it offers the option of displaying the pagination by the use of a bit of PHP. But also that does not work. The support of bestwebsoft is not helpful, they only repeat what I can read in the documentation.
My questions:
1) Is there eventually a problem in my loop, that stops the pagination from displaying?
2) Is it a problem that I use "Masonry" for showing the excerpts and order the excerpts in a horicontal manner? Maybe that interferes with the pagination?
<div class="grid" data-masonry='{ "itemSelector": ".grid-item",
"columnWidth": 285, "gutter": 20 }'>
<?php
$args = array(
'post_type' => array('post',
'os_buch_review',
'os_review',
'os_classic_review',
'os_versus',
),
'post_status' => 'publish',
'nopaging' => false,
'posts_per_page' => '20',
'order' => 'DESC',
'orderby' => 'date',
'cat' => '-5738,-1705, -5933',
);
$tk_startteaser_querie = new WP_Query( $args );
if( $tk_startteaser_querie->have_posts() ) :
?>
<?php
while( $tk_startteaser_querie->have_posts() ) :
$tk_startteaser_querie->the_post();
?>
<div class="grid-item">
<a class="linkclass" href="<?php the_permalink(); ?>"></a>
<h3 class="entry-title"><?php the_title(); ?></h3>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
}
?>
<?php the_excerpt(); ?>
</div><!-- grid-item -->
<?php
endwhile;
if ( function_exists( 'pgntn_display_pagination' ) ) {
pgntn_display_pagination( 'posts' );
}
wp_reset_postdata();
?>
<?php
else :
esc_html_e( 'Derzeit keine Beiträge!', 'text-domain' );
endif;
?>
</div><!--grid-->
I want to have some kind of pagination. I would prefer a self-coded one, but could not do it. Therefore I also would accept a plugin-solution. but nothing works! Most of all i would like to know where the problem is located.
I don't know what is the code in pgntn_display_pagination function but I have modified your code with below one which will work for you.
Kindly check below code.
<div class="grid" data-masonry='{ "itemSelector": ".grid-item",
"columnWidth": 285, "gutter": 20 }'>
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // get the current page variable and set it
$args = array(
'post_type' => array('post',
'os_buch_review',
'os_review',
'os_classic_review',
'os_versus',
),
'post_status' => 'publish',
'nopaging' => false,
'posts_per_page' => '20',
'order' => 'DESC',
'orderby' => 'date',
'cat' => '-5738,-1705, -5933',
'paged' => $paged // use $paged variable here
);
$tk_startteaser_querie = new WP_Query( $args );
if( $tk_startteaser_querie->have_posts() ) :
?>
<?php
while( $tk_startteaser_querie->have_posts() ) :
$tk_startteaser_querie->the_post();
?>
<div class="grid-item">
<a class="linkclass" href="<?php the_permalink(); ?>"></a>
<h3 class="entry-title"><?php the_title(); ?></h3>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
}
?>
<?php the_excerpt(); ?>
</div><!-- grid-item -->
<?php
endwhile;
// Below is full code of pagination
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $query->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => false,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => sprintf( '<i></i> %1$s', __( 'Next', 'text-domain' ) ),
'next_text' => sprintf( '%1$s <i></i>', __( 'Previous', 'text-domain' ) ),
'add_args' => false,
'add_fragment' => '',
) );
wp_reset_postdata();
?>
<?php
else :
esc_html_e( 'Derzeit keine Beiträge!', 'text-domain' );
endif;
?>
</div><!--grid-->
Related
I have custom page for posts which has to show up 9 posts per page and I used wp_pagenavi plugin but it doesn't work. Please help!
<div class="page-content__wrapper">
<?php
$post_category = get_field('page_category');
$posts = get_posts( array(
'numberposts' => 9,
'category_name' => $post_category,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'suppress_filters' => true,
) );
foreach( $posts as $post ){
setup_postdata($post);
?>
//...posts
<?php
}
wp_pagenavi();
wp_reset_postdata();
?>
</div>
I used WP_Query() to solve this problem (without wp_pagenavy plugin :)
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; // setup
$post_category = get_field('page_category'); // getting category name
$posts= new WP_Query(array(
'post_type'=> 'post',
'posts_per_page' => 9,
'paged' => $paged, // don't forget to give this argument
'category_name' => $post_category,
));
if($posts->have_posts()) :
while($posts->have_posts()) : $posts->the_post(); ?>
// All posts will be here!
<?php endwhile; ?>
<div class="mt-30 text-center">
<?php
$GLOBALS['wp_query'] = $posts;
the_posts_pagination(
array(
'mid_size' => '2',
'prev_text' => '<i class="fa fa-hand-o-left"></i> <',
'next_text' => '> <i class="fa fa-hand-o-right"></i>',
'screen_reader_text' => ' '));
?>
</div>
<?php else :?>
<h3><?php _e('404 Error: Not Found'); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>
On a wordpress site I am coding an authors page. Therefore I use a custom query that I also use in several other parts of the site. Partly it works fine, but as it has a major bug, I cannot use it:
I receive not only a chosen autors post. All posts of all authors are listet.
If I use the main loop, I do not have that problem. But because of the pagination which should be the same everywhere, I would like to use the custom loop. Where is my mistake?
Here my code:
<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
?>
<section class="tk_fullwidth">
<div id="primary" class="content-area">
<h1 class="page-title">Beiträge von: <?php echo $curauth->nickname; ?></h1>
<div id="main" class="site-main" role="main">
<div class="grid" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": 285, "gutter": 20 }'>
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '50',
'paged' => $paged,
'order' => 'DESC',
'orderby' => 'date',
) );
?>
<!-- begin loop -->
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="grid-item">
<a class="xyz" href="<?php the_permalink(); ?>"></a>
<h3 class="entry-title"><?php the_title(); ?></h3>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
}
?>
</div><!-- grid-item -->
<?php endwhile; ?>
<!-- end loop -->
<div class="tk_pagination">
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $query->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => false,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => sprintf( '<i></i> %1$s', __( '<', 'text-domain' ) ),
'next_text' => sprintf( '%1$s <i></i>', __( '>', 'text-domain' ) ),
'add_args' => false,
'add_fragment' => '',
) );
?>
</div>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
</div><!-- #main -->
</div><!-- #primary -->
</section><!--tk_fullwidth-->
I'm facing problem in my custom post pagination. The custom pagination is work fine on single page with same code but it is not working on another page.
I have updated the permalink many times but nothing happen. I also update .htaccess file.
My source code listed here...
<div id="home" class="tab-pane fade in active">
<p class="main_dv"><?php
//$count=1;
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$data= new WP_Query(array(
'post_type'=>'software',// your post type name
'category_name' => 'general_software', // your category name
'posts_per_page' => 5, // post per page
'paged' => $paged,));
if($data->have_posts()) :
while($data->have_posts()) : $data->the_post();?>
<div class="testcustompost1">
<div class="pst_div">
<div class="thumb">
<?php the_post_thumbnail();?>
</div>
<div class="title_des">
<div class="title">
<?php the_title();?>
</div>
<div class="description">
<?php the_content();?>
</div>
<div class="downlod_btn">
<button class="btn"> Download </button>
</div>
</div>
</div>
</div>
<?php //$count++;
endwhile;
echo '<div class="paginat_design">';
$total_pages = $data->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 »'),
));
}
echo '</div>'?>
<?php else :?>
<?php _e('404 Error: Not Found', ''); ?>
<?php endif; ?>
<?php wp_reset_postdata();?>
</p>
</div>
404 Not found error
You should try this:
<?php
/**
* Looping through the content
*/
$page = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
$data = new WP_Query (array(
'post_type'=>'software',
'category_name' => 'general_software',
'posts_per_page' => 5,
'page' => $page
)); ?>
<?php while ($data -> have_posts()) : $data -> the_post(); ?>
<!-- Your html code here -->
<?php endwhile; ?><?php wp_reset_query(); ?><?php wp_reset_postdata();
?>
Here is the pagination part:
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $data->max_num_pages,
'current' => max( 1, get_query_var( 'page' ) ),
'format' => '?page=%#%',
'show_all' => false,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => sprintf( '<i></i> %1$s', __( 'Previous Page', 'text-domain' ) ),
'next_text' => sprintf( '%1$s <i></i>', __( 'Next Page', 'text-domain' ) ),
'add_args' => false,
'add_fragment' => '',
) );
?>
Let me know if it is this help you. If not, try to change the value from paged to page.
I'm trying to make pagination for result of two post types which is one custom post type question and the normal post
first of all when I show all result without pagination using 'posts_per_page' => -1; the function works fine
but the problem happen when I try to make pagination, as you can see pagination function works normally except the some last pages of the pagination (I guess which contains question post_type even recent post type of questions appears normally )
here you are my full code
<?php
$my_query = new WP_Query(
array(
'post_type' => array('question', 'post'),
'posts_per_page' => get_option('to_count_portfolio'), // -1 to show all results
'author' => $post->post_author,
'paged' => get_query_var('paged') ? get_query_var('paged') : 1
)
);
?>
<?php
while ( $my_query->have_posts() ) : $my_query->the_post();
?>
<span class="title">
<?php echo get_post_type(); ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</span>
<br />
<?php endwhile; ?>
<?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' => $my_query->max_num_pages
)
);
?>
How can I make pagination work normally and navigate to all pagination links ?
Replace your code this:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ($paged == "1") {
$args = array(
'post_type' => array('question', 'post'),
'posts_per_page' => get_option('to_count_portfolio'), // -1 to show all results
'author' => $post->post_author,
'offset' => 0
);
} else {
$offset = $paged * 5;
$offset = $offset - 5;
$args = array(
'post_type' => array('question', 'post'),
'posts_per_page' => get_option('to_count_portfolio'), // -1 to show all results
'author' => $post->post_author,
'offset' => $offset
);
}
$loop = new WP_Query($args);
?>
<?php
if ($loop->have_posts()) :while ($loop->have_posts()) : $loop->the_post();
?>
<span class="title">
<?php echo get_post_type(); ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</span>
<br />
<?php endwhile; ?>
<div class="pagination-grp">
<?php
$big = 999999999; // need an unlikely integer
//$i=1;
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'prev_text' => __('<'),
'next_text' => __('>'),
'total' => $loop->max_num_pages
));
wp_reset_postdata();
endif;
?>
</div>
install this free plugin https://wordpress.org/plugins/wp-pagenavi/
then refer below code
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array (
'post_type' => 'post',
'cat' => '53',
'paged' => $paged,
'posts_per_page' => '10',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
get_template_part('parts/bl`enter code here`ogloop');
}
if(function_exists('wp_pagenavi'))
{
wp_pagenavi( array( 'query' => $query ) );
}
wp_reset_postdata();
} else {
echo 'no posts here';
}
This will show paging and work like a charm for you.
I guess that I figure it out
the solution is to edit the WP_Query args to be a custom number which is not same as site posts_per_page
'posts_per_page' => 11, // 13, or 20 ...
instead of
'posts_per_page' => get_option('to_count_portfolio'),
Why ? I've no idea, maybe the are some kind of conflict
someone can try it and see if that solution works with him/her same as me
Using below code i'm listing all posts under custom post type people
<?php $loop = new WP_Query(array('post_type' => 'people', 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => 'wpcf-people-sort-order','posts_per_page' => 4, 'paged' => get_query_var('paged') ? get_query_var('paged') : 1 )
); ?>
<div>Title: <?PHP the_title(); ?></div>
<div>Description: <?php echo esc_html( get_post_meta( $postid, 'wpcf-people-desscription', true ) ); ?> </div>
<?php endwhile; ?>
Below is my pagination,
<div class="cus-pagi">
<?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' => $loop->max_num_pages
) );
?>
</div>
Also i created a plugin using above code to display list of titles in sidebar. So whenever i access mysite.com/people both(i.e list of custom posts with pagination & sidebar list of post title) of my custom query are working fine.
If i go to second page, sidebar is showing empty.
did anyone know where i'm going wrong ?
You you need to use the Loop with your custom query:
<?php
$loop = new WP_Query(
array(
'post_type' => 'people',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'wpcf-people-sort-order',
'posts_per_page' => 4,
'paged' => get_query_var('paged') ? get_query_var('paged') : 1 )
);
if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post();
?>
<div>Title: <?PHP the_title(); ?></div>
<div>Description: <?php echo esc_html( get_post_meta( $postid, 'wpcf-people-desscription', true ) ); ?> </div>
<?php endwhile; endif; wp_reset_postdata(); ?>