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

Split wordpress loop to multiple layouts

Just create 2 queries using the “offset” parameter and separate them by: <?php wp_reset_query(); ?> Display posts from the 4th one (offset is starting from 0): <?php $query = new WP_Query( ‘offset=3′ ) ); ?> EDIT: Here’s some sample code: <?php query_posts(‘offset=0&showposts=2&order=ASC’); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <p><a href=”https://wordpress.stackexchange.com/questions/61605/<?php the_permalink(); ?>”><?php the_title(); … Read more

ACF custom field in [closed]

In the header.php template, you cannot access the $post variable. So you will have to map it using $wp_query, as mentioned on ACF forum here. Try this: <?php global $wp_query; $post = $wp_query->post; $background = get_field(‘background’, $post->ID); ?> <style> .site-header { background: url(<?php echo $background; ?>) no-repeat center; background-size: cover; } </style>

How do I display an image before the first post of the loop when I’m using get_template_part?

The variable $count is accessible in the scope of the current function only. So whatever happens inside get_template_part() cannot know that variable. You could use a global variable, which is accessible everywhere as $GLOBALS[‘count’]. But then you risk collisions with plugins and maybe other code. I recommend a helper function for the functions.php: /** * … Read more

Display post list with different styles

You can just set a variable to count the loop iterations, and then apply different styles or output depending on the value. For example: $post_index = 1; /* Start the Loop */ while ( have_posts() ) : the_post(); $post_class = ($post_index > 3 ? ‘style-a col-sm-12’ : ‘style-b col-sm-6’); echo ‘<div class=”‘ . $post_class . … Read more

Latest Post Styled Different Than other Posts

Since you’re using the default loop (not a custom one), you can check the counter for the first (0th) loop and alter your output just for that one. The WordPress support forum had a similar question that offered this bit of code: if( $wp_query->current_post == 0 && !is_paged() ) { /*first post*/ } You can … Read more

Using Javascript for Looped Content

This may help <?php $staff = new WP_Query(array( ‘posts_per_page’ => -1, ‘post_type’ => ‘staff_bios’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ )); while($staff->have_posts()){ $staff->the_post(); ?> //Below is what should display for each post. <div class=”staff-thumb” onclick=”staffDetails(<?php the_ID(); ?>)”> //Thumbnail details here </div> //Below is the pop up container (hidden until called). <div id=”<?php the_ID()?>” class=”popup-wrap”> <div … Read more

Basic multiple loops only displaying first loop

add the loop code to the query_posts section; example: <div id=”blog-list”> <?php query_posts( array( ‘posts_per_page’ => 8, ‘paged’ => ( get_query_var(‘paged’) ? get_query_var(‘paged’) : 1 ), )); if( have_posts() ) : while( have_posts() ) : the_post(); ?> <div class=”post” id=”post-<?php the_ID(); ?>”> <div class=”description”> <h3><?php the_title_attribute(); ?></h3> <p><?php the_content_rss(”, TRUE, ”, 20); ?></p> </div> </div> … Read more