How to create separate pagination for mutiple loops? - php

I have created two loops with pagination (first loop loops through CAT'S category and second loops through DOG'S category), but now I am stuck:(
The problem: After I click "Next entry" on my site (CAT'S category) it goes to second entry in that category BUT it also goes to my DOG'S category second entry (I don't want THAT!! ). It also happens vice versa...
What I like to do is this: I click on "Next Entry" on my CAT'S category and it goes only to next post in THAT category (CAT'S) but NOT to second post in my DOG'S category, or another way around: I click on "Next Entry" on my DOG'S category and it goes only to next post in THAT category (DOG'S) but NOT to second post in my CAT'S category .
Can someone help me please? I have asked for help on
wordpress.stackexchange.com a while ago but I didn't get any answer so I am asking question here.
Index php looks like this:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="blog">
<?php
$args = array(
'category_name' => 'cats'
);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_query($args . '&paged=' . $paged . '&cat=-3');
while( $the_query -> have_posts()) : $the_query -> the_post();
?>
<div class="post">
<div class="post_title">
<h3><?php the_title(); ?></h3>
</div>
<div class="entry">
<?php the_post_thumbnail(); ?>
<?php the_content('Read on...'); ?>
<p class="postmetadata">
<?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?><br />
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
</p>
</div>
</div>
<?php endwhile;?>
<?php wp_reset_postdata();?>
<div class="navigation">
<div style="float:left;" class="alignleft"><?php previous_posts_link('« Previous Entries') ?></div>
<div style="float:right;" class="alignright"><?php next_posts_link('Next Entries »',$the_query->max_num_pages) ?></div>
</div>
</div>
<div id="blogs">
<?php
$args = array(
'category_name' => 'dogs'
);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_query($args . '&paged=' . $paged . '&cat=-10');
while( $the_query -> have_posts()) : $the_query -> the_post();
?>
<div class="post">
<div class="post_title">
<h3><?php the_title(); ?></h3>
</div>
<div class="entry">
<?php the_post_thumbnail(); ?>
<?php the_content('Read on...'); ?>
<p class="postmetadata">
<?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?><br />
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
</p>
</div>
</div>
<?php endwhile;?>
<?php wp_reset_postdata();?>
<div class="navigation">
<div style="float:left;" class="alignleft"><?php previous_posts_link('« Previous Entries') ?></div>
<div style="float:right;" class="alignright"><?php next_posts_link('Next Entries »',$the_query->max_num_pages) ?></div>
</div>
</div>
<?php get_footer(); ?>

You need 2 different paging values so add some new ones and rewrite rules which look for them (they're really just to make the urls neater looking). The rewrite rules and the pagination link format mean you can page through one category while the other category page doesn't change.
In functions.php:
function add_new_rules()
{
// new 'paged' variables
global $wp;
$wp->add_query_var('paged_cats');
$wp->add_query_var('paged_dogs');
// rewrite rules
add_rewrite_rule('page/cats/(\d+)/dogs/(\d+)', 'index.php?paged_cats=$matches[1]&paged_dogs=$matches[2]', 'top');
add_rewrite_rule('page/cats/(\d+)/dogs/?$', 'index.php?paged_cats=$matches[1]&paged_dogs=1', 'top');
if( !array_key_exists('page/cats/(\d+)/dogs/(\d+)', (array)get_option('rewrite_rules')) )
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
add_filter('init', 'add_new_rules');
Check for the new query vars in index.php and use them for each WP_Query and the related pagination links.
<div id="blog">
<?php
$paged_cats = (get_query_var('paged_cats')) ? get_query_var('paged_cats') : 1;
$paged_dogs = (get_query_var('paged_dogs')) ? get_query_var('paged_dogs') : 1;
$cats = new WP_query(array(
'category_name' => 'cats',
'paged' => $paged_cats,
'posts_per_page' => 1
));
while( $cats->have_posts() ) : $cats->the_post();
?>
<div class="post">
<div class="post_title">
<h3><?php the_title(); ?></h3>
</div>
<div class="entry">
<?php the_post_thumbnail(); ?>
<?php the_content('Read on...'); ?>
<p class="postmetadata">
<?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?><br />
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
</p>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php if ( $cats->max_num_pages > 1 ) : ?>
<div class="navigation">
<?php
echo paginate_links(array(
'base' => home_url("page/cats/%#%/dogs/{$paged_dogs}"),
'format' => '%#%',
'current' => $paged_cats,
'total' => $cats->max_num_pages,
));
?>
</div>
<?php endif; ?>
</div>
<hr>
<div id="blogs">
<?php
$dogs = new WP_query(array(
'category_name' => 'dogs',
'paged' => $paged_dogs,
'posts_per_page' => 1
));
while( $dogs->have_posts() ) : $dogs->the_post();
?>
<div class="post">
<div class="post_title">
<h3><?php the_title(); ?></h3>
</div>
<div class="entry">
<?php the_post_thumbnail(); ?>
<?php the_content('Read on...'); ?>
<p class="postmetadata">
<?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?><br />
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
</p>
</div>
</div>
<?php endwhile;?>
<?php wp_reset_postdata();?>
<?php if ( $dogs->max_num_pages > 1 ) : ?>
<div class="navigation">
<?php
echo paginate_links(array(
'base' => home_url("page/cats/{$paged_cats}/dogs/%_%"),
'format' => '%#%',
'current' => $paged_dogs,
'total' => $dogs->max_num_pages,
));
?>
</div>
<?php endif; ?>
</div>

Your problem is this:
On pagination wordpress sends page id or count to get the next enteries and the name of the variable that goes in postback is same for both lists. When it goes to the server both lists get a request to go to next page by looking at the post variables.
The solution mentioned by jho1086 is to create paged variable as a custom variable for both lists and assign it. this would then send a different variable for each list and you can move next or previous as you wish.
You need to do both add a paged variable and add it to your pagination as well. In jho1086's solutuin see $args1 and $pag_args1 both have reference to $paged2 to make this happen.
When you select page 2 for cats it should send a catpage=2 to the server
When you select page 2 for Docs it should send a dogpage=2 to the server
If you can solve this for pagination links and pass the args then you can do following
When server gets the list of cats use catpage as a paging param
When server gets the list of dogs use dogpage as a paging param
This is in theory and will surely work. You can test variables going in and out of the request via firebug and comeback with what other issues you have but the reason your loops go to page 2 for clicking on one is that both loops are paging on the same post variable.

I find answer here https://wordpress.stackexchange.com/questions/47259/multiple-wp-query-loops-with-pagination, the choice answer is working with me. It use format.
<!-- Cats -->
<div class="animals">
<?php
$paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
$paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
// Custom Loop with Pagination 1
// http://codex.wordpress.org/Class_Reference/WP_Query#Usage
$args1 = array(
'paged' => $paged1,
'posts_per_page' => 2,
);
$query1 = new WP_Query( $args1 );
while ( $query1->have_posts() ) : $query1->the_post();
the_title();
echo '<br>';
the_category(' ');
the_excerpt();
echo '<hr>';
endwhile;
// http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
$pag_args1 = array(
'format' => '?paged1=%#%',
'current' => $paged1,
'total' => $query1->max_num_pages,
'add_args' => array( 'paged2' => $paged2 )
);
echo paginate_links( $pag_args1 );
?>
</div>
<!-- Dogs -->
<div class="animals">
<?php
// Custom Loop with Pagination 2
$args2 = array(
'paged' => $paged2,
'posts_per_page' => 2,
);
$query2 = new WP_Query( $args2 );
while ( $query2->have_posts() ) : $query2->the_post();
the_title();
echo '<br>';
the_category(' ');
the_excerpt();
echo '<hr>';
endwhile;
$pag_args2 = array(
'format' => '?paged2=%#%',
'current' => $paged2,
'total' => $query2->max_num_pages,
'add_args' => array( 'paged1' => $paged1 )
);
echo paginate_links( $pag_args2 );
?>
</div>
And since it is generating a un-clean url you can add a rel="nofollow" for SEO purposes. Here is the instruction how to do add rel="nofollow"

the functions next_post_link() and previous_post_link() has a third argument called 'in_same_cat' - You will need to set it to TRUE.
Read the codex page (click on the functions name in the answer .
From codex :
<?php next_post_link('%link', 'Next post in category', TRUE); ?>
They even have a fourth argument 'excluded_categories' which you can also use for achieving the same thing, or combining both to get even more sophisticated results.

Related

Pagination doesnt work in custom post type

Pagination template part includes common pagination function with style. The template part works for archive.php (it's for "single", you know default wp file) but doesn't work for custom post type.
Why not? How to solve it?
<?php get_header(); ?>
<main role="main">
<!-- section -->
<?php get_template_part( 'breadcrumb' );?>
<!-- Inner Pages Main Section -->
<section class="ulockd-service-details">
<div class="container">
<div class="col-md-12">
<div class="row">
<?php
/**
* Setup query to show the ‘services’ post type with ‘8’ posts.
* Output the title with an excerpt.
*/
$args = array(
'post_type' => 'team',
'post_status' => 'publish',
'posts_per_page' => 1,
);
$loop = new WP_Query( $args );
if (have_posts()): while ( $loop->have_posts() ) : $loop->the_post();
?>
<?php //if (have_posts()): while (have_posts()) : the_post(); ?>
<?php
if ( $thumbnail_id = get_post_thumbnail_id() ) {
if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'normal-bg' ) )
?>
<div class="col-md-12 ulockd-mrgn1210">
<div class="ulockd-project-sm-thumb">
<img class="img-responsive img-whp" src="<?php printf( '%s', esc_url($image_src[0]) ); ?>" alt="">
</div>
</div>
<?php
}
?>
<div class="col-md-12 ulockd-mrgn1210">
<article class="ulockd-pd-content">
<div class="ulockd-bp-date">
<ul class="list-inline">
<li class="ulockd-bp-date-innner">On <span class="text-thm2"><?php the_time('j'); ?></span> / <?php the_time('F Y') ?></li>
<li class="ulockd-bp-comment"><span class="flaticon-nurse-head text-thm1"></span> <?php the_author_posts_link(); ?></li>
<li class="ulockd-bp-comment"><span class="flaticon-chat text-thm1"></span> <?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></li>
<li class="ulockd-bp-comment"><span class="flaticon-black-check-box text-thm1"></span> <?php the_category(); ?></li>
</ul>
</div>
<h3><?php the_title(); ?> </h3>
<p class="project-dp-one"><?php html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?></p>
<a class="btn btn-lg ulockd-btn-thm2" href="<?php the_permalink(); ?>"> Read More</a>
</article>
</div>
<?php get_template_part('pagination'); ?>
<?php endwhile; ?>
<?php else: ?>
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<?php endif; ?>
</div></div></div></section>
<?php get_footer(); ?>
</main>
First of all, you don't need to include that template inside while loop. That's wrong.
Then, if you want to have an archive page for your team post type, you need to provide 'has_archive' => true within register_post_type() function args.
Also, consider changing archive page default slug if needed. If you do so, you need to open Settings > Permalinks for resetting your permalinks structure.
Then you could either use standard archive.php for the whole team archive page and standard template-parts/content.php for one post inside the loop or rewrite either of those by creating archive-team.php or content-team.php. And the_posts_pagination() function will work on proper archive page (either archive.php or archive-team.php).
I would try two things.
Add the argument paged to your wp_query args :
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'team',
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 1,
);
Put your pagination template outside the loop :
<?php endwhile; ?>
<?php get_template_part('pagination'); ?>

Multiple loops: exclude a post returned in loop 1 from loop 2

I have two wp_query loops.
The first loop looks for a featured post and formats it differently than the rest of the posts.
Then the second loop displays the rest of the posts.
I want to exclude this first, featured post from the rest of the loop.
Right now, the post ID of the first post is saved as a variable.
I want to use that variable in the second loop, with the wp_query exclude argument.
But as far as I understand, that variable dies when my first loop ends. It's then a null variable in the second loop and so nothing is excluded.
<!-- Here's the query for the featured post -->
<?php
// the arguments
$args = array(
'posts_per_page' => '1',
'orderby' => '',
'meta_key' => 'featured_post',
'meta_value' => '1'
); ?>
<?php $the_query = new WP_Query($args); ?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<!-- I'm storing the ID so I can exclude it from the rest of the loop, but I know this doens't work right now -->
<?php $postid = get_the_ID(); ?>
<div class="small-12 columns entry" >
<div class="text-center" id="featured-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('featured'); ?>
</a>
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php
$content = get_the_content();
echo wp_trim_words($content, '75');
?>
</p>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<!-- If there is no featured post, pull in the most recent post and make it big -->
<?php else: ?>
<?php
// the arguments
$args = array(
'posts_per_page' => '1',
'orderby' => '',
); ?>
<?php $the_query = new WP_Query($args); ?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<!-- I'm storing the ID so I can exclude it from the rest of the loop, but I know this doens't work right now -->
<?php $postid = get_the_ID(); ?>
<div class="small-12 columns entry" >
<div class="text-center" id="featured-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('featured'); ?>
</a>
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php
$content = get_the_content();
echo wp_trim_words($content, '75');
?>
</p>
</div>
</div>
<!-- End of the nested loop (most recent posts) -->
<?php endwhile; ?>
<?php endif; ?>
<!-- End of the featred post query loop-->
<?php endif; ?>
And here's the main loop:
<?php get_template_part('parts/content', 'featured-post'); ?>
<!-- This ends the logic for the featured post. Now we show the rest of the posts, excluding the first one we showed -->
<?php get_template_part('parts/content', 'category-filter'); ?>
<?php
// the arguments
$args=array(
'paged' => $paged,
'posts_per_page' => 9,
'post__not_in' => array($postid)
); ?>
<?php $the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- Start row that holds blocks -->
<div class="row small-up-1 medium-up-2 large-up-3">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="column entry" >
<?php if( get_the_post_thumbnail() ): ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('blog'); ?>
</a>
<?php else : ?>
<?php endif; ?>
<h5><?php the_title(); ?></h5>
<?php
$excerpt = get_the_excerpt();
echo wp_trim_words( $excerpt , '10', '');
?>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>Sorry, no more posts.</p>
<?php endif; ?>
How exactly do I set up a variable to use in the second loop?

Can someone help me to add a category to this Post?

I'm using this code in different sections of my website and I want to display different posts in each section of the front page according to their category.
Can someone please help em to add a category there one is "surf" , I've tried everything.
Or maybe a different way to do it?
Thank you.
<div class="posts">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$total_post_count = wp_count_posts();
$published_post_count = $total_post_count->publish;
$total_pages = ceil( $published_post_count / $posts_per_page );
if ( "1" < $paged ) : ?>
<div class="page-title section small-padding">
<h4 class="section-inner"><?php printf( __('Page %s of %s', 'radcliffe'), $paged, $wp_query->max_num_pages ); ?></h4>
</div>
<div class="clear"></div>
<?php endif; ?>
<?php while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part( 'content', get_post_format() ); ?>
</div> <!-- /post -->
<?php endwhile; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="archive-nav">
<?php echo get_next_posts_link( '« ' . __('Posts Antigos', 'radcliffe')); ?>
<?php echo get_previous_posts_link( __('Posts Recentes', 'radcliffe') . ' »'); ?>
<div class="clear"></div>
</div> <!-- /post-nav archive-nav -->
<?php endif; ?>
<?php endif; ?>
</div> </div> <!-- /posts -->
If you are trying to display category by ID , Then
global $post;
$args = array( 'category' => '12' );
$cat_post= get_posts( $args );
foreach( $cat_post as $post ) : setup_postdata($post); ?>
<li class="testimonial"><?php the_content(); ?></li><br/>
<?php endforeach; ?>
Note: In $args = array( 'category' => '12' ); 12 is the ID of
the category
But if you want to display category by Name, Then
global $post;
$args = array( 'category_name' => 'uncatogerized' );
$cat_post= get_posts( $args );
foreach( $cat_post as $post ) : setup_postdata($post); ?>
<li class="testimonial"><?php the_content(); ?></li><br/>
<?php endforeach; ?>
Here, uncategorized is a category name

Next button not showing other posts in Wordpress

In my wordpress I have many posts, every page I am showing 5 posts.
Bottom of my page I have next and prev button. When I click one the next button it will go to /page/2/ link but this page title is showing Page not found. And it's not showing other posts in page 2.
My next and prev code :
<div class="prev-next-btn">
<?php next_posts_link( __( 'next', 'themename' ) ); ?>
</div>
<div class="prev-next-btn">
<?php previous_posts_link( __( 'prev', 'themename' ) ); ?>
</div>
My index.php code :
<div class="center-content">
<ul>
<?php query_posts('posts_per_page=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<div class="date">In
<?php
$category = get_the_category();
if(!empty($category))
echo ''.$category[0]->cat_name.'';
?>
- <?php the_time('d M, Y') ?>
</div>
<!--<div class="auther">by <?php the_author(); ?> <span> - <?php comments_number( 'no comments', 'one comment', '% comments' ); ?> Reply</span></div>-->
<div class="title clear-both"><h2><?php the_title(); ?></h2></div>
<div class="details"><p><?php the_excerpt(); ?></p></div>
<div class="readmore">Read more</div>
<br>
</li>
<?php endwhile; ?>
</ul>
</div>
<div class="pagination">
<?php
if(function_exists('wp_pagenavi')) {
wp_pagenavi();
}
else {
?>
<div class="prev-next-btn">
<?php next_posts_link( __( 'next', 'themename' ) ); ?>
</div>
<div class="prev-next-btn">
<?php previous_posts_link( __( 'prev', 'themename' ) ); ?>
</div>
<?php } ?>
</div>
<?php else : ?>
404 Nothing here. Sorry.
<?php endif; ?>
</div>
You do have a few issues here
NEVER EVER use query_posts. It is slow, reruns queries, breaks and fails silently with pagination and worse of all, it breaks the main query object. If you break the main query object, you break page functions. So, please never use query_posts. Mke if it never existed
You have replaced the main query loop with a custom query, which you must not do. If you need to show a different amount of posts on a particular page ( not on page templates and a static front page though as this will not work there ), then use pre_get_posts. You need to go and read how helpful that action is and how to use it
Remove this line
<?php query_posts('posts_per_page=5'); ?>
Then add the following in your functions file
add_action( 'pre_get_posts', function ( $query )
{
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'posts_per_page', 5 );
}
});
<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// the query
$the_query = new WP_Query( 'cat=1&paged=' . $paged );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php
// the loop
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php
// next_posts_link() usage with max_num_pages
next_posts_link( 'Next', $the_query->max_num_pages );
previous_posts_link( 'Previous' );
?>
<?php
// clean up after the query and pagination
wp_reset_postdata();
?>
<?php endif; ?>
Just add below code: I added 'paged' variable and set in next_posts_link() and previous_posts_link()..please see below code:
<div class="center-content">
<ul>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array('posts_per_page'=>5,'paged'=>$paged )); ?>
<?php if (have_posts()) : while (have_posts()) :the_post(); ?>
<li>
<div class="date">In
<?php
$category = get_the_category();
if(!empty($category))
echo ''.$category[0]->cat_name.'';
?>
- <?php the_time('d M, Y') ?>
</div>
<!--<div class="auther">by <?php the_author(); ?> <span> - <?php comments_number( 'no comments', 'one comment', '% comments' ); ?> Reply</span></div>-->
<div class="title clear-both"><h2><?php the_title(); ?></h2></div>
<div class="details"><p><?php the_excerpt(); ?></p></div>
<div class="readmore">Read more</div>
<br>
</li>
<?php endwhile; ?>
</ul>
</div>
<div class="pagination">
<?php
global $wp_query;
if(function_exists('wp_pagenavi')) {
wp_pagenavi();
}
else { echo 'test';
?>
<div class="prev-next-btn">
<?php echo next_posts_link( __( 'next', 'themename' ) , $wp_query->max_num_pages ); ?>
</div>
<div class="prev-next-btn">
<?php echo previous_posts_link( __( 'prev', 'themename' ) , $wp_query->max_num_pages ); ?>
</div>
<?php } ?>
</div>
<?php else : ?>
404 Nothing here. Sorry.
<?php endif; ?>
</div>

WP-pagination and excluding category from page

I'm trying to use WP pagination on post archive page but exclude posts from one category to be shown there.
When I add this to my code the page2,3,4... of the archive display the same first 10 posts:
<?php query_posts('cat=-4');?>
This is the whole code of my page template so I would be grateful for all your help:
<?php
/*
Template Name: Post archive
*/
?>
<?php get_header(); ?>
<div class="container">
<div class="content col-md-9">
<div class="home-content">
<!-- Show posts -->
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'paged'=> $paged,
'posts_per_page'=> 10
);
query_posts($args); ?>
<?php query_posts('cat=-4');?>
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
<div style="float:left; margin:1%;">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail( 'thumbnail', array( 'class' => 'img-post')); // show featured image
}
?>
</div>
<h1 class="post-thumb"><?php the_title(); ?></h1>
<h4>Category: <?php the_category(', '); ?></h4>
<p><?php the_excerpt(); ?></p>
<hr style="margin-bottom:5%">
<?php endwhile; ?>
<!-- pagination -->
<div class="nav-previous alignleft" style="margin-top:-1%"><?php next_posts_link( 'See older posts' ); ?></div>
<div class="nav-next alignright" style="margin-top:-1%"><?php previous_posts_link( 'See newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
</div>
<div class="col-md-3 sidebar unstyled">
<?php dynamic_sidebar( 'home1' ); ?>
</div>
<div class="col-md-3 sidebar unstyled sidebar-space">
<?php dynamic_sidebar( 'home2' ); ?>
</div>
<div class="col-md-3 sidebar unstyled sidebar-space">
<?php dynamic_sidebar( 'articles1' ); ?>
</div>
</div>
</div>
</body>
</html>
<?php get_footer(); ?>
This code fixed my page:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'cat'=> -4,
'paged'=> $paged,
'posts_per_page'=> 10
);
query_posts($args); ?>
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
Modifying to reflect OP's solution for benefit of future readers
Change query() slightly as shown below
$args = array(
'cat'=> -4,
'posts_per_page'=> 10,
'paged'=> $paged
);

Categories