Hook into the loop via a plugin, and output something after every X post?

You can try the following: Method 1: We can inject the ads via the the_post action, in the main loop: add_action( ‘loop_start’, ‘wpse_141253_loop_start’ ); function wpse_141253_loop_start( $query ) { if( $query->is_main_query() ) { add_action( ‘the_post’, ‘wpse_141253_the_post’ ); add_action( ‘loop_end’, ‘wpse_141253_loop_end’ ); } } function wpse_141253_the_post() { static $nr = 0; if( 0 === ++$nr % … Read more

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

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

Changing behavior of the loop twice in one page

Create a new WP_Query for the slider posts. <div class=”featured-rotator”> <?php $slide_query = new WP_Query( ‘category_name=featured’ ); if ( $slide_query->have_posts() ): ?><ul> <?php while ( $slide_query->have_posts() ) : $slide_query->the_post(); ?> <li class=”post”> <div class=”image”><?php the_post_thumbnail(); ?></div> <h2><a href=”https://wordpress.stackexchange.com/questions/145555/<?php esc_url( the_permalink() ); ?>” title=”Permalink to <?php the_title(); ?>” rel=”bookmark”><?php the_title(); ?></a></h2> <?php if (get_post_meta($post->ID, “Author”, true)): … Read more

Add Incrementing ID to each paragraph in the_content

If I understand your question correctly, you can try the following: add_filter( ‘the_content’, ‘incrementparagraphs’, 10, 1 ); function incrementparagraphs( $content ) { return preg_replace_callback( ‘|<p>|’, function ( $matches ) { static $i = 0; return sprintf( ‘<p data-section-id=”%d”>’, $i++ ); }, $content ); } to replace every <p> tags with <p data-section-id=”1″>, where the data-section-id … Read more

WordPress category & taxonomy loop with pagination

Don’t use ‘numberposts’=>-1 because numberposts is depracated moreover -1 shows all the post on one page. Instead use posts_per_page and set its value according to how many posts do you want. $paged= (get_query_var(‘paged’ )) ? get_query_var(‘paged’):1; global $query_string; $myquery = wp_parse_args($query_string); $myquery = array( ‘paged’ => $paged, ‘posts_per_page’=>10, ‘tax_query’ => array( ‘relation’ => ‘OR’, array( … Read more

Apply styling only to first page sticky posts

Strange that stickies aren’t completely unset from the main loop on paged pages but only on the first page. If we look at the source, we will see that stickies are only unset from the main loop if they are on the first page. So we have two options here depending on what you exactly … Read more

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