html5blank pagination not working - php

<?php
/* Template Name: Front page */
get_header();
?>
<div class="rfp_hide" id="rhm_show">
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
'post_type' => 'product',
'page' => $paged,
'posts_per_page' => 20,
'product_cat' => '',
'orderby' => 'date',
'order' => 'DESC'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $post, $paged;
?>
<div class="rhm_container">
<?php echo do_shortcode('[show_post]'); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<nav>
<ul>
<li><?php previous_posts_link( '« PREV', $loop->max_num_pages) ?></li>
<li><?php next_posts_link( 'NEXT »', $loop->max_num_pages) ?></li>
</ul>
</nav>
</div>
</main><!--/main content -->
<?php get_footer(); ?>
So, this is my html5blank template that I have which shows posts.
I can't seem to be able to make the pagination work.
Well, that's not entirely true. I can see the "Next" button at the bottom. The href is example.com/page/2. However when I click it, it just refreshes the page and does not go to page 2.
Does anyone know why it might be like that?
Thank!

Related

How can I show my index page posts with post meta?

I try to show my posts in my index page with post meta for this reason I make a wp query like this:
<?php $recent = new WP_Query(
array(
'posts_per_page' => 5,
'post_type' => 'post',
'meta_key' => 'post-filter-select',
'meta_value' => 'music'));
while($recent->have_posts()) : $recent->the_post();?>
It's great and work but for pagination I have big problem! It don't work!
may I customize my index page query? How can I do this customization with keeping my pagination work ?
Quick example:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 5,
'paged' => $paged,
'post_type' => 'page',
'meta_value' => 'music'
);
$recent = new WP_Query($args);
?>
<?php if ($recent->have_posts()) : while ($recent->have_posts()) : $recent->the_post(); ?>
// loop
<?php endwhile; endif; ?>
<nav>
<ul>
<li><?php previous_posts_link( '« PREV', $recent->max_num_pages) ?></li>
<li><?php next_posts_link( 'NEXT »', $recent->max_num_pages) ?></li>
</ul>
</nav>
<?php wp_reset_query(); ?>
Hope help you.

Pagination on Home Page (WordPress)

I'm having an issue trying to get pagination to work on the homepage of a site I'm working on.
The "Older" and "Newer" links show correctly, and it updates the url to reflect the page number but the posts content remains the same as it does on the first page when flipping through the pages. Here is the code I'm using, simplified of course:
if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); }
elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); }
else { $paged = 1; }
$get_featured_posts = new WP_Query( array(
'posts_per_page' => 9,
'post_type' => 'post',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'paged' => $paged,
'offset' => 5
) );
while( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
<h3 class="entry-title entry-added">
<?php the_title(); ?>
</h3>
<p class="short_description"><?php echo short_description('...', 16); ?> </em></p>
<p class="read_more">Read More</p>
<?php
endwhile;
?>
<?php
// Reset Post Data
wp_reset_query();
?>
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
Can't seem to figure out what the problem is, any help would be appreciated.
try to use wp_reset_postdata(); instead of wp_reset_query(); and also updated condition for $paged.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$get_featured_posts = new WP_Query( array(
'posts_per_page' => 9,
'post_type' => 'post',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'paged' => $paged,
'offset' => 5
) );
while( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
<h3 class="entry-title entry-added">
<?php the_title(); ?>
</h3>
<p class="short_description"><?php echo short_description('...', 16); ?> </em></p>
<p class="read_more">Read More</p>
<?php
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
?>
Please read this and insert that code of pagination on your page and remove newer and older links
https://www.elegantthemes.com/blog/tips-tricks/how-to-add-pagination-to-wordpress
Figured out the problem thanks to #milo on the WordPress exchange. Turns out there are special considerations when using "offset" and pagination. Check this link for more details.

Wordpress Static frontpage search pagination

I have a static frontpage on my wordpress website, displaying my posts. Currently it shows 10 posts and I want to make it possible to click "next page" to see the next 10 posts in the query and so on. I have tried getting the pagination to work, but it looks like I'm unable to connect it with my search query.
Here is my query:
<?php
query_posts(
array( 'post_type' => 'post',
'order' => 'DESC',
'meta_key' => 'cf_votes',
'orderby' => 'meta_value_num',
'posts_per_page' => 10
)
);
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
And here is the pagination I have tried:
<?php
global $wp_query;
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
So basically I'm able to see the first 10 posts perfectly. But no alternative to see more posts is shown.
Wordpress Codex is pretty comprehensive on the Pagination problem, I recommend you to see this:
http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query
There's a section specifically for the Static Front Page.
Something like:
<?php
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
$args = array(
'posts_per_page' => 3,
'paged' => $paged
);
query_posts($args);
?>
<?php if ( have_posts() ) : ?>
<!-- Add the pagination functions here. -->
<!-- Start of the main loop. -->
<?php while ( have_posts() ) : the_post(); ?>
<!-- the rest of your theme's main loop -->
<?php endwhile; ?>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

Pagination with Wordpress using "wp-query"

Hey all i'm running a query loop in a custom page.php using a custom post type. I would for it to paginated so i could have a specific amount of post per page. I was wondering if someone could help me out. I have added my code below:
<?php query_posts( array(
'post_type' => array( 'POSTTYPE' ),
'showposts' => -1 )
); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="">
<?php the_title(); ?>
<?php the_post_thumbnail( 'thumbnail' , array('class' => 'aligncenter project_post_thumbnail') ); ?>
View
</div>
<?php endwhile; ?>
Thanks!
The problem as wordpress.org documentation says:
Pagination won't work correctly, unless you set the 'paged' query var appropriately: adding the paged parameter
Example of usage:
<?php
$args = array(
'cat' => '5',
'post_type' => 'POSTTYPE',
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
while (have_posts()) : the_post();
/* Do whatever you want to do for every page... */
?>
<?php the_title(); ?>
<?php the_post_thumbnail( 'thumbnail' , array('class' => 'aligncenter project_post_thumbnail') ); ?>
View
<?php
endwhile;
?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php
wp_reset_query(); // Restore global post data
?>
Also you can check rvoodoo guide if you have more questions about it.

Wordpress: archive multiple post types

I'm trying to figure out if it's possible to archive multiple post types on a page, I have an individual archive for each of the post types working fine, but I also want another page that will archive both of them. I'm still quite new to WP so I'm not at all sure if it's possible but what I'm doing so far isn't working correctly:
<?php query_posts('post_type=type01'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div class="type01-div" data-value="<?php
$date = DateTime::createFromFormat('dnY', get_field('type01_date_select'));
echo $date->format('dnY');
?>">STUFF HERE</div>
</a>
<?php endwhile; endif; ?>
<?php query_posts('post_type=type02'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div class="type02-div" data-value="<?php
$date = DateTime::createFromFormat('dnY', get_field('type02_date_select'));
echo $date->format('dnY');
?>">STUFF HERE</div>
</a>
<?php endwhile; endif; ?>
So all the posts from 'type01' are showing up, but the posts from 'type02' aren't. Is it possible to archive both? In separate loops though as each post type will be wrapped in a different div class.
You need to reset your query for the next loop, add this between your loops:
<?php wp_reset_query(); ?>
I have a similar page like this and used this code to do it:
<h2>type01</h2>
<?php
$args = array(
'post_type' => array( 'type01' ),
'order' => 'asc',
'orderby' => 'title',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
<h2>type02</h2>
<ul>
<?php
$args = array(
'post_type' => array( 'type02' ),
'order' => 'asc',
'orderby' => 'title',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
Check out this link for more info: http://codex.wordpress.org/Function_Reference/wp_reset_query

Categories