I have a blog page in my wordpress site http://jarm.shahumyanmedia.com/blog/.
Here the blogs are posts, and I need to display 5 posts for each page, but I can't display pagination link.
This is how I am getting posts:
$posts = get_posts( array(
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC',
'category' => 5)
);
And this is how I am trying to get pagination links:
<?php wp_link_pages(); ?>
http://codex.wordpress.org/Template_Tags/wp_link_pages
But I don't see any output.
Install and active this plugin and add this code..
http://www.devdevote.com/cms/wordpress-plugins/wp-paging
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('paged='.$paged.'&posts_per_page=5&orderby=date&cat=5&order=DESC');
while (have_posts()) : the_post();
....
endwhile;
wp_paging();
Related
Currently I am trying to get wordpress pagination to display at the bottom of the page but nothing shows up, if I echo out "paged" it outputs 1 so I believe it is correctly reading the page it is on. The loop I am using is as follows:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'company_list', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 6, 'paged' => $paged);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
To echo out the actual pagination at the bottom of the page I am using:
echo paginate_links( $loop );
Currently no pagination is being displayed at the bottom of the page but the loop is working correctly. The page is also not set as a static front page.
Thanks.
1)You do not have to use question mark in your first row
$paged = (get_query_var('paged')) ?
2)also see :
https://stackoverflow.com/a/33757648/10210277
I've set up a basic homepage to show 3 articles per page with pagination to navigate through these pages. At the moment it'll only show pagination for pages 1 & 2 and no more, even though I have 12 articles which result in 4 pages. I'm not quite sure where I'm going wrong here:
<?php
$paged = (get_query_var('paged'))? get_query_var('paged') : '1';
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 2
);
$the_query = new WP_Query( $args );
while ($the_query -> have_posts()) : $the_query -> the_post();
include(locate_template('content-post.php' ));
endwhile;
?>
<?php the_posts_pagination( array('mid_size' => 3) ); ?>
the_posts_pagination use default WP query so it not work here. Can you please try below code:
<?php
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 2
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
while ($wp_query -> have_posts()) : $wp_query -> the_post();
include(locate_template('content-post.php' ));
endwhile;
the_posts_pagination( array('mid_size' => 3) );
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
Code is tested in work perfect.
Your code looks alright to me. I was having the same issue, I resolved it by matching the posts_per_page with the Blog pages show at most field located in Settings->Reading in the admin dashboard
example:
"posts_per_page" => 6 then Blog pages show at most should be also 6
I hope this helps.
Use this plugin Click here
and use this shortcode for pagination <?php wp_pagenavi(); ?>
and I use exact following loop for my project and its working.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args= array(
'cat' => '',
'orderby'=> 'date',
'order'=> 'DESC',
'paged' => $paged ,
'posts_per_page' => 3
);
query_posts($args);
if (have_posts()) :
while (have_posts()):
the_post();
endwhile;
endif;
?>
Please try it. Hope it will work for you also.
And If you are displaying your posts on home page, you need to replace
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
with
<?php
if ( get_query_var('paged') )
{
$paged = get_query_var('paged');
}
else if ( get_query_var('page') )
{
$paged = get_query_var('page');
}
else
{
$paged = 1;
}
The problem is that $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; retrieves the data of the main query object but not for the custom one.
I found a solution here https://wordpress.stackexchange.com/questions/120407/how-to-fix-pagination-for-custom-loops
I know there were a lot of questions about how to use wp_pagenavi with custom wp_query() for CPTs, and I can handle it easily. But I've encountered a bit more complicated situation.
I have a CPT named 'project' and CPT named 'avtoritet_audiotape'. What I need to do - is to show all CPT's 'avtoritet_audiotape' using pagination, but on the single 'project' CPT - it's a kind of relation (for example while I am on page http://simpex/project/radioprogramma-avtoritet, where 'project' is my CPT name).
My code, which is working perfectly on any archive pages, or even single pages is:
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
Information related to my single CPT instance 'project'
<?php endwhile; ?>
<?php $loop = new WP_Query(
array(
'post_type' => 'avtoritet_audiotape',
'posts_per_page' => 6,
'paged' => get_query_var('paged'),
'meta_key' => 'audiotape_date',
'orderby' => 'meta_value_num',
) );
?>
<?php if ( $loop->have_posts() ): ?>
#Some stuff
<?php wp_pagenavi( array( 'query' => $loop ) ); ?>
<?php endif; ?>
So, pagination shows pagination links correctly, but when trying to access http://simpex/project/radioprogramma-avtoritet/page/2 - it redirects to http://simpex/project/radioprogramma-avtoritet
Is it possible in anyway? Thank you
plz try this way.
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$postArray = array('post_type' => 'room', 'posts_per_page' => 5, 'order' => 'DESC', 'paged' => $paged);
$roomPost = new WP_Query($postArray);
global $post;
if ($roomPost->have_posts()) {
while ($roomPost->have_posts()) : $roomPost->the_post(); ?>
<div class="post_title"> <?php the_title(); ?></div>
<?php
endwhile;
wp_pagenavi(array('query' => $roomPost));
}
wp_pagenavi doesn't work from page 2.
[OK] url/wordpress/2013/06/
[NG. 404 error occured] url/wordpress/2013/06/page/2/
I tried some plugins, but nothing changed.
This is my code.
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'post_category' => 3,
'paged' => $paged,
'posts_per_page' => 9,
......
);
$myquery = new WP_Query($args);
<?php if ($myquery->have_posts()) : ?>
<?php while ($myquery->have_posts()): $myquery->the_post(); ?>
/* Do stuff */
<?php endwhile; ?>
wp_pagenavi(array('query' => $myquery));
<?php endif; ?>
Default query works fine in the other page(loop.php).
Wordpress 3.5.1
WP-PageNavi 2.83
Tried plugins are
Top Level Categories Fix
Custom Post Type Category Pagination Fix
Does anyone know anything?
I need to create a wordpress-site which shows 5 posts on the front and in a different loop: 2 posts of the next page. These show up if you visit the second page. Do you have any ideas? I wanna show "More articles" by displaying "older" posts in a different loop.
Thanks
For the first page, limit your listing to 5 posts per page in wordpress settings.
Then you create the second page and apply a page template in witch you have made a custom query to fetch 2 posts.
$cat = get_cat_ID($category);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_per_page = 2; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
'category__in' => array($cat),
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => $post_per_page,
'caller_get_posts' => $do_not_show_stickies
);
$temp = $wp_query; // assign orginal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if( have_posts() ) :
...
To read more, see Wordpress Codex Reference