Wordpress page won't paginate - wordpress

Okay I am ripping my hair out over this and I know it is super simple and is staring me in the face but I just can't see it. In essence what is happening is that my pagination isn't working. I use the plugin wp_pagenavi (which is not the issue already checked) It gives me a list of links of each page in the pagination. That all works fine, in fact all the code does what it is supposed to do. The problem is when I click on the pagination link such as "2" or "3" it attempts to go to the corresponding pagination ie www.yousitehere.com/somepage/page/2 but instead the site just reloads the current page without the /page/2.
I think somewhere the page either doesn't realize it needs to paginate and therefore ignores all instances of /page or something is resetting the pagination before the page loads. (its not the reset_query).
This is a Wordpress site. Unfortunately I am unable to show the site link which makes it harder for you bu hopefully someone has a suggestion.
here is my code
<div id="content" class="clearfix">
<div id="main" class="col960 left first clearfix" role="cont_detail">
<?php if (have_posts()) : while (have_posts()) : the_post();
$id = get_the_ID();
$array = metadata($id);
?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="cont_detail" >
<header>
<div id="header_bg_top"></div>
<div id="header_bg">
<?php if($array['custom_facebook'] !="" && $array['custom_twitter'] !="" && $array['custom_linkedin'] != ""&& $array['custom_website'] != "" && $array['custom_blog'] != "" && $array['custom_email'] != ""){?>
<div class="social_link_container">
<div class="width">
<?php if(isset($array['custom_facebook']) && $array['custom_facebook'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-facebook.png">
<?php }
if(isset($array['custom_twitter']) && $array['custom_twitter'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-twitter.png">
<?php }
if(isset($array['custom_linkedin']) && $array['custom_linkedin'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-in.png">
<?php }
if(isset($array['custom_website']) && $array['custom_website'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-web.png">
<?php }
if(isset($array['custom_blog']) && $array['custom_blog'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-blog.png">
<?php }
if(isset($array['custom_email']) && $array['custom_email'] !=""){?>
<img src="<?php echo get_template_directory_uri(); ?>/images/author-email.png"><?php }?>
</div>
</div>
<?php } ?>
<h1 class="cont_detail_title" itemprop="headline"><?php the_title(); ?></h1>
<?php if(isset($array['custom_description']) && $array['custom_description'] !="")
{
?>
<span class="title_description"><?php echo $array['custom_description']; ?></span>
<?php
}
?>
</div><!-- header-bg -->
</header> <!-- end article header -->
<section>
<div class="content-left">
<?php if(isset($array['featured_thumb']) && $array['featured_thumb'] !="")
{
?>
<div class="cont_detail_image">
<?php print_thumbnail($array['featured_thumb'], "medium");?>
</div>
<?php
}
?>
</div>
<div class="content-right">
<?php the_content(); ?>
</div>
</section> <!-- end article section -->
</article> <!-- end article -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1>Not Found</h1>
</header>
<section class="post_content">
<p>Sorry, but the requested resource was not found on this site.</p>
</section>
<footer>
</footer>
</article>
<?php endif;
wp_reset_query();
//Sort queries, most viewed, alphabetical, date
echo '<section><div id="content_bg" class="group">';
$row_num = 1;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if( $_GET['sort'] == 'date' ) {
$sortOrder = getSortOrder( $_GET['dsort_order'] );
$meta_queries[] = array(
'key' => 'custom_authorid',
'value' => $post->ID,
'compare' => 'LIKE',
);
query_posts(array(
'post__not_in' => array($post->ID),
'post_type' => 'post',
'meta_query' => $meta_queries,
'order'=>$sortOrder,
'orderby'=> 'date',
'posts_per_page' => 9,
'paged' => $paged
));
}
elseif( $_GET['sort'] == 'alpha' ) {
$sortOrder = getSortOrder( $_GET['asort_order'] );
$meta_queries[] = array(
'key' => 'custom_authorid',
'value' => $post->ID,
'compare' => 'LIKE',
);
query_posts(array(
'post__not_in' => array($post->ID),
'post_type' => 'post',
'meta_query' => $meta_queries,
'order'=>$sortOrder,
'orderby'=> 'title',
// adding posts_per_page, set to 9 might be different then global preference
'posts_per_page' => 9,
'paged' => $paged
));
}
elseif( $_GET['sort'] == 'mviewed' ) {
}
else{
$meta_queries[] = array(
'key' => 'custom_authorid',
'value' => $post->ID,
'compare' => 'LIKE',
);
query_posts(array(
'post__not_in' => array($post->ID),
'post_type' => 'post',
'posts_per_page' => 9,
'meta_query' => $meta_queries,
'paged' => $paged
));
}
?>
<div class="paginate_nav">
<?php wp_pagenavi(); // use the page navi function ?>
<div class="sort_nav">
<?php contrPaginationLinks( $sortOrder ) ?>
</div><!--sort_nav-->
</div><!--paginate_nav-->
<?php
if( $_GET['sort'] == 'mviewed' ) {
}
else{
if (have_posts()) : while (have_posts()) : the_post();
$item = metadata($post->ID);
$containsVideos = false;
foreach ($item['cat'] as $value) {
if (strpos($value->cat_name,'Videos') !== false) {
$containsVideos = true;
}
}
?>
<div class="story-container" >
<div class="story_left">
<div class="story_image">
<input type="hidden" name="vidID" value="<?php echo $item['media_link']; ?>" />
<div class="about_latest_image <?php echo $item['media_link']; ?>">
<a href="<?php echo $item['link']; ?>">
<?php
print_thumbnail($item['featured_thumb'],"thumbnail", $item['youtube_link'], $item['vimeo_link'], $item['media_link']);
?>
<?php if($containsVideos == true){echo '<span class="videoIndicator"></span>';} ?>
</a>
</div>
</div>
<?php if($_GET['sort'] == 'date'){ ?>
<div class="story_view">
<?php echo $item['date']; ?>
</div>
<?php } ?>
</div>
<div class="story_title">
<a href="<?php echo $item['link']; ?>" title="<?php echo $item['title']; ?>">
<span class="story_title"><?php echo $item['title']; ?></span>
</a>
</div>
<?php if(isset($item['custom_description']) && $item['custom_description'] !="") {
?>
<div class="story_description"><?php echo $item['custom_description']; ?></div>
<?php
}
?>
<div class="story_content"></div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h1><?php _e("No Posts Yet", "hooplahatheme"); ?></h1>
<p><?php _e("Sorry, What you were looking for is not here.", "hooplahatheme"); ?></p>
<?php endif;
} // end display else default
echo '</div></section>';
//
// reset query after display is done
//
wp_reset_query();
?>
<footer>
</footer> <!-- end article footer -->
</div> <!-- end #main -->
Update
It turns out that there is a 302 redirect occurring which is what I am trying to find out the next step.

Christopher's answer probably works for most people.
But..
If you want to stop the redirect from also affecting /pagename/page/1, this will help:
add_filter('redirect_canonical', 'my_redirect_canonical', 10, 2);
function my_redirect_canonical($redirect_url, $requested_url) {
$do_redirect = true;
if(preg_match('/page/',$requested_url)){
$do_redirect = false;
}
return $do_redirect;
}
Found here.

So for anyone with a similar question the answer is simple. You can't paginate single post pages by default in wordpress. It will just redirect back to the root URL of the page. What you need to do to stop this is add this to your themes functions.php
add_filter('redirect_canonical','pif_disable_redirect_canonical');
function pif_disable_redirect_canonical($redirect_url) {
if( is_singular() && in_category('PLACE CAT ID HERE') ) {
$redirect_url = false;
}
return $redirect_url;
}
for more info on this you can look here http://wordpress.org/support/topic/home-pagination-page2-redirect-to-a-post

Related

Pagination issue in my wordpress custom page template

I am using this code for pagination but on the front its showing only pagination link like this "« Previous 1 2 3 4 … 10 Next »" and showing all post(content) in a single page when i click on other pagination link then it showing same post(content) on every link
<?php while( have_rows( 'press' ) ): the_row();
$row++;
// Ignore this image if $row is lower than $min
if($row < $min) { continue; }
// Stop loop completely if $row is higher than $max
if($row > $max) { break; } ?>
<?php
$img_obj = get_field('press');
foreach($img_obj as $press) :
?>
<div class="col-lg-4 col-md-6">
<div class="press-post-wrapper">
<div class="press-post-image">
<img src="<?php echo $press['image']; ?>" alt="<?php echo $press['publication']; ?>">
</div>
<div class="metaData">
<span class="pDate"><?php echo $press['publication'].','?>
<?php echo get_the_date('Y/m/d'); ?></span>
</div>
<div class="press-post-description">
<p><?php echo $press['description']; ?></p>
</div>
</div>
</div>
<?php endforeach; endwhile; ?>
</div>
<?php
// Pagination
echo paginate_links( array(
'base' => get_permalink() . 'page/%#%' . '/', 'format' => '?paged=%#%',
'current' => $page,
'total' => $pages
) );
?>

How to get permalink for every post in this shortcode function

I want to get the permalink of the images that shown on the home page, so that when someone clicks on the image redirects to its full post.
add_shortcode( 'zee_recent_works', function( $atts, $content= null ){
ob_start();
$atts = shortcode_atts(array(
'slides' => 2,
'title' => '',
'description' => ''
), $atts);
extract($atts);
$item_per_slide = 4;
$args = array(
'numberposts' => $item_per_slide*$slides,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'zee_portfolio'
);
$portfolios = get_posts( $args );
$i = 1;
$j = 1;
$count = count($portfolios);
if ($count>0) {
?>
<div class="col-md-12">
<div id="scroller" class="carousel slide">
<div class="carousel-inner">
<?php
foreach( $portfolios as $key=>$value ) {
if( (($key+1)%($item_per_slide)==0) || $j== $count) {
$lastContainer= true;
} else {
$lastContainer= false;
}
if($i==1){
?>
<div class="item <?php echo ($key==0)? 'active': ''; ?>">
<div class="row">
<?php
}
?>
<div class="col-md-<?php echo round(12/$item_per_slide) ?>">
<div class="portfolio-item">
<div class="item-inner">
<?php
echo get_the_post_thumbnail( $value->ID, array(400,400), array(
'class' => "img-responsive",
'alt' => trim(strip_tags( $value->post_title )),
'title' => trim(strip_tags( $value->post_title ))
));
?>
<h5>
<?php echo $value->post_title; ?>
</h5>
<div class="overlay">
<?php
$full_img = wp_get_attachment_image_src( get_post_thumbnail_id($value->ID), 'full');
$img_src= $full_img[0];
?>
<a class="" title="<?php echo $value->post_title; ?>" href="<?php the_permalink(); ?>" rel="prettyPhoto"></a>
</div>
</div><!--.item-inner-->
</div><!--.portfolio-item-->
</div>
<?php
if(($i == $item_per_slide) || $lastContainer) {
?>
</div><!--/.row-->
</div><!--/.col-xs-->
<?php
$i=0;
}
$i++;
$j++;
}
?>
</div>
</div>
</div><!--/.col-md-12-->
<?php
}
return ob_get_clean();
});
and the link is there:
<a class="" title="<?php echo $value->post_title; ?>" href="<?php the_permalink(); ?>" rel="prettyPhoto"></a>
where the permalink should work but its not working.
Instead of the_permalink() you can try get_permalink($value->ID)
final line should be
<a class="" title="<?php echo $value->post_title; ?>" href="<?php echo get_permalink($value->ID); ?>" rel="prettyPhoto" ></a>
Hope it helps :)
Thanks.

All posts on page of one category

I really can't figure this out. I'm trying to have posts all posts on a page from one category, but I still get all categories. This is the code I'm using now. I thought I could manage with WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );, but it totally drives me nuts.
<?php /* Template Name: Blog */ ?>
<?php get_header(); ?>
<div id="content-wrap">
<div id="content">
<div class="post_content">
<h1 class="archive_title"><?php the_title(); ?></h1>
<?php
$query['post_type'] = 'post';
// WP 3.0 PAGED BUG FIX
if ( get_query_var('paged') )
$paged = get_query_var('paged');
elseif ( get_query_var('page') )
$paged = get_query_var('page');
else
$paged = 1;
//$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query['paged'] = $paged;
$recipe_posts = new WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );
while ( $recipe_posts->have_posts() ) { $recipe_posts->the_post(); }
query_posts($query);
if (have_posts()) : ?>
<?php $more = 0; ?>
<div class="posts">
<?php while (have_posts()) : the_post();
$is_recipe = in_category('Resep'); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>>
<?php if (option::get('index_thumb') == 'on') {
get_the_image( array( 'size' => 'loop', 'width' => option::get('thumb_width'), 'height' => option::get('thumb_height'), 'before' => '<div class="post-thumb">', 'after' => '</div>' ) );
} ?>
<div class="details">
<h2 class="title"><?php the_title(); ?></h2>
<?php if ( option::get('display_meta') == 'on' ) { ?>
<div class="meta">
<?php
if ( $is_recipe ) {
$fields = get_fields();
if ( !empty( $fields ) ) echo $fields;
} else { ?>
<p><strong><img src="<?php echo get_template_directory_uri() . '/images/person.png'; ?>" /><?php _e('Author', 'wpzoom'); ?>:</strong><?php the_author_posts_link(); ?></p>
<p><strong><img src="<?php echo get_template_directory_uri() . '/images/clock.png'; ?>" />
<?php _e('Posted', 'wpzoom'); ?>
:</strong> <?php echo get_the_date(); ?></p>
<?php } ?>
</div>
<?php } ?>
<div class="entry">
<?php the_content('<span>'.__('Read More', 'wpzoom').' ›</span>'); ?>
</div>
<p>
<?php if ( option::get('display_readmore') == 'on' && (option::get('display_content') == 'Excerpt') ) { ?>
<a href="<?php the_permalink(); ?>" class=" clean more-link">
<?php _e( ( $is_recipe ? 'Lihat Resep' : 'Read More' ), 'wpzoom' ); ?>
</a>
<?php } ?>
<?php edit_post_link( __('Edit', 'wpzoom'), ' <small>', '</small>' ); ?>
</p>
</div>
<div class="cleaner"> </div>
</div>
<!-- /.post -->
<?php endwhile; ?>
</div>
<div class="cleaner"> </div>
<?php get_template_part( 'pagination' ); ?>
<?php wp_reset_query(); ?>
<div class="cleaner"> </div>
<?php endif; ?>
</div><!-- / .post_content -->
</div><!-- / #content -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
You're making it far too complex, just specificy the stuff you need inside the while loop:
$recipe_posts = new WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );
while ( $recipe_posts->have_posts() ) {
$recipe_posts->the_post();
echo '<li>' . get_the_title() . '</li>';
}
wp_reset_query();
You have entered loop inside loop, try this following with cleaning your code:
$args = array('posts_per_page' => -1 , 'category_name' => 'resep');
$recipe_posts = new WP_Query($args);
if($recipe_posts->have_posts()) :
while($recipe_posts->have_posts()) :
$recipe_posts->the_post();
?>
<h1><?php the_title() ?></h1>
<div class='post-content'><?php the_content() ?></div>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
?>
I cleaned the whole template, but posts from other categories were still there. In the end I managed with these lines
global $wp_query;
$args = array_merge( $wp_query->query, array( 'category_name' => 'resep' ) );
query_posts( $args );
$recipe_posts = new WP_Query($args);
$more = 0;
if($recipe_posts->have_posts()) :
while ($recipe_posts->have_posts()) : $recipe_posts->the_post();?>

Wordpress query_posts Pagination issue

thank you in advanced for any insight I've been scratching my head over this.
This is the code i'm using to call the posts on the homepage: (www.csmpromo.com)
<div id="home-posts">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array( 'cat' => 'home', 'types' => $types, 'posts_per_page' => 19, 'paged' => $paged, ) ); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="home-post"><a href="<?php the_permalink(); ?>" class="transition">
<div class="home-image">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('home-thumb', array('class' => 'home-image')); } else { ?>
<img src="<?php bloginfo('template_directory'); ?>/img/fallback.jpg" alt="<?php the_title(); ?>" class="home-image" />
<?php } ?>
</div>
<?php the_titlesmall('', '<i class="icon-right-open-mini"></i>', true, '80') ?></a>
<div class="home-post-meta">
<i class="icon-user" style="font-size:7px; color:#9B362F"></i> <?php the_author_link(array('class' => 'home-author')); ?></span>
<i class="icon-feather" style="font-size:7px; color:#9B362F"></i> <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>
<i class="icon-chat" style="font-size:7px; color:#9B362F"></i> <?php comments_number('0 Comments', '1 Comments', '% Comments' );?></div>
</div>
<?php endwhile; endif; ?>
<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(); ?>
</div>
I've read there are many issues with using query_posts with pagination but every solutions i've tried has failed.
Thank you!
It's recommended to abandon the usage of query_posts, leave the original query on the home page intact, and modify the query from your functions.php file, using pre_get_posts, e.g.:
add_action( 'pre_get_posts','so16286638_pre_get_posts' );
function so16286638_pre_get_posts( $query )
{
if( is_home() && $query->is_main_query() ){
$query->set( 'cat', 'home' );
$query->set( 'post_type', 'post' );
// more params
}
return $query;
}
More info: https://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts

Bootstrap: Carousel with keyboard controls

Has anyone been able to implement Twitter Bootstrap carousel with keyboard controls? I know this is going to be implement in the next release, but for now I was wondering if any of you has been able to make it work.
Here's my current code:
<script type="text/javascript">
jQuery(document).keypress(function(event) {
if (event.keyCode === RIGHT_ARROW) {
$('a.carousel-control.right').trigger('click');
}
if (event.keyCode === LEFT_ARROW) {
$('a.carousel-control.left').trigger('click');
}
});
</script>
But I'm not getting anywhere with this. Any ideas?
Edit: Here's the Wordpress code I am running...
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<?php if ( $post->post_type == 'portfolios' && $post->post_status == 'publish' ) {
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id(),
'orderby' => 'menu_order',
'order' => 'ASC'
) );
?>
<?php if ( $attachments ) {
$the_rest = array_slice($attachments, 0, 100);
?>
<div id="carousel-<?php the_ID(); ?>" class="featured-carousel carousel slide carousel-fade">
<div class="carousel-inner">
<?php
global $post;
$post_num = 0;
foreach( $the_rest as $attachment) :
$image = wp_get_attachment_image_src( $attachment->ID, 'orion-thumb-900', false );
$post_num++;
?>
<div class="item <?php if($post_num == 1){ echo 'active'; } ?>">
<?php echo "<img src='" . $image[0] . "'>"; ?>
<div class="container">
</div> <!-- /.container -->
</div> <!-- /.item -->
<?php endforeach; ?>
<?php } ?>
<?php } ?>
</div> <!-- /.carousel-inner -->
<a class="left carousel-control" href="#carousel-<?php the_ID(); ?>" data-slide="prev">‹</a>
<a class="right carousel-control" href="#carousel-<?php the_ID(); ?>" data-slide="next">›</a>
</div> <!-- /.carousel -->
<section class="entry-content clearfix">
<?php the_content(); ?>
<?php orion_related_posts(); ?>
</section> <!-- end article section -->
</article> <!-- end article -->
<?php endwhile; ?>
thanks for that,
Even better with carousel events and devices support - 'click' sucks these days!
$(document).bind('keyup', function(e) {
if(e.which == 39){
$('.carousel').carousel('next');
}
else if(e.which == 37){
$('.carousel').carousel('prev');
}
});
Here's the correct code, thanks DavidChase and Flemingslone!
<script type="text/javascript">
jQuery(document).bind('keyup', function(e) {
if (e.keyCode==39) {
jQuery('a.carousel-control.right').trigger('click');
}
else if(e.keyCode==37){
jQuery('a.carousel-control.left').trigger('click');
}
});
</script>

Resources