pagination within wp_query / wordpress - wordpress

I have written this code for a custom loop in Wordpress, but I cannot seem to get pagination working.
<?php //Template Name: Acapellas ?>
<?php get_header(); ?>
<?php if (is_user_logged_in()) { ?>
<div id="main-content">
<div class="container">
<div class="row">
<div class="col-md-3">
<?php get_sidebar('primary-left'); ?>
</div>
<div class="col-md-9">
<div class="post-<?php the_ID(); ?> post-content">
<h1>Acapellas</h1>
<?php $loop = new WP_Query( array( 'post_type' => 'acapella', 'posts_per_page' => 100 ) ); ?>
<ul class="acapellas row">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li class="post-<?php the_ID(); ?> col-md-6">
<div class="wrap">
<h2><?php the_title() ?></h2>
<?php the_content(); ?>
<span class="download left"><?php get_attachment_icons($echo=true); ?></span>
<span class="list-date right">First added: <?php the_time('F jS, Y') ?></span><br>
<?php
global $post;
$post_type = get_post_type(get_the_ID());
$post_type_taxonomies = get_object_taxonomies($post_type);
if (!empty($post_type_taxonomies)) {
echo '<ul class="details">';
foreach ($post_type_taxonomies as $taxonomy) {
$terms = get_the_term_list(get_the_ID(), $taxonomy, '', '</li><li>', '');
if ($terms) {
echo '<li>' . $terms . '</li>';
}
}
echo '</ul>';
}
?>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php
} else {
wp_redirect( 'http://www.voclr.it/signup' ); exit;
}
?>
<?php get_footer(); ?>

Move your $paged variable outside the loop and include it as a parameter of WP_Query
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query( array(
'post_type' => 'acapella',
'posts_per_page' => 100,
'paged' => $paged,
));

Related

Wordpress CPT pagination returns 404 page

I want to add pagination to my CPT wordpress posts. I've seen some of the solutions, but neither I see no pagination or the pagination does not work.
I've added some pagination code, and it shows the correct number of pages but when I click on page number it returns 404 page. The url is also correct.
Here's my code:
<div class="container">
<div class="row">
<?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; ?>
<?php $args = array( 'post_type' => 'Realizacje', 'posts_per_page' => 6, 'category_name' => array('projekty-wnetrz', 'wykonczenia-pod-klucz'), 'paged' => $paged); ?>
<?php $loop = new WP_Query($args); ?>
<?php $count=0; ?>
<?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
$num = $loop->post_count;
?>
<div class="col-md-4">
<div class="realisation">
<!-- <div class="gallery">
<?php
$images = get_field('galeria');
$size = 'medium';
if( $images ): ?>
<div id="lightgallery<?php echo $count; ?>">
<?php foreach( $images as $image ): ?>
<div class="gal">
<img src="<?php echo $image; ?>"/>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div> -->
<div class="galeria">
<div class="lightg" id="lightgallery<?php echo $count; ?>">
<a href="<?php echo get_the_post_thumbnail_url(); ?>">
<div class="relative-box"><img class="first_image"src="<?php echo get_the_post_thumbnail_url(); ?>"/>
<div class="demo-gallery-poster">
<i class="fa fa-search" aria-hidden="true"></i>
</div></div>
<div class="gallery-title"><h5 class="gallery-t"><?php the_title(); ?></h5></div>
</a>
<?php
$count=$count+1;
$images = get_field('galeria');
$size = 'large';
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<img src="<?php echo $image; ?>"/>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<h5>Brak realizacji</h5>
<?php endif; ?>
<div class="pagination">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $loop->max_num_pages,
'prev_text' => '«',
'next_text' => '»'
) );
?>
</div>
<?php wp_reset_postdata(); ?>
</div>
</div>

Pagination for a list of posts with custom_terms

I have code that gets all posts for a custom term,
I want to apply pagination for that code.
<div> <?php
$text = $_POST['text'];
/* echo ($text); */
$args = array( 'numberposts' => -1 );
$posts = get_posts( $args );
foreach($posts as $post)
{
$custom_terms = get_the_terms($post->ID,'Characters');
foreach($custom_terms as $custom_term)
{
if ( ($custom_term->name) == ($text) )
{
?>
<div class="col-sm-2">
<article class="item">
<div class="article-inner">
<div class="overlay"></div>
<div class="img-wrapper"><img class="img-100p latest-post-image"
src="<?php the_post_thumbnail_url('large'); ?>" alt="img"></div>
<div class="article-info">
<h4 class="entry-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php
//echo $countA ?><?php //echo $count_posts?><?php //echo $count%$st?></a>
</h4>
</div>
</div>
</article>
</div>
<?php
}
}
}
?>
</div>
I'm using plugin
https://wordpress.org/plugins/wck-custom-fields-and-custom-post-types-creator/
to create that custom_terms on backend admin wordpress.
and try to use this code but when go to page number 2 no posts apperas
<div>
<?php
$text = $_POST['text'];
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$count = 0;
$st = 15;
$args = array( 'numberposts' => -1 );
$posts = get_posts( $args );
$stack = array(2005);
$poststatus = array( 'publish' );
$current_category = single_cat_title("", false);
foreach($posts as $post)
{
$custom_terms = get_the_terms($post->ID,'characters');
foreach($custom_terms as $custom_term)
{
if ( (($custom_term->name) == ($text)) )
{
$counter ++ ;
array_push($stack,($post->ID) );
}
}
}
$args1 = array(
'post_type' => 'post',
'post__in' => $stack,
//'category_name' => '',
'post_status' => 'publish',
'posts_per_page' => 18,
//'offset' => 5,
'order_by' => 'date',
'paged' => $paged,
'ignore_sticky_posts' => 5 ,
);
$wp_query = new WP_Query( $args1 );
$count_posts = $wp_query->post_count;
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
$count++;
if ($count%$st == 4) :
$count = 1;
?>
<?php
endif;
?>
<div class="col-sm-4">
<article class="item">
<div class="article-inner">
<div class="overlay"></div>
<div class="img-wrapper"><img class="img-100p latest-post-image"
src="<?php the_post_thumbnail_url('large'); ?>" alt="img"></div>
<div class="article-info">
<h4 class="entry-title">
<?php the_title(); ?>
</h4>
</div>
</div>
</article>
</div><!--col-sm-4-->
<?php
endwhile;
//wp_reset_postdata();
//wp_reset_query();
//wp_reset_postdata();
endif;
?>
#ManoharSingh
This is full template file
<?php
/**
<?php /* Template Name: C1
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* If you'd like to further customize these archive views, you may create a
* new template file for each one. For example, tag.php (Tag archives),
* category.php (Category archives), author.php (Author archives), etc.
*
* #link https://codex.wordpress.org/Template_Hierarchy
*
* #package Primer
* #since 1.0.0
*/
get_header();
$temp = $wp_query;
// $wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=6&post_type=post_type_name'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div>
<?php
$text = $_POST['text'];
/* echo ($text); */
$args = array( 'numberposts' => -1 );
$posts = get_posts( $args );
foreach($posts as $post)
{
$custom_terms = get_the_terms($post->ID,'characters');
foreach($custom_terms as $custom_term)
{
if ( ($custom_term->name) == ($text) )
{
?>
<div class="col-sm-2">
<article class="item">
<div class="article-inner">
<div class="overlay"></div>
<div class="img-wrapper"><img class="img-100p latest-post-image" src="<?php the_post_thumbnail_url('large'); ?>" alt="img"></div>
<div class="article-info">
<h4 class="entry-title">
<?php the_title(); ?><?php //echo $countA ?><?php //echo $count_posts?><?php //echo $count%$st?>
</h4>
</div>
</div>
</article>
</div>
<?php
}
}
}
?>
</div>
<?php endwhile; ?>
<section class="all-pagination">
<div class="container">
<div class="col-md-12">
<div class="col-md-12 in-pagination">
<ul class="pagination">
<?php wp_pagenavi( array( 'query' => $wp_query ) ); ?>
<?php //if (function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' => $wp_query ) ); } ?>
</ul>
</div>
</div>
</div>
</section>
<?php ?>
<?php get_footer(); ?>
Try this code,
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=6&post_type=post_type_name'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<!-- LOOP: Usual Post Template Stuff Here-->
<?php endwhile; ?>
<nav>
<?php previous_posts_link('« Newer') ?>
<?php next_posts_link('Older »') ?>
</nav>
And you can try this plugin for pagination 'https://wordpress.org/plugins/wp-pagenavi/'

Two custom loops on same page in wordpress?

I wasn't able to find anything on here, so I am bringing this question to you. The following code does mainly what I want, only the page-cycle doesn't work: When I want to navigate to older posts, the page that is seen displays the same new posts again. How do I do this properly?
So index.php has two loops:
<?php
$args = array( 'numberposts' => 1,
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
?>
// regular post html with wp tags
<?php endforeach; ?>
<?php
query_posts('posts_per_page=12&offset=1');
if (have_posts()) : ?>
<h3>Headline</h3>
<?php while (have_posts()) : the_post(); ?>
// regular html with wp tags for these posts (teasers, with the_excerpt)
<?php endwhile; ?>
<div class="navigation">
<span class="nextlink"><?php next_posts_link( 'Older', 0 ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nothing found'); ?></h3>
<?php endif; ?>
Here is the explanation: One visits the blog: The most recent blog post is displayed in full length in one block, the 12 older posts (excluding the first one with offset, so 2–13) are displayed in another block with content teasers and a next-previous-navigation at the bottom to display post teasers 14–25 and so on. (The problem: it's always 2–13)
// Edit: Code in response to the top answer, now the full code of the index.php. Notice, that the HTML has changed, since I have used normalized HTML, since it should usually not matter. This times it's the actual code.
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', 0 ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
I am trying out this code now (14.10.17), but it doesn't add functioning page navigation...:
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', 0 ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
New:
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', $the_query->max_num_pages ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You haven't set up paging, so your query always thinks its on page 1.
Also according to the WP Developer Resources , you shouldn't use query_posts- use WP_Query or pre_get_posts instead, so I'm using WP_Query below to do your 2nd query.
Note that I've assumed you are using this on a static homepage, but I've added the change required for a custom page in comments.
<?php
$args = array( 'numberposts' => 1,
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
?>
// regular post html with wp tags
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
<?php
/* Set up your pagination - $paged will contain the current page, telling WP_Query which post to start with (e.g. #13 on page 2) */
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
/* NOTE: if this is NOT on a static page
get the 'paged' query var instead of 'page', i.e.:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
*/
$display_count = 12; /* variable for the number of posts per page */
$excluded_count = 1; /* the number of posts excluded from the start position */
/* Calculate the offset, i.e. the post number to start the page with
Normally this is calculated by: ($paged-1) * $display_count
so we just need to add 1 for the one we excluded */
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
/* set up your new query passing in the page so WP_Query knows what to return */
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
/* set up your new query */
$the_query = new WP_Query( $args );
<?php if ( $the_query->have_posts() ) : ?>
<h3>Headline</h3>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
// regular html with wp tags for these posts (teasers, with the_excerpt)
<?php endwhile; ?>
<div class="navigation">
<span class="nextlink"><?php next_posts_link( 'Older', $the_query->max_num_pages ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nothing found'); ?></h3>
<?php endif; ?>
The above code is untested, but the basic logic should be right.
UPDATE:
next_posts_link and
previous_posts_link use the global variable $wp_query by default, so to make is use your custom query, pass $custom_query->max_num_pages into next_posts_link, e.g.:
<span class="nextlink"><?php next_posts_link( 'Older', $the_query->max_num_pages ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>

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();?>

pagination issue wordpress on static front page

hi have a problem where i can't get pagination to work on a static front page, looked at wordpress codex and done what it says built but still no joy,
any help greatly appreciated
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$type = 'Galleries';
$args=array(
'category_name' => 'Gallery',
'post_status' => 'publish',
'posts_per_page' => 2,
'paged' => $paged
);
$my_query = null;
$my_query = new WP_Query($args);
?>
<section id="maincontent" class="twelve columns">
<ul id="gallery_menu">
<?php if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li class="gallery_titleframe">
<div class="gallery_titleborder">
<div class="gallery_titleimage">
<?php $str = get_the_ID() ; ?>
<a href="<?php the_permalink() ?>" title="<?php echo get_post_meta($str, 'gallery1', true); ?>">
<img src="<?php echo get_post_meta($str, 'gallery1', true); ?>" width="256" height="186">
</a>
</div>
</div>
<div class="gallery_titletext">
<?php the_title(); ?>
</div>
</li>
<?php endwhile;
} ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(); ?></div>
<div class="nav-next"><?php previous_posts_link(); ?></div>
</div><!-- #nav-below -->
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
next_posts_link and previous_posts_link depend on the global $wp_query. You could temporarily assign your custom query to the global before calling them.
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = $my_query;
?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(); ?></div>
<div class="nav-next"><?php previous_posts_link(); ?></div>
</div><!-- #nav-below -->
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
Replace this
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
with this
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}

Resources