How can I access specific posts brought back by query_posts?

Why not just use a counter and then conditional logic? $i = 0; while($loop->have_posts()) : $loop->the_post(); if($i === 0){ echo ‘<div class=”a”>’.other_stuff().'</div>’; } elseif($i === 1){ echo ‘<div class=”b”>’.other_stuff().'</div>’; } else { echo ‘<div class=”default”>’.other_stuff().'</div>’; } $i++; endwhile;

Loop don’t work within single.php page

To give you a more thorough answer I would have to see some actual code, but I think the gist of the answer is in the file you are trying to use. “single.php” is the template file used to display the content of a single post, as the name implies. It isn’t meant for displaying … Read more

How to modify search.php to not show pages only show posts

The search template is way too late to change anything: The pages are searched already here, and your page numbers would be wrong. Do not alter the output, alter the query. Filter posts_search instead, and if there is a search term, filter posts_where_paged and remove the post type you don’t want to be searched. Sample … Read more

First article : single column; Other articles : 2 columns

Test and let me know: Put the following code into your index.php (or front-page.php): <?php if( have_posts() ) : ?> <div class=”col-full”> <?php for( $news = 0; $news < 1; $news++ ) { ?> <?php the_post(); ?> <h3 class=”news-title”><?php the_title(); ?></h3> <div class=”news-excerpt”><?php the_excerpt(); ?></div> <?php } ?> </div> <div class=”place-for-ad”></div> <?php // Start Two … Read more

2nd page displaying the exact same posts as my first page (minus the very first post)

Solution 1 It looks like this might be what is happening to your template: http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query Basically what it’s saying is that the second page doesn’t realize it’s the second page because the “paged” parameter is missing. I’ve just copied directly from the wordpress documentation, which says you should do this: <?php $paged = (get_query_var(‘paged’)) ? … Read more

Exclude taxonomy term from all loops, but having it on widget

Looks like you’ve excluded a taxonomy term, not the whole taxonomy. Is that what you intended? But on to the answer… Right before your query in the widget add: remove_action( ‘pre_get_posts’, ‘exclude_category_posts’ ); And then you probably want to put it back again after that query by repeating: add_action( ‘pre_get_posts’, ‘exclude_category_posts’ ); That is a … Read more

3 random images from custom post type, each in a div with a diffrent class

Getting different classes in the divs is relatively simple and mostly not a WordPress question, but there are WordPress bits to it that need comment. Truncated code reformatted for legibility: $classes = array( ‘side left’, ‘middle’, ‘side right’ ); $qry = new WP_Query( array( ‘post_type’=> ‘portfolio’, ‘posts_per_page’ => 3, ‘orderby’ => ‘rand’, ‘order’ => ‘ASC’ … Read more

Loop Problem: Displays same set of post for all categories

You are passing the same arguments to retrieve every set of posts. You have alter the arguments dynamically to reflect the current category. $categories = get_categories($catArgs); if($categories){ foreach($categories as $category) { $postArgs[‘cat’] = $category->cat_ID; $my_query = new WP_Query($postArgs); // … Untested, and I am away from my dev server but that should be pretty close. … Read more