CPT and ACF Repeater not working together - php

Here's the page template code I'm working with, defined into sections...
<?php
//* Template Name: Partnerships Archive
?>
<!-- Header =========================================== -->
<?php get_header(); ?>
<!-- Homepage Header Video =========================================== -->
<div class="subpage-video-sca">
<!-- VIDEO -->
<div class="subpage-desktop-vid-sca">
<video title="<?php the_field('seo_video_title'); ?>" autoplay loop muted playsinline>
<source src="<?php the_field('vimeo_link'); ?>" type="video/mp4">
</video>
</div>
<!-- GRAD-OVERLAY -->
<div class="subpage-overlay-image-sca">
</div>
<!-- OVERLAID TEXT -->
<div class="subpage-text-over-video-sca">
<div>
<h1><?php the_field('sub_page_title'); ?></h1>
<p><?php the_field('paragraph'); ?></p>
</div>
</div>
</div>
<!-- Breadcrumbs =========================================== -->
<?php echo do_shortcode("[breadcrumbs]"); ?>
<!-- Main Content =========================================== -->
<div class="wrap">
<?php
$args = array(
'post_type' => 'partnerships',
'orderby' => 'title',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a class="one-third partnership-block" href="<?php the_permalink(); ?>">
<img src="<?php the_field('logo'); ?>" alt="<?php the_title();?> graphic">
</a>
<?php $products_count = $the_query->current_post + 1; ?>
<?php if ( $products_count % 4 == 0): ?>
</div><div class="row">
<?php endif; ?>
<?php endwhile; endif; ?>
</div>
<!-- Testimonials =========================================== -->
<div class="wrap">
<div class="page-section-headers pt-testimonials-container txt-right">
<h1>WHAT <span class="red">OUR PARTNERS</span><br>HAVE TO SAY</h1>
</div>
<?php if( have_rows('testimonial') ): ?>
<div class="testimonial-slider-container slick-slider">
<?php while( have_rows('testimonial') ): the_row();
// vars
$text = get_sub_field('testimonial_text');
$client = get_sub_field('client_name');
$company = get_sub_field('client_company');
?>
<div class="testimonial-slider-single">
<p><?php echo $text; ?></p>
<h2><?php echo $client; ?></h2>
<h3><?php echo $company; ?><h3>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
The code in the main content area is pulling through custom post types I have.
The code in the Testimonials area is pulling through data from an ACF Repeater field for this page specifically.
They both work independently but when I have them both on the page at the same time, the testimonials doesn't pull through.
That said, Ive just noticed that when I put the testimonials first and the main content after, they both work!!
Can anyone help? Is there something I haven't closed properly in the Main content or something? I don't get it...
It's wordpress, using Genesis Framework, latest versions of both. The page is here: http://staging.seedcreativeacademy.co.uk/partnerships/

add wp_reset_postdata(),after while :
<div class="wrap">
<?php
$args = array(
'post_type' => 'partnerships',
'orderby' => 'title',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a class="one-third partnership-block" href="<?php the_permalink(); ?>">
<img src="<?php the_field('logo'); ?>" alt="<?php the_title();?> graphic">
</a>
<?php $products_count = $the_query->current_post + 1; ?>
<?php if ( $products_count % 4 == 0): ?>
</div><div class="row">
<?php endif; ?>
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>

Related

How to output text from single custom post type on archive page

I have a custom post type. There are single and archive pages. The archive page displays cards with the team. Each card has a city. How can I, when creating a single team member, specify his city and display it on the archive page. This information is not on the single page, only archived.
<?php
$args = array(
'post_type' => 'speakers',
);
$loop = new WP_Query( $args );
while ($loop->have_posts()) :
$loop->the_post(); ?>
<li>
<?php if ( is_object_in_term( $loop->post->ID, 'countries', 'germany' ) ) {
echo '<div class="speaker-flag"><img src="/wp-content/uploads/2022/08/flag-for-germany.svg"></div>';
} else if ( is_object_in_term( $loop->post->ID, 'countries', 'switzerland' ) ) {
echo '<div class="speaker-flag"><img src="/wp-content/uploads/2022/08/flag-for-switzerland.svg"></div>';
} ?>
<a href="<?php echo esc_attr(the_permalink())?>">
<div class="speaker-img">
<?php $img_url = get_the_post_thumbnail_url( $loop->post->ID ); ?>
<img src="<?php echo $img_url ?>">
</div>
<div class="speaker-name">
<p>
<?php the_title(); ?>
</p>
</div>
<div class="speaker-city">
<p>
Fribourg
</p>
</div>
</a>
</li>
<?php endwhile;
wp_reset_query(); ?>
//single
<div class="speaker_info">
<div class="speaker_text">
<h4>
<?php the_title(); ?>
</h4>
<?php the_content(); ?>
</div>
<div class="speaker_img">
<img src="<?php the_field('speaker_img'); ?>">
</div>
</div>

Wrapping a div around the results of a word press loop but excluding the first 2

I have a loop for a custom post type. I'm bringing back a block of title, image and content for each post. I want to apply slick slider to the results to create a slick carousel, but I don;t want to include the first two results of the loop - so I'd need to create a parent div to the results but only start that div after the first two results.
I've trialed ways of querying the results on a loop count to apply a class to only the first two results, but this doesn't really achieve what I'm after.
<div class="wrapper_for_news_items">
<?php
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'news',
'order' => 'DESC'
));
if( $posts ): ?>
<?php $post = $posts[0]; $c=0; ?>
<?php foreach( $posts as $post ):
setup_postdata( $post );
?>
<div class="treatment_block news_block <?php $c++; if($c == 1) { echo ' featured'; } elseif($c == 2) { echo ' featured'; } ?>">
<h2 class="block_title above"> <?php the_title( '' ); ?></h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below"> <?php the_title( '' ); ?></h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div> <!-- treatment news block wrapper -->
You could just create 2 loops.
Use the first for the featured output and the second for the carousel.
<div class="wrapper_for_news_items">
<?php
$args_with_two_posts = array(
'posts_per_page' => 2,
'post_type' => 'news',
'order' => 'DESC'
);
$query_with_two_posts = new WP_Query( $args_with_two_posts );
if( $query_with_two_posts->have_posts ) :
while ( $query_with_two_posts->have_posts ) : $query_with_two_posts->the_posts; ?>
<div class="treatment_block news_block featured">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of 2 post initial news loop -->
</div>
<!-- treatment news block wrapper -->
<?php
// Start your second loop containing the slickslider content
?>
<div class="wrapper_for_news_carousel_items">
<?php
$args_with_all_posts = array(
'posts_per_page' => -1,
'offset' => 2 // Offset the 2 initial posts
'post_type' => 'news',
'order' => 'DESC'
);
$query_with_two_posts = new WP_Query( $args_with_all_posts );
if( $args_with_all_posts->have_posts ) :
while ( $args_with_all_posts->have_posts ) : $args_with_all_posts->the_posts; ?>
<div class="treatment_block news_block">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div>
<!-- treatment news carousel items -->
Or you could count the posts in the loop and asign a wrapper before the third post and after the last post to create the carousel.
<div class="wrapper_for_news_items">
<?php
$args_with_two_posts = array(
'posts_per_page' => 2,
'post_type' => 'news',
'order' => 'DESC'
);
$query = new WP_Query( $args_with_two_posts );
$counter = 1; // Set the counter
if( $query->have_posts ) :
while ( $query->have_posts ) : $query->the_posts;
if ( $count == 3 ) { echo '<div class="slick-slider">'; };
?>
<div class="treatment_block news_block">
<h2 class="block_title above">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date top">
<?php echo get_the_date() ?>
</h3>
<div class="post_icon" style="background-image: url('<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail_url($post_id, 'thumbnail');
}
?>');">
<button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>
</div>
<h2 class="block_title below">
<?php the_title( '' ); ?>
</h2>
<h3 class="post_date bottom">
<?php echo get_the_date() ?>
</h3>
<p class="excerpt">
<?php the_excerpt( '' ); ?>
</p>
</div>
<?php
$counter++; // Add +1 every loop
if (($query->current_post +1) == ($query->post_count)) {
echo '</div>'; // This is the last post
}
endwhile;
?>
<?php wp_reset_postdata(); ?>
<?php else : ?> No News Found!
<?php endif; ?>
<!-- end of news loop -->
</div>
<!-- treatment news block wrapper -->

AJAX Load More Plugin Loads Posts That are Already Shown

I am working on a site with a page that has multiple sections, each section has multiple loops featuring multiple categories. I use Ajax Load More plugin to load new posts for each sections. The issue is when I click on Load More, it loads both the posts already shown and the one that hasn't been shown. I want it to load only new posts not already shown.
Here is the shortcode I used:
echo do_shortcode('[ajax_load_more container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]');
Here is the loop on on of the sections
<div class="row">
<div class="col-lg-12 col-sm-12">
<div class="music_box bg-color1">
<div class="music_box_top">
<?php
$sticky = get_option( 'sticky_posts' );
rsort( $sticky );
$args = array(
'post__in' => $sticky,
'posts_per_page' => 1,
'cat' => 34
);
$sticky_query = new WP_Query( $args );
while ( $sticky_query->have_posts() ) : $sticky_query->the_post();
?>
<a href="<?php the_permalink(); ?>">
<div class="fashion_box_thumb">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'full', array() );
}
?>
</div>
</a>
<div class="fashion_box_text">
<a href="<?php the_permalink(); ?>">
<h3><?php the_title(); ?></h3>
</a>
<p><?php the_excerpt(); ?></p>
<div class="post_cont_icons">
<span class="fa fa-comments cmnt"> <?php comments_number('0','1','%'); ?></span>
<?php echo getPostLikeLink(get_the_ID());?>
<span class="matchtime2"><i class="fa fa-clock-o"></i> <?php the_time();?><br></span>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<div class="clear"></div>
</div><!--music_box_top-->
<div class="fashion_box_bottom">
<?php
$args = array(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => 4,
'cat' => 34
);
$sticky_query = new WP_Query( $args );
$count = 0;
while ( $sticky_query->have_posts() ) : $sticky_query->the_post(); ?>
<?php $count++; ?>
<?php if ($count == 1) :
?>
<div class="fashion_box_bottom_item">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<?php elseif ($count == 2) : ?>
<div class="fashion_box_bottom_item">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<?php elseif ($count == 3) : ?>
<div class="fashion_box_bottom_item">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<?php elseif ($count == 4) : ?>
<div class="fashion_box_bottom_item">
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
</div>
<div class="clear"></div>
</div><!--music_box_bottom-->
</div><!--music_box-->
</div><!--col-lg-12-->
<?php else :
get_template_part( 'woodclefpro/pro_template3' );
endif;
endwhile;
wp_reset_postdata(); ?>
</div><!--row-->
<div class="row">
<?php
echo do_shortcode('[ajax_load_more container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]');
?>
</div>
This is for those that might come across the question above and are facing the same issue that I was. Here is how I solved it.
Add the code below right before endwhile
$do_not_duplicate[] = $post->ID;
Add this inside your shortcode: post__not_in="'.$post__not_in.'"
Then your final shortcode looks like this:
echo do_shortcode('[ajax_load_more ajax_load_more post__not_in="'.$post__not_in.'" container_type="div" post_type="post" posts_per_page="3" preloaded="true" preloaded_amount="4" pause="true" scroll="false" button_loading_label="Loading..." seo="true" category="church-music-news"]');
Not quite right. The fact is that on the page of one of the Addons to this plugin say that the template output single entry, for example "single.php" should be nothing but a shortcode. All content single.php should be placed in the template used by the plugin. Sorry for the crooked English.
https://connekthq.com/plugins/ajax-load-more/add-ons/single-posts/
Note: Ajax Load More will take care of loading ALL posts, including
the initial post when a user lands on the page. All that should remain
in your single.php loop is the ajax_load_more shortcode (as seen
above).

wordpress: show posts in two columns

I have a theme that shows the latest four posts in one column. I want to convert this to two posts in two columns.
I made two divs next to each other and put the first in descending order and the other in ascending order. Then I set it to show only 2 posts.
But now it shows 2 posts in the left div and all four posts in the right div:
I don't understand why it is doing this. Here is the code:
<section class="container">
<div class="left-half">
<article>
<!-- =========================
SECTION: LATEST NEWS
============================== -->
<?php
$parallax_number_of_posts = get_option('posts_per_page');
$args = array( 'post_type' => 'post', 'posts_per_page' => $parallax_number_of_posts, 'order' => 'ASC','ignore_sticky_posts' => true );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$parallax_one_latest_news_title = get_theme_mod('parallax_one_latest_news_title',esc_html__('Latest news','parallax-one'));
if($parallax_number_of_posts > 0) {
?>
<section class="brief timeline" id="latestnews" role="region" aria-label="<?php esc_html_e('Latest blog posts','parallax-one'); ?>">
<div class="section-overlay-layer">
<div align="center" class="container">
<div class="row">
<!-- TIMELINE HEADING / TEXT -->
<?php
if(!empty($parallax_one_latest_news_title)){
echo '<div class="col-md-12 timeline-text text-left"><h2 class="text-left dark-text">'.esc_attr($parallax_one_latest_news_title).'</h2><div class="colored-line-left"></div></div>';
} elseif ( isset( $wp_customize ) ) {
echo '<div class="col-md-12 timeline-text text-left paralax_one_only_customizer"><h2 class="text-left dark-text "></h2><div class="colored-line-left "></div></div>';
}
?>
<div class="parallax-slider-whole-wrap">
<!--<div class="controls-wrap">
<button class="control_next icon icon-arrow-carrot-down"><span class="screen-reader-text"><?php esc_attr_e('Post slider navigation: Down','parallax-one')?></span></button>
<button class="control_prev fade-btn icon icon-arrow-carrot-up"><span class="screen-reader-text"><?php esc_attr_e('Post slider navigation: Up','parallax-one')?></span></button>
</div>-->
<!-- TIMLEINE SCROLLER -->
<div itemscope itemtype="http://schema.org/Blog" id="parallax_slider" class="col-md-6 timeline-section">
<ul class="vertical-timeline" id="timeline-scroll">
<?php
$i_latest_posts= 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
$i_latest_posts++;
if ( !wp_is_mobile() ){
if($i_latest_posts % 2 == 1){
echo '<li>';
}
} else {
echo '<li>';
}
?>
<div itemscope itemprop="blogPosts" itemtype="http://schema.org/BlogPosting" id="post-<?php the_ID(); ?>" class="timeline-box-wrap" title="<?php printf( esc_html__( 'Latest News: %s', 'parallax-one' ), get_the_title() ) ?>">
<div itemscope itemprop="image" class="icon-container white-text">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail('parallax-one-post-thumbnail-latest-news');
else: ?>
<img src="<?php echo parallax_get_file('/images/no-thumbnail-latest-news.jpg'); ?>" width="150" height="150" alt="<?php the_title(); ?>">
<?php
endif;
?>
</a>
</div>
<div class="info">
<header class="entry-header">
<h1 itemprop="headline" class="entry-title"><br><br><br>
<?php the_title(); ?>
</h1>
<!-- .entry-meta -->
</header>
<div itemprop="description" class="entry-content entry-summary">
<?php the_excerpt(); ?>
<?php printf( esc_html__( 'Bekijk de fotos %s', 'textdomain' ), '<span class="screen-reader-text"> '.get_the_title().'</span>' ); ?>
</div>
</div>
</div>
<?php
if ( !wp_is_mobile() ){
if($i_latest_posts % 2 == 0){
echo '</li>';
}
} else {
echo '</li>';
}
endwhile;
wp_reset_postdata();
?>
</ul>
</div>
</div><!-- .parallax-slider-whole-wrap -->
</div>
</div>
</div>
</section>
<?php
}
} ?>
</article>
</div>
<!--rechts-->
<div class="right-half">
<article>
<!-- =========================
SECTION: LATEST NEWS
============================== -->
<?php
$parallax_number_of_posts = get_option('posts_per_page');
$args = array( 'post_type' => 'post', 'posts_per_page' => $parallax_number_of_posts, 'order' => 'DESC','ignore_sticky_posts' => true );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$parallax_one_latest_news_title = get_theme_mod('parallax_one_latest_news_title',esc_html__('Latest news','parallax-one'));
if($parallax_number_of_posts > 0) {
?>
<section class="brief timeline" id="latestnews" role="region" aria-label="<?php esc_html_e('Latest blog posts','parallax-one'); ?>">
<div class="section-overlay-layer">
<div align="center" class="container">
<div class="row">
<!-- TIMELINE HEADING / TEXT -->
<br>
<br>
<br>
<div class="parallax-slider-whole-wrap">
<div class="controls-wrap">
<button class="control_next icon icon-arrow-carrot-down"><span class="screen-reader-text"><?php esc_attr_e('Post slider navigation: Down','parallax-one')?></span></button>
<button class="control_prev fade-btn icon icon-arrow-carrot-up"><span class="screen-reader-text"><?php esc_attr_e('Post slider navigation: Up','parallax-one')?></span></button>
</div>
<!-- TIMLEINE SCROLLER -->
<div itemscope itemtype="http://schema.org/Blog" id="parallax_slider" class="col-md-6 timeline-section">
<ul class="vertical-timeline" id="timeline-scroll">
<?php
$i_latest_posts= 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
$i_latest_posts++;
if ( !wp_is_mobile() ){
if($i_latest_posts % 2 == 1){
echo '<li>';
}
} else {
echo '<li>';
}
?>
<div itemscope itemprop="blogPosts" itemtype="http://schema.org/BlogPosting" id="post-<?php the_ID(); ?>" class="timeline-box-wrap" title="<?php printf( esc_html__( 'Latest News: %s', 'parallax-one' ), get_the_title() ) ?>">
<div itemscope itemprop="image" class="icon-container white-text">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail('parallax-one-post-thumbnail-latest-news');
else: ?>
<img src="<?php echo parallax_get_file('/images/no-thumbnail-latest-news.jpg'); ?>" width="150" height="150" alt="<?php the_title(); ?>">
<?php
endif;
?>
</a>
</div>
<div class="info">
<header class="entry-header">
<h1 itemprop="headline" class="entry-title"><br><br><br>
<?php the_title(); ?>
</h1>
<!-- .entry-meta -->
</header>
<div itemprop="description" class="entry-content entry-summary">
<?php the_excerpt(); ?>
<?php printf( esc_html__( 'Bekijk de fotos %s', 'textdomain' ), '<span class="screen-reader-text"> '.get_the_title().'</span>' ); ?>
</div>
</div>
</div>
<?php
if ( !wp_is_mobile() ){
if($i_latest_posts % 2 == 0){
echo '</li>';
}
} else {
echo '</li>';
}
endwhile;
wp_reset_postdata();
?>
</ul>
</div>
</div><!-- .parallax-slider-whole-wrap -->
</div>
</div>
</div>
</section>
<?php
}
} ?>
</article>
</div>
</section>
If I understood correctly what you want to achieve - to divide several posts into two columns, I can not understand exactly how you want to achieve this into code. If you rely on this condition $the_query->current_post % 2 == 1 to filter the posts, then in your code it only filter printing of the li element, but then the cycle continues and show the post itself, ie what you achieve with this code is to place two posts (div.timeline-box-wrap) elements in one li.If you want to use this method of separation, you should change the code a little (I will simplify it, but the main is, that you must stop current loop if your condition pass).
You don't need to query DB two times with the same query - this is performance issue, so you can use the same result and loop over two times.
You can use $the_query->current_post to get current post and filter.
<section class="container">
<div class="left-half">
<article>
<?php
$parallax_number_of_posts = get_option('posts_per_page');
$args = array( 'post_type' => 'product', 'posts_per_page' => $parallax_number_of_posts, 'order' => 'ASC','ignore_sticky_posts' => true );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
if($parallax_number_of_posts > 0) {
?>
<section class="brief timeline" id="latestnews" role="region" aria-label="<?php esc_html_e('Latest blog posts','parallax-one'); ?>">
<ul class="vertical-timeline" id="timeline-scroll">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
if($the_query->current_post % 2 == 1)
continue; ?>
<li><?php the_title() ?></li>
<?php endwhile; ?>
</ul>
</section>
<?php
}
} ?>
</article>
</div>
<div class="right-half">
<article>
<?php
$the_query->rewind_posts();
if ( $the_query->have_posts() ) {
if($parallax_number_of_posts > 0) {
?>
<section class="brief timeline" id="latestnews" role="region" aria-label="<?php esc_html_e('Latest blog posts','parallax-one'); ?>">
<ul class="vertical-timeline" id="timeline-scroll">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
if($the_query->current_post % 2 == 0)
continue; ?>
<li><?php the_title() ?></li>
<?php endwhile; ?>
</ul>
</section>
<?php
}
} ?>
</article>
</div>
</section>
P.S. You can simplify more, if you set 2 variables: $left and $right and use only one loop to set one or other with html, and then print their values.

the_content(); not showing in images.php

I am having problem getting the_content(); on image.php or attachment.php, the_content(); it's showing in single.php but no in imaage.php, I tried to edit the code but I got nothing,
<div class="content section-inner">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="posts">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="content-inner">
<div class="featured-media">
<?php $imageArray = wp_get_attachment_image_src($post->ID, 'full', false); ?>
<a href="<?php echo esc_url( $imageArray[0] ); ?>" title="<?php the_title_attribute(); ?>" rel="attachment">
<?php echo wp_get_attachment_image( $post->ID, 'post-image' ); ?></a>
</div> <!-- /featured-media -->
<div class="post-header">
<h2 class="post-title"><?php echo basename(get_attached_file( $post->ID )); ?></h2>
<div class="post-meta">
<span><?php _e('Uploaded', 'lingonberry'); echo ' '; the_time(get_option('date_format')); ?></span>
<span class="date-sep">/</span>
<span><?php _e('Width:', 'lingonberry'); echo ' ' . $imageArray[1] . ' px'; // 1 is the width ?></span>
<span class="date-sep">/</span>
<span><?php _e('Height:', 'lingonberry'); echo ' ' . $imageArray[2] . ' px'; // 2 is the height ?></span>
</div>
</div> <!-- /post-header -->
<?php if ( ! empty( $post->post_excerpt ) ) : ?>
<div class="post-content">
<?php the_excerpt(); ?>
</div> <!-- /post-content -->
<?php endif; ?>
</div> <!-- /content-inner -->
<div class="post-nav">
<?php
/**
* Grab the IDs of all the image attachments in a gallery so we can get the URL of the next adjacent image in a gallery,
* or the first image (if we're looking at the last image in a gallery), or, in a gallery of one, just the link to that image file
*/
$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
foreach ( $attachments as $k => $attachment ) :
if ( $attachment->ID == $post->ID )
break;
endforeach;
$l = $k - 1;
$k++;
if ( isset( $attachments[ $k ] ) ) :
// get the URL of the next image attachment
$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
$prev_attachment_url = get_attachment_link( $attachments[ $l ]->ID );
else :
// or get the URL of the first image attachment
$next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
endif;
?>
<?php _e('« Previous<span> attachment</span>', 'lingonberry'); ?>
<?php _e('Next<span> attachment</span> »', 'lingonberry'); ?>
<div class="clear"></div>
</div> <!-- /post-nav -->
<?php comments_template( '', true ); ?>
<?php endwhile; else: ?>
<p><?php _e("We couldn't find any posts that matched your query. Please try again.", "lingonberry"); ?></p>
<?php endif; ?>
</div> <!-- /post -->
</div> <!-- /posts -->
I need help on this
Your code is bit of a mystery but if it looks like this
<?php if ( ! empty( $post->post_excerpt ) ) : ?>
<div class="post-content">
<?php the_excerpt(); ?>
<?php the_content(); ?>
</div> <!-- /post-content -->
<?php endif; ?>
the commands the_excerpt() and the_content() will only execute when there is an excerpt present. The if-statement says "if excerpt is not empty then execute the following code.
Try this:
<div class="post-content">
<?php if ( ! empty( $post->post_excerpt ) ) : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php the_content(); ?>
</div> <!-- /post-content -->
There is a shorter way of writing this but this way it shows the change better.

Categories