Tag Info

Hot answers tagged

8

// get current page we are on. If not set we can assume we are on page 1. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // are we on page one? if(1 == $paged) { //true }


7

The solution is to not alter the main query in the template. The default query happens before the template is loaded, so querying in the template overwrites that original query, which is a waste of resources. See the example in codex under pre_get_posts for the correct way to alter the default query without pagination issues.


6

should it be.. $paged = (get_query_var('page')) ? get_query_var('page') : 1; WP_Query in codex: Pagination Note: You should set get_query_var( 'page' ); if you want your query to work with pagination. Since Wordpress 3.0.2, you do get_query_var( 'page' ) instead of get_query_var( 'paged' ). The pagination parameter 'paged' for WP_Query() remains the ...


5

if you only want to know that you are on the first page of a paginated page, try: if( !is_paged() ) { //first page of pagination } http://codex.wordpress.org/Function_Reference/is_paged


5

twentyeleven_content_nav() uses the main query object, $wp_query. You'll need to use the $wp_query variable, rather than $unfiltered_query, then wp_reset_query() to restore the original $wp_query (which it'll find in $wp_the_query, something you should probably avoid touching directly). As long as you're careful to restore the original query, you're in good ...


4

For multi-page posts: The $page global variable returns the current page of a multi-page post. The $numpages global variable returns the total number of pages in a multi-page post. For paginated archive index pages: The $paged global variable returns the current page number of a paginated archive index. To use any of these variables, simply globalize ...


4

Here you go: <?php if ( is_paged() ) echo 'some text'; See http://codex.wordpress.org/Conditional_Tags#A_Paged_Page


4

You shouldn't need to do any special queries for this. Here is one way to accomplish it /** * conditional check ensures special class only shows on top post on first page. * if you want top post on page 2, etc. to have special class, just set $first_post to true */ if( (int) get_query_var( 'paged' ) > 1 ){ $first_post = false; } else { ...


3

I was looking for a simple way to determine whether or not to use the posts_nav_link() function and all solutions I found online were either too complex or unreliable. For example, many people suggested using the $paged global variable, but I found that this variable returned the same value for the first page, even when the first page was the only page! So, ...


3

The same, with built-in function: <?php if ( ! get_query_var('paged')) : ?> { your code here } <?php endif; ?>


2

the argument for WP_Query is paged, but the query var is page, no 'd' on the end. 'paged' => get_query_var( 'paged' ) should be: 'paged' => get_query_var( 'page' )


2

Not sure if you can use a complete different template but you can use different template parts using the global $page variable. Example: global $page; if ( $page == 2 ) { get_template_part( 'page', 'two' ); } else { get_template_part( 'page', 'default'); } This would load the template file page-two.php or page-default.php depending on ...


2

Isn't it so that you have exactly 10 posts and you're showing them all on first page. $found_posts - The total number of posts found matching the current query parameters found_posts on your first page shows 10. All of these posts are shown on first page. So there are no posts to show on second page - therefore it's empty.


2

You set offset param, so paged param is ignored ;) From Codex: offset (int) - number of post to displace or pass over. Warning: Setting the offset parameter overrides/ignores the paged If you want to ignore most recent post in this query, you can achieve it in two ways. 1. Custom pagination. $ppp = get_option('posts_per_page'); // or any other ...


2

Also from codex.wordpress.com/Pagination (Under "Advanced Troubleshooting Steps" > "Removing query_posts from the main loop") regarding modifying the main query via the pre_get_posts action mentioned by Milo: [...] add the query for your home and category pages back in your theme's functions.php file: function my_post_queries( $query ) { // do not ...


2

So, all query conditionals (is_paged, is_singular, etc) look something like this: function is_paged() { global $wp_query; if ( ! isset( $wp_query ) ) { _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' ); return false; } return ...


2

you could change the one line to: $first_post = ( !is_paged() ) ? $posts[0]->ID : ''; or use a different approach: if ($wp_query->current_post == 0 && !is_paged() ) { echo '<div class="post top-post-special" id="post-' . get_the_ID() . '">'; } else { echo '<div class="post" id="post-' . get_the_ID() . '">'; }


2

Use a pre_get_posts action in your functions.php with conditional tags, and remove the call to query_posts: function wpa62751_pre_get_posts( $query ) { if ( is_category( 'my-category' ) && is_main_query() ) $query->set( 'posts_per_page', 4 ); } add_action( 'pre_get_posts', 'wpa62751_pre_get_posts' );


2

$wp_query->current_post holds information about current post in loop, not global set of posts. Numering posts across multiple pages is not available natively (as far as I know) and probably would be to unreliable (for example what if number of posts per page changes is customized to be uneven?). For specific implementation building custom numbering, ...


2

Because you are using <?php $query = new WP_Query ( $args ); ?> the wp_query global isn't changed (used by next_posts_link). So you can change the new WP_Query call to just query_posts( $args ); (and change your loop without the $query->). Or you can overwrite the <?php global wp_query; $wp_query = new WP_Query ( ); $wp_query->query($args); ...


2

You don't need the type variable and other bits of custom search query code, or custom functions like the other answers. In your searchbox, instead of submitting the form to / submit it to /my_post_type/ instead! WordPress will handle all the rest for you automagically, with no effort involved. What's more this means all the usual functions will work just ...


1

Ok, so I got it working more or less correctly, although there is still a small problem left, please read on.. Here is what I've got: in fucntions.php: Rewrite rules add_action('init', 'my_rewrite_add_rewrites'); function my_rewrite_add_rewrites(){ add_rewrite_rule( '^services/([^/]+)/?$', ...


1

No. Query conditionals are part of WordPress' object cache, and incur no additional resources when called.


1

There are several ways of doing this. You could, for instance, incorporate a counter into your loop and treat the post data with respect to the counter's value. YOUR QUERY HERE $my_counter = 0; while ( have_posts() ) : the_post(); $my_counter++; if ( $my_counter <= 4 ) { SLIDER ACTION } else { REGULAR POST ACTION } endwhile;


1

If anyone comes across this issue, you can add this to your functions.php code add_filter('redirect_canonical','pif_disable_redirect_canonical'); function pif_disable_redirect_canonical($redirect_url) { if (is_singular()) $redirect_url = false; return $redirect_url; } Source


1

A couple of points you should try out: Remove the 'paged' => $loop->query_vars['paged'] from your $pagination array. It's not a parameter in the docs. Remove the 'base' => @add_query_arg('paged','%#%') from your $pagination array. I believe WordPress catches the paged parameter using the default page parameter. Which is it's default. Here are ...


1

I had this exact problem. I just stumbled upon the solution! In case this helps you, in both my initial queries before the array merge I changed the posts_per_page to be -1 like 'posts_per_page' => -1 instead of 10. When I did this, the pagination links suddenly appeared and worked fine. I then added 'posts_per_page' => 10 to my final query after the ...


1

I once calculated these variables for the Kohana Pagination library. If you replace the variables with your own you should be all set. $current_first_item = (int) min((($current_page - 1) * $items_per_page) + 1, $total_items); $current_last_item = (int) min($current_first_item + $items_per_page - 1, $total_items);


1

You are doing a few different things wrong-- or at least convoluted and suspect-- in that code and I am sure that that is resulting in your query results getting out of sync with the pagination. You've got a couple of queries in there, including one made by query_posts which you should really never be using at all, plus some filters. Honestly, I didn't crawl ...


1

First, let's go through variables one by one: $numpages is set on each setup_postdata() call. It becomes either 1 or number of pages in multipage post. $max_page doesn't seem to be global at all. I don't see it referenced as such in code and from quick test it is not getting set on archive page for me. $multipage indicates if current post has multiple ...



Only top voted, non community-wiki answers of a minimum length are eligible