Modify this loop to fit my jQuery slider (slides)

Tried very simple math. <div class=”slide”> will print after every 4 post. So, if statement with old school logic $i%4 == 0 <div class=”slides_container”> <?php $args = array( ‘post_type’ => ‘fastighet’, ‘numberposts’ => -1, ‘orderby’ => ‘ASC’ ); $posts = get_posts($args); ?> <?php $i = 0; foreach($posts as $post): ?> <?php if($i%4 == 0): ?> … Read more

WordPress Loop – Style rows of posts differently

It’s basically only some math, but you can use $wp_query properties perfectly for that case: Increment global $wp_query; if ( have_posts() ) { while ( have_posts() ) { the_post(); printf( ‘<div %s>%s</div>’, get_post_class( “style-{$wp_query->current_post}” ), // OR: // get_post_class( “style-“.++$wp_query->wpse66475_increment_posts ) ); } } // endif; So the 1st time, your style-n would increment by … Read more

Why execute the_post()?

It is necessary to execute that function if you want to use the template functions such as the_title() & the_permalink(). You should not use it if you aren’t using those kind of functions but for the themes it’s generally recommended to use these functions since they automatically ensure that all wordpress filters are being applied. … Read more

How to retrieve an image from a post and display it before excerpt of a post? [duplicate]

if it is the “Featured Image” of your post, you can use: <?php // check if the post has a Post Thumbnail assigned to it. if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?> check: the_post_thumbnail function else if you want to get the first image inside your post, you can use somthing like that: function … Read more

‘category__and’ for custom taxonomy?

I think this question can cause a misunderstanding. You say: I want to retrieve all the posts that have custom taxonomies ‘taxonomy-1’ and ‘taxonomy-2’ but do you want post that have both taxonomy-1 and taxonomy-2 and taxonomy-3 is irrilevant? $args = array( ‘post_type’ => ‘post-type-x’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘taxonomy-1’, … Read more