Display post thumbnail for specific category outside the loop

Use get_the_post_thumbnail with a new WP_Query. <?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘large’); echo ‘<a href=”‘ . $large_image_url[0] . ‘” title=”‘ . the_title_attribute(‘echo=0’) . ‘” >’; echo get_the_post_thumbnail($post->ID, ‘thumbnail’, array(‘class’ => ‘aligncentre’)); echo ‘</a>’; } ?>

Video post format, extra content breaks video embed

If you don’t know what the content is, use a regular expression to test if there is an URL. Sample code: $content = get_the_content(); $pattern = ‘~([^”\’])?(https?://.*\.(flv|aac|mp4|mov|m4a|f4a|ogg|oga|mp3))([^”\’\?])?~i’; if ( preg_match( $pattern, $content, $matches ) ) { $parsedUrl = parse_url( $matches[ 0 ] ); // create the vidoe markup } else { // echo $content or … Read more

How to fetch posts that are stored in the different table than (default) wp_posts?

Don’t hack the Core. There are filters in WP_Query that should more than suffice to include your table, if your SQL and regex are good enough. posts_distinct – Alters SQL ‘DISTINCTROW’ clause to the query that returns the post array. posts_groupby – Alters SQL ‘GROUP BY’ clause of the query that returns the post array. … Read more

first excerpt fine, subsequent post excerpts shift to the right instead of displaying vertically [closed]

I can’t add comments yet, but do you get what Milo is saying? Just look at this section and it is as if there are no closing or tags for the classes post and post-preview. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class=”post-image”> <?php if ( has_post_thumbnail() ) … Read more

How to filter posts by category INSIDE the loop

Got a quite radical solution : function wpse_102497_modify_query_order( $query ) { if ( $query->is_main_query() ) { $query->set( ‘orderby’, ‘title’ ); } } add_action( ‘pre_get_posts’, ‘wpse_102497_modify_query_order’ ); Hope this will help.

Limit Loop to One Category

There is no category argument for query_posts, a category ID should be passed via cat. However, if this is an additional query, please use WP_Query rather than query_posts. If this is the main query, please see pre_get_posts to alter the main query parameters. For more info please see When to use WP_query(), query_posts() and pre_get_posts.

WP_Query loop doen’t work with my custom taxonomy

Your taxonomy and term arguments are incorrect. The preferred method is via tax_query $args = array( // … other args ‘tax_query’ => array( array( ‘taxonomy’ => $term->taxonomy, ‘field’ => ‘slug’, ‘terms’ => $term->name ) ) ); Please see WP_Query for all valid arguments and their correct formatting.

Search page loop banner image issue

You have the header inside the Loop, so of course it prints once for each result. Put that outside the Loop proper. if (have_posts()) { ?> <img src=”https://wordpress.stackexchange.com/questions/102754/banner.jpg” /><?php while ( have_posts() ) { the_post(); // print contents } } Also, don’t use relative URLs in WordPress. You are in for all kinds of headache … Read more