Tag Info

Hot answers tagged

3

You're 95% of the way there already. Just add if ( $my_query->have_posts() ) and incorporate your $odd variable: <?php $my_query = new WP_Query('offset=5&showposts=10'); if ( $my_query->have_posts() ) : $odd = false; while ($my_query->have_posts()) : $my_query->the_post(); $odd = !$odd; ?> <div ...


3

Case #1: Simple Offset You want to 'offset' posts of a category archive by 'n', i.e. you simply don't want to show the first/latest 'n' posts in an archive. That is, (considering the posts_per_page setting in WP Dashboard > Settings > Reading is set to 10) you want posts 11 to 20 to be shown on the first page (e.g. example.com/category/tech/), 21 to 30 on ...


2

get_term_by returns an object, try passing $term->slug to your query instead.


2

t31os says: [See edit history for previous code and comments] Using Ajax to paginate your queries I've put together some code that will fetch your posts and comments via ajax using simple prev/next navigation via ajax. 1) Replace all the code you posted in your author.php with the following.. <?php $cat_settings = array( 'Articles' => 7, 'Journals' ...


2

No need to have two queries, you can just reuse the same post data by resetting the current post position and running the loop again: $wp_query->current_post = 2; you'd have to do this twice to achieve what you're asking, and stop it the second time at the third post.


2

posts_per_page => -1 is equivalent to 'nopaging' => true, which basically means no LIMIT clause is used at all. The workaround is to set posts_per_page to a large number. This is a limitation of the LIMIT syntax itself: http://dev.mysql.com/doc/refman/5.0/en/select.html


2

doing 3 separate queries is unnecessary and inefficient, do one query for all 12 posts and output your container markup every fourth post. $args = array( 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page'=> 12 ); $my_query = new WP_Query( $args ); if( $my_query->have_posts() ): ?> <div ...


2

This will most likely require two loops to the best of my knowledge. The second loop just needs to know to exclude the post you just queried. Something like the following should do the trick. $first_id = 5; // This should be set in the previous loop to the post ID of the post returned by your first query. $args2 = array( 'post_type' => 'portfolio', ...


1

Fetch all five posts in one query, store the result in a variable and take one each time you want to show an advertisement. Now you cannot get duplicates, and more important: you save four queries.


1

Because of query mechanics either $paged or $offset is used, but not both at the same time. Basically if you want custom offset then it is assumed that you do not want pagination. You would probably need to hook into post_limits and change generated LIMIT SQL to adjust offset, unless there is an easier way that I am missing.


1

It's a php error probably because its expecting either one of your if statements to be closed before the endwhile. It's hard to tell without seeing all the code but at a guess check this one is closed: if ($tags) { also I would wrap your foreach in curly brackets. Maybe just preference though... foreach($tags as $individual_tag){ $tag_ids[] = ...


1

Do you mean you want to display three blocks of four related posts, and flip between the three blocks using scrollable? If so, does the below help (not tested)? Assuming scrollable needs its content in separate divs, you could do something like this. It should produce a containing div with up to three divs inside, each containing 4 posts... assuming you ...


1

try: if(!is_paged()) { $post_offset = $blogpost_count; } else { $post_offset = (get_query_var('paged')-1)*2+$blogpost_count; } ... ... 'offset' => $post_offset;


1

Is WP set to that -6 offset you need? In that case try date_i18n() to generate your date instead of date().


1

Here's your code wrapped up in a plugin. The important thing is that it prepare()s the input, so the query is safe. You can define 2 arguments: Offset & Limit. Those are basically just the SQL LIMIT. If you don't have any use for the plugin, just deactivate it, as it won't do anything - its output is attached to a filter … $most_commented = ...


1

I don't think that you can get an offset of the page outside of the loop, since it will be out of the context. Offset may vary depending on the arguments you are using to get posts for the loop. Easiest solution will be to calculate offset in the app. You will need to pass post_id as an attribute and then loop through all the posts obtained by ...


1

The "offset" depends on the query-- sort order, conditions like category or tag, meta queries, etc.--, and it changes every time a post is added to the blog. It isn't something you "get" so much as something you calculate. On a "single post" page the query is pretty straightforward and returns a single post-- that is, 0 offset. Assuming what you want is ...


1

Neither of those are complete loops. That is, in both you have the start of an if but not the end of it, and the start of a while loop, but no the end of it. Also, you shouldn't be using query_posts either, as it over writes the main query and is rarely the right function for pulling posts. get_posts would be better. I would do this, using one as an ...


1

Yep - it is pretty inefficient. Here is a rewrite: <div id="engagement"> <?php $images = new WP_Query( array( 'post_parent' => get_the_ID(), 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', ...


1

You are going about this the hard way, and the less efficient way. You already have a Loop on the page. You should be able to use that and that alone. if (have_posts()) { while (have_posts()) { the_post(); if (6 < $wp_query->current_post) { // formatting for your first six posts } else { // formatting for the other posts ...


1

Reason of this behavior is pretty simple. First of all you have to know that get_posts uses WP_Query to get posts. So let's look at WP_Query implementation. On line 1998 of query.php you can find: if ( $q['posts_per_page'] == -1 ) { $q['nopaging'] = true; Then on line 2544 of query.php you find: if ( empty($q['nopaging']) && ...



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