I'd like to display titles and thumbnails of my posts using this code snippet, which I'm unable to do so.
How do I solve this problem?
Code
<div class="row">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
<div class="col-md-4">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="<?php the_post_thumbnail('thumbnail');?>
</div>
echo '<h5 class=" card-title ">'.get_the_title().'</h5 >';?>
<p class="card-text "><?php echo get_the_excerpt(); ?></p>
<a href="<?php the_permalink();?>" class="btn btn-primary"> Continue Reading »
</a>
</div>
<?php
endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;?>
</div>
It seems you might have PHP codes in your HTML. Maybe, try this:
<div class="row">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); ?>
<div class="col-md-4">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="<?php the_post_thumbnail('thumbnail'); ?>
</div>
<?php echo '<h5 class=" card-title ">' . get_the_title() . '</h5 >'; ?>
<p class="card-text"><?php echo get_the_excerpt(); ?></p>
Continue Reading »
</div>
<?php endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
?>
</div>
If it did not solve your problem, maybe look into your syntax errors/warnings.
You might consider indenting your codes, it would help you find errors without looking into error logs.
Related
This question already has answers here:
Bootstrap row with columns of different height
(3 answers)
Closed 1 year ago.
Unexpected space exists in loop.depend screen width, the space appear or hidden
Link to the web page in the image
<div class="container">
<div class="row">
if (have_posts()): while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="col-xxs-12 col-xs-6 col-sm-6 col-md-3 ulockd-prl5">
<div class="ficon-box text-center hvr-shadow ulockd-mb20">
<div class="ficon">
<span class="<?php echo get_post_meta($post->ID, 'hekim-extension_ozellikler_icon-select', true);?> text-thm" title="<?php the_title(); ?>"></span>
</div>
<div class="fib-details">
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt();//html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?> <?php _e( 'Read More...', 'hekim' )?></p>
<?php // html5wp_excerpt('html5wp_index');?>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
need add <div class="clearfix visible-xxs-block"></div> after all 4th col-xxs-12 elements.
solution:
<div class="row">
<?php
$xxs_block = 1;
if (have_posts()): while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<?php $xxs_block++; ?>
<div class="col-xxs-12 col-xs-6 col-sm-6 col-md-3 ulockd-prl5">
<div class="ficon-box text-center hvr-shadow ulockd-mb20">
<div class="ficon">
<span class="<?php echo get_post_meta($post->ID, 'hekim-extension_ozellikler_icon-select', true);?> text-thm" title="<?php the_title(); ?>"></span>
</div>
<div class="fib-details">
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt();//html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?> <?php _e( 'Read More...', 'hekim' )?></p>
<?php // html5wp_excerpt('html5wp_index');?>
</div>
</div>
</div>
<?php if ($xxs_block == 5) { ?> <div class="clearfix visible-xxs-block"></div> <?php } ?>
Getting to grips with ACF and it's flexible content field.
I have two layouts as shown below but I can't seem to get the second part (image_block) working correctly as it keeps popping up with a (parse error) I'm probably missing something obvious but if anyone has some advice it would be very helpful.
<?php if( have_rows('content-h') ):?>
<?php while ( have_rows('content-h') ) : the_row();?>
<?php if( get_row_layout() == 'text_block' ):
$title = get_sub_field('title');
$description = get_sub_field('description');
$subheading = get_sub_field('subheading');
?>
<div class="col-lg-6">
<div class="section-title">
<span class="text-color"><?php echo $subheading; ?></span>
<h2 class="mt-3 content-title"><?php echo $title; ?></h2>
</div>
</div>
<div class="col-lg-6">
<p><?php echo $description; ?></p>
</div>
<?php endif; ?>
</div>
<div class="row justify-content-center">
<?php if( get_row_layout() == 'image_block' ):
$image = get_sub_field('image');
$title = get_sub_field('title');
$description = get_sub_field('description');
$link = get_sub_field('link');
?>
<div class="col-lg-3 col-md-6 col-12">
<div class="intro-item mb-5 mb-lg-0">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" alt="" class="img-fluid w-100">
<h4 class="mt-4 mb-3"><?php echo $title; ?></h4>
<p><?php echo $description; ?></p>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Any help is appreciated.
This is a straight PHP parsing error, nothing to do with ACF or flexible fields.
See the comment where I believe you are missing an endif. The best thing to do in these situations is to go through your code line by line noting where you are starting a conditional and whether you have ended it correctly (so the blocks are nested).
Also check that your HTML elements are formed correctly. There appears to be an extra closing div tag - see comments in the code.
<?php if( have_rows('content-h') ):?>
<?php while ( have_rows('content-h') ) : the_row();?>
<?php if( get_row_layout() == 'text_block' ):
$title = get_sub_field('title');
$description = get_sub_field('description');
$subheading = get_sub_field('subheading');
?>
<div class="col-lg-6">
<div class="section-title">
<span class="text-color"><?php echo $subheading; ?></span>
<h2 class="mt-3 content-title"><?php echo $title; ?></h2>
</div>
</div>
<div class="col-lg-6">
<p><?php echo $description; ?></p>
</div>
<?php endif; ?>
</div> <!-- THIS closing div tag seems to be spurious -->
<div class="row justify-content-center">
<?php if( get_row_layout() == 'image_block' ):
$image = get_sub_field('image');
$title = get_sub_field('title');
$description = get_sub_field('description');
$link = get_sub_field('link');
?>
<div class="col-lg-3 col-md-6 col-12">
<div class="intro-item mb-5 mb-lg-0">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" alt="" class="img-fluid w-100">
<h4 class="mt-4 mb-3"><?php echo $title; ?></h4>
<p><?php echo $description; ?></p>
</div>
</div>
<?php endif; //THIS IS WHAT NEEDS TO BE ADDED CHECK IT IS IN THE RIGHT PLACE ?>
<?php endwhile; ?>
<?php endif; ?>
for the first time I'm facing a problem that I can't explain. I'm creating a simple wordpress loop for a gallery but, I don't know why, the loop change my html code inside the loop.
At first, this is what I wrote :
<?php query_posts('posts_per_page=9');
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<?php
$post_image_id = get_post_thumbnail_id($post_to_use->ID);
if ($post_image_id) {
$thumbnail = wp_get_attachment_image_src( $post_image_id, 'large', false);
if ($thumbnail)
(string)$thumbnail = $thumbnail[0];
} else {
$thumbnail = './assets/no-picture.jpg';
}
?>
<article class="col-lg-4 col-sm-6">
<a href="#Modal1" data-toggle="modal" class="gallery-box">
<img src="<?php echo $thumbnail; ?>" class="img-responsive" alt="Image">
<div class="gallery-box-caption">
<div class="gallery-box-content">
<div>
<h2><?php the_title(); ?></h2>
<h6 class='wide-space'><?php the_category(); ?></h6>
<i class="icon-lg ion-ios-play-outline"></i>
</div>
</div>
</div>
</a>
</article>
<?php endwhile; ?>
<?php endif; ?>
But when it's launched online, the code inside the loop become this :
<article class="col-lg-4 col-sm-6">
<a href="#Modal1" data-toggle="modal" class="gallery-box">
<img src="https://labelleequipeproductions.com/wp-content/uploads/2020/08/lessines-terre-de-developpement.jpg" class="img-responsive" alt="Image">
</a>
<div class="gallery-box-caption">
<div class="gallery-box-content">
<a href="#Modal1" data-toggle="modal" class="gallery-box">
</a>
<div>
<a href="#Modal1" data-toggle="modal" class="gallery-box">
<h2>Lessines, Terre de développement</h2>
</a>
<h6 class="wide-space">
<ul class="post-categories">
<li>
Corporate
</li>
</ul>
</h6>
<i class="icon-lg ion-ios-play-outline"></i>
</div>
</div>
</div>
</article>
Are there someone who could help me on this ? I never seen this before and I often use this kind of loop.
I need to show some categories in my home page, and show the category image, and also the link of the same. Using the WORDPRESS.
For them to stick to the same style of example is not the problem. I'm having difficulties appearing, that is, the problem is in the code that calls the categories and their attributes like: image, link and title.
Example
Here's what I'm trying to do:
<section id=""
class="projects">
<div class="js-projects-gallery">
<div class="projects_block row">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$args = array(
'show_option_all' => '',
'echo' => 1,
'hide_empty' => 0,
'style' => 'list',
'title_li' => __('Categorias')
);
?>
<div class="project project_item col-sm-6 col-md-4 col-lg-3">
<?php foreach (get_categories($args) as $cat) : ?>
<a class="link" href="<?php echo get_category_link($cat->term_id); ?>"
title="<?php echo $cat->cat_name; ?>">
<figure>
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>"
class="size-goarch-image-480x880-croped">
<figcaption>
<h3 class="project-title">
<?php echo $cat->cat_name; ?>
</h3>
<h4 class="project-category">
<?php echo $cat->cat_name; ?>
</h4>
<div class="project-zoom"></div>
</figcaption>
</figure>
</a>
<?php endforeach; ?>
</div>
<?php endwhile; else: ?>
<div class="project project_item col-sm-6 col-md-4 col-lg-3">
<p><?php echo "Sorry, we have nothing posted yet."; ?></p>
</div>
<?php endif; ?>
</div>
</div>
</section>
I'm trying to use the Infinite Scroll plugin for Wordpress. I set it up and it doesn't work.
Screen of settings:
Template file
<div id="posts-wrapper" class="row main">
<?php $counter = 1; ?>
<?php if ( have_posts() ){ while ( have_posts() ){ the_post(); ?>
<?php $url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' ); ?>
<div class="single-post <?php if( $counter == 5 ) { echo "col-xs-12 col-sm-12 col-md-8 col-lg-8"; } else { echo "col-xs-12 col-sm-6 col-md-4 col-lg-4";} ?>">
<div class="thumbnail">
<div class="category-wrapper"><?php the_category(', ');?></div>
<a class="href-overlay" href="<?php the_permalink(); ?>"><div class="wrapper">
<div class="<?php if( has_term( 'hot', 'hot', $post->ID ) ){ echo "inside inside-hot"; } else { echo "inside";} ?>"><div class="image-cover" style="background-image: url(<?php echo $url[0]; ?>)"></div></div>
</div></a>
<div class="post-wrapper">
<p class="post-created-by">Napisane przez <strong><span class="special"><?php echo get_the_author(); ?></span></strong> | <i class="glyphicon glyphicon-comment"></i> <?php comments_number( '0' , '1' , '%' ); ?></p>
<h2 class="post-title"><?php the_title(); ?></h2>
</div>
</div>
</div>
<?php $counter++ ; ?>
<?php }else{ ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php } ?>
</div>
<div id="paginacja">
<?php next_posts_link('wczytaj więcej »')?>
</div>
What am I doing wrong?