WP-PageNavi Issues, Url changes but the posts remain the same? - wordpress

The issue I am having is I have created a new blog page on its own page template page being called blog.php, I have pulled 5 posts into each page and the first page work great and link to the single posts that they are attached too.
When I try to add wp-pagenavi into my nav-below I run into an issue. What happens is I will click to go the next page and it changes the url, but the posts remain the same as before, when it should be switching them to the next set.
I don't know if you can use wp-pagenavi outside of index.php, but if anyone can let me know what I am doing wrong here and why I continue to get the same posts that would be awesome and greatly appreciated. I have one of my blogs on blog.php and that is the file I am trying to get to work. I have posted the code for it below.
<?php
/**
* Template Name: Blog Page <?php query_posts("posts_per_page=8"); ?>
*/
get_header(); ?>
<div id="content">
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5' ) ); ?>
<?php
//THE LOOP.
if( have_posts() ):
while( have_posts() ):
the_post(); ?>
<article id="post-1" <?php post_class( 'clearfix' ); ?>>
<h2 class="entry-title"> <a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
<div class="postmeta">
<span class="author"> Posted by: <?php the_author(); ?> </span>
<span class="date"> <?php the_date(); ?> </span>
<span class="num-comments">
<?php comments_number('No comments yet', 'One comment', '% comments'); ?></span>
<span class="categories">
<?php the_category(); ?>
</span>
<span class="tags">
<?php the_tags(); ?>
</span>
</div><!-- end postmeta -->
<?php if( has_post_thumbnail() ): ?>
<div class="thumb">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</div>
<?php endif; ?>
<div class="entry-content">
<?php
if( is_single() OR is_page() ):
the_content();
else:
the_excerpt();
endif;
?>
</div>
<?php comments_template(); ?>
</article><!-- end post -->
<?php
endwhile;
else: ?>
<h2>Sorry, no posts found</h2>
<?php endif; //END OF LOOP. ?>
<div id="nav-below" class="pagination">
<?php if( function_exists('wp_pagenavi') ):
wp_pagenavi();
else:
?>
<?php next_posts_link( '← Older Posts' ); ?>
<?php previous_posts_link( 'Newer Posts →' ); ?>
<?php endif; ?>
</div><!-- end #nav-below -->
</div><!-- end content -->
<?php get_footer(); ?>

After <div id="content"> have this code:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5', 'paged' => $paged ) ); ?>

Related

Pagination don't work in custom page template

I created a custom page template like category.php but I can't get the pagination working.
I just filter post from one category.
Here is my code:
<?php
/* Template Name: News */
?>
<?php get_header(); ?>
<div class="col-lg-9 col-md-8 content">
<div class="box">
<h1 class="title"><?php the_title(); ?></h1>
<div class="box-int">
<article>
<?php // Display blog posts on any page # http://m0n.co/l
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=5' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
}
?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<br><br>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Old'); ?></div>
<div class="next"><?php previous_posts_link('Newx »'); ?></div>
</nav>
<?php } else { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Old'); ?></div>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>
</article>
</div>
</div>
</div>
<div class="col-lg-3 col-md-4">
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
What's wrong here? I click in Page 2, but the post are always the same.
Your query is a bit of a mess here with some syntax errors as well.showposts died with the dinosaurs, it is long time depreciated. You should use posts_per_page. 'showposts=5' . '&paged='.$paged is also a mess. You query shouls simplify look like this
$args = array(
'posts_per_page' => 5,
'paged' => $paged
);
$query = new WP_Query( $args );
while ($query->have_posts()) : $query->the_post(); ?>
When querying the loop with WP_Query, you need to assign $max_pages parameter to the next_posts_link().
So you would need to change <?php next_posts_link('« Old'); ?> to <?php next_posts_link('« Old', $the_query->max_num_pages ); ?>
Also go and read this question on this subject. If I missed something, this question will most certainly help you out a lot.

Wordpress Pagination

I have a wordpress site : There is a problem with the pagination.. When I click on 2'nd page it shows up the first one(index page). The other pages are working. Can you help me?
I looked up for errors in the loop but i didn't found anything!
this my index.php code
<?php get_header(); ?>
<div id="content">
<?php if(get_option('freshlife_featured_content_enable') == 'on') { ?>
<div id="featured-content">
<div class="heading">
<span class="heading-text"><?php _e('Featured Articles', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<ul>
<?php
$counter = 1;
query_posts( array(
'showposts' => get_option('freshlife_featured_post_num'),
'tag' => get_option('freshlife_featured_post_tags')
) );
if( have_posts() ) : while( have_posts() ) : the_post();
?>
<li class="featured-<?php echo $counter; ?>"><?php the_post_thumbnail('featured-thumb', array('class' => 'entry-thumb')); ?><span class="entry-date"><abbr title="<?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . __(' ago', 'themejunkie'); ?></abbr></span><h2 class="entry-title"><?php the_title(); ?></h2></li>
<?php $counter++; endwhile; endif; wp_reset_query(); ?>
</ul>
</div> <!-- end #featured-content -->
<?php } ?>
<div class="heading">
<span class="heading-text"><?php _e('All Stories', 'themejunkie'); ?></span>
</div> <!-- end .heading -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php include(TEMPLATEPATH. '/includes/templates/loop.php'); ?>
<?php endwhile; ?>
<div class="clear"></div>
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(); else { ?>
<div class="pagination">
<div class="left"><?php previous_posts_link(__('Newer Entries', 'themejunkie')) ?></div>
<div class="right"><?php next_posts_link(__('Older Entries', 'themejunkie')) ?></div>
<div class="clear"></div>
</div> <!-- end .pagination -->
<?php } ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It's hard to say without looking at the WP_Query generated by the requests.
But I do see something that might be causing problems, query_posts alters the main query, that could be messing with the pagination.
Try to use get_posts instead query_posts, so the main loop is not affected.
A more detailed explanation can be found here

Creating multiple pages with a loop of 1 category in wordpress

i need to make a loop for a single category.
Everything works fine, exept that i'm unable to split the page in multiple parts.
This is the LOOP of my page.
Output is fine, exept that navigation bar doesn't show, and simply adding to url a /page/2 it shows the first 2 posts.
<?php query_posts('cat=179&posts_per_page=2'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-meta">
<?php morlottiTabs_posted_on(); ?>
</div>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
<div class="entry-utility">
<?php morlottiTabs_posted_in(); ?>
<?php edit_post_link( __( 'Edit', 'morlottiTabs' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div>
<?php endwhile; endif; ?>
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'morlottiTabs' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'morlottiTabs' ) ); ?></div>
</div><!-- #nav-below -->
<?php endif; ?>
You can try to do it this way. There are some other methods listed for pagination as well.
Reference: http://digwp.com/2009/08/wordpress-page-navigation/
Reference: http://codex.wordpress.org/Class_Reference/WP_Query
Edit:
Would you want to try a different method?
Wordpress has their own method of pagination
Reference: http://codex.wordpress.org/Function_Reference/paginate_links
<?php echo paginate_links( $args ) ?>

the content function is ignoring more tag

I'm doing "page of post" in twenty eleven theme. Problem is that the_content function ignores more tag and show the whole post. It work just fine in index page.
My code:
/*
Template Name: Page Of Posts
*/
?>
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php
$args= array(
'category_name' => '');
query_posts($args);
if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
Please help!
Can you list a file you are requesting with get_template_part('content', get_post_format() ) it should be in the theme folder named like content-gallery.php(or any other post_format).
Anyway, you can try the good old:
<?php global $more; $more = 0; ?>
Place it before the call for the content.

more flexible or advanced page creation in wordpress 3.2.1

I've been looking into ways to make the wordpress page creation be a little more flexible.
I've gotten as far as defining my own template pages and using those to create the new pages, but I'd like to be able to have a way to input content for more than just the one post div.
When creating a page it is similar to creating a post - i.e you get to edit a title and a bit of content but that's it.
Does anyone know of a method or plugin that would allow editing the title and content of 2 divs on the same page during page creation?
I suggest you use Magic Fields. It basically allows you to add a lot of custom fields. It allows you to build advanced templates. Example of one I created recently:
<?php get_header();?> <div id="left_sidebar" class="grid_3">
<ul class="post_menu sf-menu sf-vertical">
<li class="active"><?php echo $post->post_title; ?></li>
<?php $currentPost = $post; ?>
<!-- Start Loop -->
<?php $args=array(
'post_type' => "post",
'category__in' => get_page_cats($post->ID),
'showposts' => '5000',
'order_by' => 'date',
'order' => 'ASC');
?>
<?php $menu_posts = array(); ?>
<?php $the_query = new WP_Query( $args );?>
<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php if($related_content = get('menu_parent_page')): ?>
<?php $menu_posts[$related_content]['sub'][] = array('id' => $post->ID, 'title' => $post->post_title); ?>
<?php else: ?>
<?php $menu_posts[$post->ID]['parent'] = array('id' => $post->ID, 'title' => $post->post_title); ?>
<?php endif; ?>
<?php endwhile; else: ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php $postCount = 1; ?>
<?php $totalPosts = sizeof($menu_posts); ?>
<?php if($totalPosts > 0):?>
<?php foreach($menu_posts as $the_post): ?>
<li <?php if($postCount == $totalPosts): ?> class="last<?php if($currentPost->ID == $the_post['parent']['id']): ?> active<?php endif; ?>"<?php elseif($currentPost->ID == $the_post['parent']['id']): ?> class="active"<?php endif; ?> ><?php echo $the_post['parent']['title']; ?>
<?php $totalSubPosts = sizeof($the_post['sub']); ?>
<?php $subPostCount = 1; ?>
<?php if($totalSubPosts > 0):?>
<ul>
<?php foreach($the_post['sub'] as $sub_post): ?>
<li <?php if($subPostCount == $totalSubPosts): ?> class="last" <?php endif; ?>><?php echo $sub_post['title']; ?>
<?php $subPostCount++; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php $postCount++; ?>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
<div id="page_content" class="grid_9">
<!-- Start Loop -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1 class="page_header"><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php $logo_image = get_image('extra_logo_image', 1, 1, 0); ?>
<?php if($logo_image): ?>
<img class="brand_logo_all" src="<?php echo $logo_image; ?>" alt="logo" />
<?php endif; ?>
<?php endwhile; else: ?>
<p>An Error Occurred</p>
<?php endif; ?>
<?php wp_reset_query(); ?>
<!-- End Loop -->
<?php $download_items = get_group('download'); ?>
<?php if($download_items): foreach ($download_items as $item): ?>
<div class="download">
<a href="<?php echo $item['download_pdf'][1];?>">
<div class="pdf">
<table>
<tr>
<td><?php echo $item['download_description'][1];?></td>
</tr>
</table>
</div>
</a>
</div>
<?php endforeach; endif;?>
<?php $disable_call_to_action = get('extra_disable_call_to_action'); ?>
<?php if(!$disable_call_to_action): ?>
<?php include_once(TEMPLATEPATH . "/call_to_action.php"); ?>
<?php endif; ?>
</div><!-- #page_content -->
</div><!-- #container --><?php get_footer();?>

Resources