I'm having trouble figuring out this pagination issue on my site. The problem is that page 2 shows the same content as page 1. It's not supposed to do that.
<?php
$args = array( 'post_type' => 'baseball-news', 'posts_per_page' => 5 );
$baseball_loop = new WP_Query( $args );
while ( $baseball_loop->have_posts() ) : $baseball_loop->the_post();
?>
<?php
if ( get_post_type() == 'baseball-news' ) : ?>
<?php include( TEMPLATEPATH . '/includes/show-baseball-posts.php' ); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php kriesi_pagination($baseball_loop->max_num_pages); ?>
<?php wp_reset_query(); ?>
This is the site for Kriesi pagination.
Site.
You are not using pagination parameter paged in your query. You use it like this:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
$args = array( 'post_type' => 'baseball-news', 'posts_per_page' => 5 , 'paged' => $paged );
Related
I'm working on adding pagination to a page and I am following along on the official codex but I am not getting results. Right now I want to populate pagination after 1 post per page (for testing purposes). No pagination shows, the h3 tags return empty. I have tried multiple queries other than the one below to no avail. Help is sorely needed and appreciated.
<?php
$paged = (get_query_var ('paged')) ? get_query_var ('paged') : 1;
$args = array(
'post_type' => array('post'),
'posts_per_page' => 1,
'paged' => $paged,
'cat' => 5,
'tag__not_in' => 22
);
$the_query = new WP_Query ( $args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- THE CONTENT -->
<?php endwhile; ?>
<h3><?php next_posts_link('Next'); ?></h3>
<h3><?php previous_posts_link('Previous');?></h3>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
I am not getting paging links when using WP_Query in WordPress. I am trying to fetch all the products on the page and show them in page by page manner. For this I want to show the paging links on the bottom. But paging links are not showing.
Below is the link - here
And the code for this is:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'product',
'posts_per_page' => 3,
'paged' => $paged
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
echo '<br />' . woocommerce_get_product_thumbnail().' '.get_the_title().'';
endwhile;
?>
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<? wp_reset_query(); ?>
next_posts_link(); and previous_posts_link(); and not showing links.
Please help.
Use this code instead of of above code.
<?php
$temp = $wp_query;
$wp_query= null;
$postsPerPage = 3;
$argsev = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => $postsPerPage,
'paged' => $paged
);
$wp_query = new WP_Query($argsev);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
global $product;
echo '<br />' . woocommerce_get_product_thumbnail().' '.get_the_title().'';
endwhile; ?>
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<?php
$wp_query = null; $wp_query = $temp;
wp_reset_query();
?>
I am trying to assign serial no in my WordPress Post Category summary Page. For this I have written following code. It is working fine but problem is in the case of paging.
When I am going to 2nd page or 3rd page it assigns the no from 1 again. Currently I am showing 5 posts/per page. Then in 2nd page it should show post no starting from 6 but it starts from 1 again. Same to 3rd and other pages. How can I show it in 1st page from 1-5 and in 2nd page 6-10 etc?
Below is my code:
<?php
// args
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
'paged' => $paged,
'post_type' => 'post',
'cat' => 5,
);
$the_query = new WP_Query( $args );
$postNumber = 1;// to give serial no to post
?>
<?php if($the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php echo $postNumber++; ?> <?php the_title(); ?>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php custom_numeric_posts_nav(); ?>
<?php endif; ?>
<?php wp_reset_query();
Taking help from this topic https://wordpress.stackexchange.com/questions/155903/show-number-of-posts-and-number-on-current-page I have been able to solve my problem. Below is my working code:
<?php
// args
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$ppp = get_query_var('posts_per_page');
$end = $ppp * $paged;
$args = array(
'paged' => $paged,
'post_type' => 'post',
'cat' => 5,
);
$the_query = new WP_Query( $args );
$postNumber = $end - $ppp + 1;// to give serial no to post
?>
I am trying to create a paging within the page.php my thema and is not showing up ! How do?
I'm doing as follows:
Loop:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query_prof = array('post_type' => 'Professor', 'posts_per_page' => 10, 'paged'=>$paged);
$profLoop = new WP_Query($query_prof);
if( $profLoop->have_posts()) : while( $profLoop->have_posts()) : $profLoop->the_post();
get_template_part('partials/content','professores'); ?>
<?php endwhile;
?>
calling on page:
<?php wp_pagenavi( array( 'type' => 'Professor' ) ); ?>
Paging appears , no more list is the first direct
In wordpress I have a page template called news that I want to display all the posts from one category - 'News'. I don't want to use the category.php because there is a massive blog on the site already.
query_posts('cat=145');
while ( have_posts() ) : the_post();
//do something
endwhile;
Works fine but I have read that query_posts has drawbacks (like speed)
I tried doing this but it just showed me nothing:
while ( have_posts() ) : the_post();
if ( in_category( '145' ) ) : //also tried 'News'
//do something
Why doesn't' in_category work here?
please try this code:
$args = array('post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'news' // please pass here you news category slugs
),
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
print_r($post);
endwhile;
wp_reset_postdata();
You could WP Query for achieving your requirement.
Documentation: https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
Example:
<?php
$args = array(
'cat' => 145,
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
Try to use get_posts() function:
$get_p_args = array('category'=> 145,'posts_per_page'=>-1);
$myposts = get_posts( $get_p_args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<div>
<?php the_title(); ?>
</div>
<?php endforeach;
wp_reset_postdata();?>
Try this:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
global $wp_query;
$args = array_merge( $wp_query->query_vars, array(
'post_type' => 'post', // You can add a custom post type if you like
'paged' => $paged,
'posts_per_page' => 6, // limit of posts
'post_status' => 'publish',
'orderby' => 'publish_date',
'order' => 'DESC',
'lang' => 'en', // use language slug in the query
) );
query_posts( $args );