wp_list_categories: get latest featured_image of category

You can use a custom Walker, the easiest of which in your case is the Walker_Category and extend it like so: class CategoryThumbnail_Walker extends Walker_Category { // A new element has been stumbled upon and has ended function end_el( &$output, $category, $depth, $args ) { // Output the standard link ending parent::end_el( &$output, $category, $depth, … Read more

Return vs Echo Shortcode

Just define a variable, and concat all html as string and return it. <?php function services_shortcode( $atts ) { // Attributes extract( shortcode_atts( array( ‘slug’ => ”, ), $atts ) ); $html=””; if ( isset( $slug ) ) { $args = array( ‘post_type’ => ‘cbd_services’, ‘name’ => $slug ); // -1 Shows ALL Posts $loop … Read more

Style every four posts differently [duplicate]

Standard Loop: <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( ‘content’, get_post_format() ); ?> <?php endwhile; ?> Loop checking for 4th post: <?php $i = 0; while ( have_posts() ) : the_post(); $i++; ?> <?php if(!$i%4): get_template_part( ‘content’, get_post_format() . ‘-4th’ ); ?> <?php else: get_template_part( ‘content’, get_post_format() ); endif; ?> <?php endwhile; … Read more

Sort posts by custom taxonomy name

One solution would be- $terms = get_terms(‘taxonomy-name’); foreach($terms as $term) { $posts = get_posts(array( ‘post_type’ => ‘custom_post_type_name’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘taxonomy-name’, ‘field’ => ‘slug’, ‘terms’ => $term->slug ) ), ‘numberposts’ => -1 )); foreach($posts as $post) { // do what you want to do with the posts here } }

Insert/sticky specific post into Loop at specific location

This took a bit of trial and error but I think I got it. I was getting an infinite loop until I added suppress_filters. After that it was short work. function insert_post_wpse_96347($posts) { global $wp_query; $desired_post = 151; if (is_main_query() && is_home() && 0 == get_query_var(‘paged’)) { $p2insert = new WP_Query(array(‘p’=>$desired_post,’suppress_filters’=>true)); $insert_at = 3; if … Read more

Guidance with The Loop for CMS

Strictly, you don’t need to use a loop in a page template, but it doesn’t hurt, the content of the page will still load, the loop will simply only run once as there is only one post/page. Many themes include a loop in page templates, I guess for some compability issue. If you are building … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)