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

How can I create a loop to build slides based on multiple categories using Coda Slider

For those who were interested in an answer to this question, I found the answer myself. <div class=”coda-slider” id=”slideshow”> <?php // array of category IDs $categories = array(1,2,3,4,5); foreach ($categories as $cat) : $post = false; $post = get_posts(‘cat=”.$cat.”&posts_per_page=1’); if($post) : $post = $post[0]; setup_postdata($post); ?> <!– rest of normal loop –> <div <?php post_class(); … 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