post thumbnail, conditions, else wont work

Thanks everyone for all the help! I really appreciate it. I was able to make it work by removing [0] in $imgsrc = $img[0]; and using custom_get_meta() like: $img = post_movie_get_meta(‘featured_img’) and: $img = post_movie_get_meta(‘backdrop_img’)

WordPress Loop if/else

https://codex.wordpress.org/Class_Reference/WP_Query#Properties found_posts is the total number of posts returned by the query. example code: <?php $args = array( ‘post_type’ => ‘your_custom’ ); $custom_query = new WP_Query( $args ); if( $custom_query->have_posts() ) { $number_of_posts = $custom_query->found_posts; while( $custom_query->have_posts() ) { $custom_query->the_post(); if( $number_of_posts == 1 ) { the_content(); } else { the_excerpt(); } } wp_reset_postdata(); } … Read more

How to setup a query to output posts by groups of five?

you can create a simple counter and condition: <?php $count = 0; ?> <?php if( $query->have_posts() ) : ?> <ul class=”posts”> <?php while ( $query->have_posts() ) : $query->the_post(); if ($count < 5){ ?> <li> <?php the_title(); ?> </li> <?php }else{ echo ‘</ul><ul class=”posts”>’; ?> <li> <?php the_title(); ?> </li> <?php $count = 0; } $count … Read more

Does WP have a global of $id?

If you are using netbeans and xdebug, or have set up your debugging environment correctly then you can observe the variables, objects e.t.c as they change. To see when they are created and what is contained within objects such as wp_query or wp_rewrite your posts->ID is set once the function wp() is called in wp-blog-header.php. … Read more

single.php – how to mark current page in the loop

Here’s a rewritten version of your code <ul id=”questions” class=”subpage”> <?php $current_id = get_the_ID(); $index_query = new WP_Query( array( ‘post_type’ => ‘faq’, ‘orderby’ => ‘modified’, ‘posts_per_page’ => ‘-1’, ‘order’ => ‘DESC’ ) ); while ( $index_query->have_posts() ) : $index_query->the_post(); if(get_the_ID() == $current_id) echo ‘this post has the same ID as the current global one’; ?> … Read more

Targeting custom post type

You can make use of get_post_type( $post ) to check whether a post belongs to a certain post type Inside your loop, you can do the following check while ($my_query->have_posts()) : $my_query->the_post(); if ( ‘activists’ == get_post_type() ) { /* Custom code for ‘activists’ post type. */ } else { /* Custom code for the … Read more