I am trying to include a repeater field in a custom taxonomy template but it keeps returning No Posts to display. I know there are posts to display so I am baffled.
I have tried adding in wp_reset_postdata() but that didn't do anything, I am getting no errors.
Here is the repeater in question:
<?php if( have_rows('feature_repeater') ): ?>
<div class="related-posts">
<h2>You May Also Like...</h2>
<div>
<?php while( have_rows('feature_repeater') ): the_row();
// vars
$image = get_sub_field('collection_image');
$content = get_sub_field('collection_title');
$link = get_sub_field('collection_link');
?>
<div>
<?php if( $link ): ?>
<a href="<?php echo $link; ?>">
<?php endif; ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php if( $link ): ?>
</a>
<?php endif; ?>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php else : ?>
No Posts to Display
<?php endif; ?>
and here is my template:
<?php
/**
* Template used for single posts and other post-types
* that don't have a specific template.
*
* #package Avada
* #subpackage Templates
*/
// Do not allow directly accessing this file.
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Direct script access denied.' );
}
?>
<?php get_header(); ?>
<section id="content" class="full-width" style="width: 100%;">
<div id="post-15912" class="fusion-archive-description post-15912 avada_portfolio type-avada_portfolio status-publish format-standard has-post-thumbnail hentry portfolio_category-dumfries-and-galloway inn-features-coastal-breaks inn-features-countryside-walks inn-features-cycling-holidays inn-features-dog-friendly-pubs inn-features-fine-dining inn-features-fishing-holidays inn-features-romantic-getaways">
<div class="post-content">
<?php
$portfolio_cat_slug = get_queried_object()->slug;
$portfolio_cat_name = get_queried_object()->name;
?>
<h1><?php echo $portfolio_cat_name; ?></h1>
<?php echo category_description(); ?>
<div class="fusion-aligncenter" style="margin-top: 20px;">Buy <?php echo $portfolio_cat_name; ?> Gift Vouchers</div>
</div>
<div class="fusion-posts-container fusion-blog-layout-grid fusion-blog-layout-grid-3 isotope fusion-blog-pagination " data-pages="2" style="position: relative; height: 1384.4px;">
<?php
$collection_post_args = array(
'post_type' => 'avada_portfolio', // Your Post type Name that You Registered
'posts_per_page' => 999,
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'inn-features',
'field' => 'slug',
'terms' => $portfolio_cat_slug
)
)
);
$collection_post_qry = new WP_Query($collection_post_args);
if($collection_post_qry->have_posts()) :
while($collection_post_qry->have_posts()) :
$collection_post_qry->the_post();
?>
<article id="post-15912" class="fusion-post-grid post fusion-clearfix post-15912 avada_portfolio type-avada_portfolio status-publish format-standard has-post-thumbnail hentry portfolio_category-dumfries-and-galloway inn-features-coastal-breaks inn-features-countryside-walks inn-features-cycling-holidays inn-features-dog-friendly-pubs inn-features-fine-dining inn-features-fishing-holidays inn-features-romantic-getaways" style="position: absolute; left: 0px; top: 0px; padding: 10px;">
<div class="fusion-post-wrapper">
<div class="fusion-flexslider flexslider fusion-post-slideshow">
<ul class="slides">
<li class="flex-active-slide" style="width: 100%; float: left; margin-right: -100%; position: relative; opacity: 1; display: block; z-index: 2;">
<div class="fusion-image-wrapper" aria-haspopup="true">
<a href="<?php the_permalink(); ?>">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<img width="384" height="173" alt="" data-src="<?php echo $url ?>" class="attachment-full size-full wp-post-image lazyloaded" src="<?php echo $url ?>" draggable="false">
</a>
</div>
</li>
</ul>
</div>
<div class="fusion-post-content-wrapper">
<div class="fusion-post-content post-content">
<h2 class="entry-title" itemprop="headline"><?php the_title(); ?></h2>
</div>
<div class="fusion-meta-info">
<div class="fusion-alignleft">
Read More
</div>
</div>
</div>
</div>
</article>
<?php
endwhile;
endif;
?>
</div>
</div>
<div class="fusion-aligncenter" style="margin-top: 20px;">Buy <?php echo $portfolio_cat_name; ?> Gift Vouchers</div>
<?php if( have_rows('feature_repeater') ): ?>
<div class="related-posts">
<h2>You May Also Like...</h2>
<div>
<?php while( have_rows('feature_repeater') ): the_row();
// vars
$image = get_sub_field('collection_image');
$content = get_sub_field('collection_title');
$link = get_sub_field('collection_link');
?>
<div>
<?php if( $link ): ?>
<a href="<?php echo $link; ?>">
<?php endif; ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php if( $link ): ?>
</a>
<?php endif; ?>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php else : ?>
No Posts to Display
<?php endif; ?>
</section>
<?php do_action( 'avada_after_content' ); ?>
<?php get_footer(); ?>
Related
The featured thumbnail image is supposed to just show the single thumbnail image of the post but instead it pulls every post image and displays them instead for every post. Instead of just the post thumbnail. This is the code for it and also what it looks like on the page:
<?php $featured_image = new WP_Query('page_id=ID'); ?>
<?php while ($featured_image->have_posts()) : $featured_image->the_post(); ?>
<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { ?>
<?php $img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(302, 170)); ?>
<div class="the-image">
<img src="<?php echo $img_src[0]; ?>" />
</div>
<?php }; ?>
<?php endwhile; ?>
thats the code for servering the image and heres what happens on the main page (I have 2 posts currently and a featured test image for both of them, the scaling works but as you can see, it puts both images, on both posts...)
I'm not sure if it needs to be inside my loop for the title and excerpt, or outside of it (currently inside).
Here is the full code for the recent posts sidebar:
<div class="col-lg-4 d-none d-lg-block">
<h3 style="text-align: center; font-weight: 700;">Recent Posts</h3>
<?php
$result = wp_get_recent_posts(array(
'numberposts' => 10,
'category' => '',
'post_status' => 'publish',
));
foreach( $result as $p ){
?>
<div class="paddingarea text-dark">
<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) { ?>
<?php $img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(302, 170)); ?>
<div class="the-image">
<img src="<?php echo $img_src[0]; ?>" />
</div>
<?php }; ?>
<a class="card-title" href="<?php echo get_permalink($p['ID']) ?>" style="font-weight: 600;"><?php echo $p['post_title']?></a><br />
<p class="card-text"><?php echo excerpt(10); ?></p>
</div>
<?php
}
?>
</div>
Try this, it's simple and it's working for me:
<?php
$result = wp_get_recent_posts(array(
'numberposts' => 10,
'category' => '',
'post_status' => 'publish',
));
foreach( $result as $p ){
?>
<div class="paddingarea text-dark">
<div class="the-image">
<img src="<?php echo get_the_post_thumbnail_url($p['ID'], array(302, 170)); ?>" />
</div>
<a class="card-title" href="<?php echo get_permalink($p['ID']) ?>" style="font-weight: 600;"><?php echo $p['post_title']?></a><br />
<p class="card-text"><?php //echo excerpt(10); ?></p>
</div>
<?php
}
?>
I'm using ACF to post WP posts on a page. But I to be able to control certain CSS properties using nth:child selectors. Heres the PHP which displays every thing fine. Problem is (I'm assuming) that the "foreach" item is making the nth:child not work, because the are not siblings?
<div class="row">
<?php
$posts = get_field('projects');
if ( $posts ) {
foreach ( $posts as $post ): ?>
<div class="col-xl-6 no-space">
<?php
setup_postdata($post); ?>
<div class="project__wrap">
<div class="project__project"><?php echo get_the_post_thumbnail(); ?></div>
<div class="project__description__list col-xl-6"><div class="project-content"><h2><?php echo get_the_title() ; ?></h2><p><?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 15 ) ); ?></p></div>
<div class="heart"><?php
$image = get_field('heart_icon');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
</div> <!-- .project__description__list -->
</div> <!-- .project__wrap -->
<?php wp_reset_postdata(); ?>
</div>
<?php endforeach;
}
?>
div.project-content:nth-child(odd) {
top:0;
left:0;
}
div.project-content:nth-child(even) {
bottom:0;
right:0;
}
The problem in your case is, project-content is always the first child of it's container (project__description__list). What you want is this for .col-xl-6.no-space. But this would be very ambiguous, so I would suggest, to add another class to this div - i.e. project-row-item.
<div class="col-xl-6 no-space project-row-item">
doing so, you could change your css like this
.project-row-item:nth-child(odd) div.project-content {
top:0;
left:0;
}
.project-row-item:nth-child(even) div.project-content {
bottom:0;
right:0;
}
<?php $posts = get_field('projects');
if ( $posts ) {
$i=0; $k; $class='';
foreach ( $posts as $post ):
$k= $i%2;
if($k==0){ $class='even'; } else { $class='odd'; }?>
<div class="col-xl-6 no-space">
<?php setup_postdata($post); ?>
<div class="project__wrap">
<div class="project__project"><?php echo get_the_post_thumbnail(); ?></div>
<div class="project__description__list col-xl-6"><div class="project-content <?php echo $class; ?>"><h2><?php echo get_the_title() ; ?></h2><p><?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 15 ) ); ?></p></div>
<div class="heart"><?php $image = get_field('heart_icon');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
</div> <!-- .project__description__list -->
</div> <!-- .project__wrap -->
<?php wp_reset_postdata(); ?>
</div>
<?php $i++; endforeach; } ?>
Now you could change your style as :
div.project-content.odd {
top:0;
left:0;
}
div.project-content.even {
bottom:0;
right:0;
}
I am currently working on a WordPress site for the first time and having some issues figuring out how to achieve what I am aiming for. I would like for it to display a banner advertisement after every third post then continue from where it left off in my existing post.
Because I probably worded this poorly I will display an example image below.
Here's the current loop file I am using within my index.php file.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$title = htmlentities(get_the_title ());
$str = explode ("–", $title);
$artist = preg_replace('#\[[a-zA-Z].*\]#','',$str[0]);
$song = preg_replace('#\[[a-zA-Z].*\]#','',$str[1]);
?>
<div class="album-meta" style="border-bottom: 1px solid #eee;">
<div class="cover">
<img width="90px" height="90px" src="<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo ''.$feat_image.''; ?>" alt="<?php the_title(); ?>">
</div>
<div class="metadata">
<a href="<?php the_permalink(); ?>" style="text-decoration: none; color: #757575"><p><i style="font-size: 13.7px;"><?php print $song; ?></i></p>
<p><strong style="font-size: 15px;"><?php print $artist; ?></strong></p>
</a>
<p>Download
</div>
</div>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
You can do it like below:-
<?php $i = 0; // create a counter?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$title = htmlentities(get_the_title ());
$str = explode ("–", $title);
$artist = preg_replace('#\[[a-zA-Z].*\]#','',$str[0]);
$song = preg_replace('#\[[a-zA-Z].*\]#','',$str[1]);
?>
<div class="album-meta" style="border-bottom: 1px solid #eee;">
<div class="cover">
<img width="90px" height="90px" src="<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo ''.$feat_image.''; ?>" alt="<?php the_title(); ?>">
</div>
<div class="metadata">
<a href="<?php the_permalink(); ?>" style="text-decoration: none; color: #757575"><p><i style="font-size: 13.7px;"><?php print $song; ?></i></p>
<p><strong style="font-size: 15px;"><?php print $artist; ?></strong></p>
</a>
<p>Download
</div>
</div>
<?php if($i%3 ==0 && $i >0){ // check you reached to third div or not?>
<!-- write the html of advertisement div ------->
<?php $i++;} ?> <!-- increase counter -->
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Try this...
<?php
$counter = 0;
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$title = htmlentities(get_the_title ());
$str = explode ("–", $title);
$artist = preg_replace('#\[[a-zA-Z].*\]#','',$str[0]);
$song = preg_replace('#\[[a-zA-Z].*\]#','',$str[1]);
if($counter == 3){ ?>
********** Advertisement code write here ***********
<?php
}
?>
<div class="album-meta" style="border-bottom: 1px solid #eee;">
<div class="cover">
<img width="90px" height="90px" src="<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo ''.$feat_image.''; ?>" alt="<?php the_title(); ?>">
</div>
<div class="metadata">
<a href="<?php the_permalink(); ?>" style="text-decoration: none; color: #757575"><p><i style="font-size: 13.7px;"><?php print $song; ?></i></p>
<p><strong style="font-size: 15px;"><?php print $artist; ?></strong></p>
</a>
<p>Download
</div>
</div>
<?php
$counter++;
endwhile; else : ?>
I am using an Image Gallery in Custom Post Type on my WordPress Website. The Plugin I am using for that is Advanced Custom Fields. There is some error, due to which image gallery is not getting displayed on frontend.
Please check the page.
http://divinepower.co.in/cof/projects/residential/surrey-hills-vic/
Though the same code is working fine on another custom post type.
http://divinepower.co.in/cof/brands/gloster/asta/
The code I am using is
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
// Show the Gallery
if( have_rows('gallery_slideshow') ):
echo '<div class="projects-gallery-wrap">';
echo '<div class="projects-gallery">';
// loop through the rows of data
while ( have_rows('gallery_slideshow') ) : the_row();
$imgObj = get_sub_field('image', $post->ID);
echo '<img class="item" src="'.$imgObj[sizes]['projects-gallery'].'" alt="'.$imgObj[alt].'"/>';
endwhile;
echo '</div>';
echo '</div>';
endif;
?>
<div id="inner-content" class="wrap cf">
<main id="main" class="main-content" role="main" itemscope itemprop="mainContentOfPage" itemtype="http://schema.org/Blog">
<div class="gallery-controls">
<button class="prev"><i class="fa fa-chevron-left"></i></button>
<button class="next"><i class="fa fa-chevron-right"></i></button>
</div>
<article id="post-<?php the_ID(); ?>" <?php post_class('cf'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<?php
$currentBrandName = cosh_get_brand_name();
$currentBrandSlug = cosh_get_brand_slug();
?>
<div class="content">
<header class="article-header">
<div class="title-wrap">
<h1 class="entry-title single-title" itemprop="headline"><?php the_title(); ?></h1>
<?php
// Brand Image
print apply_filters( 'taxonomy-images-list-the-terms', '', array(
'before' => '<ul class="projects-logos">',
'after' => '</ul>',
'image_size' => 'full',
'taxonomy' => 'brand'
) );
?>
</div>
<?php
// Social share
$currentURL = get_permalink( $post->ID );
?>
<div class="social-share">
<i class="fa fa-facebook"></i>
<i class="fa fa-pinterest-p"></i>
</div>
</header>
<section class="entry-content cf" itemprop="articleBody">
<div class="content-wrap">
<?php the_content(); ?>
<?php
// projects Link
$projectsURL = site_url()."/brand/".$currentBrandSlug;
if($projects){ ?>
View all <?php echo $currentBrandName; ?> projectss ›
<?php }; ?>
</div>
<?php
// Additional Info
$materials = get_field('materials', $post->ID);
$projectsSpecs = get_field('projects_specs', $post->ID);
if($materials || $projectsSpecs){ ?>
<div class="additional-info">
<?php
// Materials
if($materials){ ?>
<h4>Materials <i class="fa fa-pencil"></i></h4>
<p><?php the_field('materials'); ?></p>
<?php };
// projects Specs
if($projectsSpecs){ ?>
Download Specs <i class="fa fa-download"></i>
<?php }; ?>
</div>
<?php } ?>
</section>
<?php/*
// Show the Gallery
if( have_rows('gallery_slideshow') ):
echo '<div class="projects-gallery-wrap-mobile">';
echo '<div class="projects-gallery-mobile">';
// loop through the rows of data
while ( have_rows('gallery_slideshow') ) : the_row();
$imgObj = get_sub_field('image', $post->ID);
echo '<img class="item" src="'.$imgObj[sizes]['projects-gallery'].'" alt="'.$imgObj[alt].'"/>';
endwhile;
echo '</div>';
echo '</div>';
endif;
*/ ?>
</div>
</article>
<?php get_template_part('parts/enquiry_form'); ?>
</main>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Please help me to find the error. Thanks
I have a wordpress websites which shows latest posts with title, image, description and read more button in the blog page. when the read more button is clicked it will be directed to the single.php and its working fine.
Now i have created a new custom post type called "Products" where i can add products. it have similar layout of the single.php, but i need some changes and additional things in the single page of the products. So, I am planning to create a separate file single_product.php .
I want the read more button under the product to automatically link to the single_product.php as the blog posts are linked to the single.php
Here is the code for : Single.php
<?php get_header(); ?>
<!--BEGIN #content -->
<div id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!--BEGIN .hentry -->
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<!--BEGIN .post-header-->
<div class="post-header">
<div class="inner"> <span class="meta-category">
<?php the_category(', '); ?>
</span>
<h1 class="post-title">
<?php the_title(); ?>
<?php $format = get_post_format(); ?>
<?php if ($format == "image" || $format == "gallery" || $format == "video") : ?>
<span class="icon"><img src="<?php echo get_template_directory_uri(); ?>/images/icon-<?php echo $format; ?>.png" alt="<?php echo $format; ?>" /></span>
<?php endif; ?>
</h1>
<span class="meta-published">
<?php _e('Posted', 'engine') ?>
<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' '. __('ago', 'engine'); ?></span> <span class="meta-author">
<?php _e('by', 'engine') ?>
<?php the_author_posts_link(); ?>
</span> </div>
<!--END .post-header -->
</div>
<!--BEGIN .featured-image -->
<div class="featured-image <?php echo get_post_format(); ?>">
<?php if (get_post_format() == 'video' && get_post_meta(get_the_ID(), 'dt_video', true) != '') : ?>
<?php
global $wp_embed;
$video_url = get_post_meta(get_the_ID(), 'dt_video', true);
$video_embed = $wp_embed->run_shortcode('[embed width="620"]'.$video_url.'[/embed]');
?>
<div id="video-<?php the_ID(); ?>"><?php echo $video_embed; ?></div>
<?php elseif (get_post_format() == 'gallery') : ?>
<!--BEGIN #slides -->
<div id="single-slides" class="clearfix">
<?php
$args = array(
'orderby' => 'menu_order',
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => -1,
);
$attachments = get_posts($args);
?>
<?php if ($attachments) : ?>
<div class="slides_container">
<?php foreach ($attachments as $attachment) : ?>
<?php
$format = get_post_format();
$src = wp_get_attachment_image_src( $attachment->ID,
array( '9999','9999' ), false, '' );
$src = $src[0];
$image = dt_resize($attachment->ID, $src, 620, '', true);?>
<div> <span class="overlay-icon overlay-<?php echo $format; ?>">
<a rel="group-<?php the_ID(); ?>"
title="<?php echo $attachment->post_title;?>"
class="colorbox-<?php echo $format; ?>"
href="<?php echo $src; ?>"></a></span>
<img height="<?php echo $image['height']; ?>"
width="<?php echo $image['width']; ?>"
alt="<?php echo apply_filters('the_title', $attachment->post_title); ?>"
src="<?php echo $image['url']; ?>"
/> </div>
<?php endforeach; ?>
</div>
<!--BEGIN .slide-cntrols-->
<div id="slide-controls"> Next
Prev
<!--END .slide-cntrols-->
</div>
<?php endif; ?>
<!--END #slides -->
</div>
<?php elseif (has_post_thumbnail() && get_option('dt_blog_image') != 'false'):?>
<?php $thumb = get_post_thumbnail_id(get_the_ID());
$image = dt_resize( $thumb, '', 620, '', true );
echo '<img src="'.$image['url'].'" width="'.$image['width'].'"
height="'.$image['height'].'" alt="" />';?>
<?php endif; ?>
<!--END .featured-image -->
</div>
<!--BEGIN .post-content -->
<div class="post-content">
<?php the_content(); ?>
<!--END .post-content -->
</div>
<!--BEGIN .post-footer-->
<div class="post-footer"> <span class="meta-published">
<?php echo human_time_diff( get_the_time('U'), current_time('timestamp')).'
'. __('ago', 'engine'); ?></span> <span class="meta-comments">
<?php comments_number(__('No Comments', 'engine'),
__('1 Comment','engine'), __('% Comments', 'engine')); ?>
</span>
<!--END .post-footer-->
</div>
<!--END .hentry-->
</div>
<?php comments_template('', true); ?>
<?php endwhile; else : ?>
<p>
<?php _e('No posts found', 'engine'); ?>
</p>
<?php endif; ?>
</div>
<!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
How can i do this ?
Try to use like this :
1. archive-{post_type}.php
2. single-{post_type}.php
Check this link for more detail.
See the Page Hierarchy in an image:
archive-{custompost_type_name}.php /* like archive-brand.php */
single-{custompost_type_type}.php /* like single-brand.php */
taxonomy-{custompost_type_category_name}.php /* like
taxonomy-brand_category.php*/