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
Related
I'm trying to configure the Wordpress pagination in de Index homepage.
I've used the WP_Query with the regard of get_query_var('paged') before, just as the code shows:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( array(
'cat' => 7,
'posts_per_page' => 2,
'paged' => $paged
) );
?>
Then I used the native Wordpress function previous_posts_link() to go back onte the list of posts.
The problem that happens is that when the page loads, the url of the page changes, but the posts that shows are the same as before. Even to page 3 or 4, it just shows the same list of pages.
Where am I going wrong?
I'm using an array inside WP_Query, this is for the index.php page. The code is like so
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = new WP_Query( array(
'post__not_in' => $exclude_ids, // This works correctly
'paged' => $paged,
'posts_per_page' => 9, // I added this as a hope but didn't work
) );
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
but the paged is not working. I echod took the $paged out and it is doing 1,2,3 like it should (I'm assuming?) so it that part is working, and the URL is changing and the pagination link recognises it's on page 1,2,3 but the posts are all the same.
Turns out I'm dumb.
I had but the $args as new WP_Query while it should have just been the array.
Pagination on my website not working, everything else is fine, But when i click to go to "/page/2/3/" it shows no page found error.
Website : http://savemoney.16mb.com
Error pages: http://savemoney.16mb.com/page/2/
and currently Front Page set to "Latest Posts" (Not Static Page)
Pagination Code (Frontpage.php):
<?php
// show all coupons and setup pagination
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
query_posts( array( 'post_type' => APP_POST_TYPE, 'post_status' => $post_status, 'ignore_sticky_posts' => 1, 'paged' => $paged ) );
?>
<?php get_template_part('loop', 'coupon'); ?>`
Any advice on how to get this pagination working correctly would be appreciated!
Thanks,
T
have you tried , "add_args" => false ?
here is more info for that https://core.trac.wordpress.org/ticket/30831
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();
I'm having difficulty pulling only the desired category into an archive page on Wordpress. My code is below, I thought by defining get-category-by-slug this would work, but instead its pulling all of the post from every category into the page.
<?php
$category = get_category_by_slug('weddings');
$args = array(
'post_type' => 'elp_projects',
'posts_per_page' => 12,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
);
query_posts($args);
$x = 0;
while (have_posts()) : the_post();
?>
Any ideas on how to fix this would be appreciated.
I've also tried these combinations with no luck.
<?php
$category = get_category_by_slug('weddings');
$args = array(
'post_type' => 'elp_projects',
'posts_per_page' => 12,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
);
$query = new WP_Query( 'category_name=weddings' );
$x = 0;
while (have_posts()) : the_post();
?>
and
<?php $query = new WP_Query( 'category_name=weddings' ); ?>
and
<?php
$args = array(
'post_type' => 'elp_projects',
'posts_per_page' => 12,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
);
$query = new WP_Query( 'category_name=weddings' );
$x = 0;
while (have_posts()) : the_post();
?>
Please do not use query_posts its not the best way to query data its a last resort if you will.
Instead use WP_Query to get posts from one category just do $query = new WP_Query( 'category_name=staff' ); refer to this page for more information on how to get posts from one category using WP_Query.
EDITED
Try this
$the_query = new WP_Query( array(
'post_type' => 'page',
'orderby' => 'date',
'category_name' => 'wedding', //name of category by slug
'order' => 'DESC',
'posts_per_page' => )); // how many posts to show
// Put into the loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
// Restore original Post Data if needed
wp_reset_postdata();