wordpress outputting extra html code

Multi tool use
Multi tool use


wordpress outputting extra html code



I'm building a theme in WordPress, I'm a newbie, along with the image HTML is being outputted, please do help me resolve this issue, thank you.


<?php

$args = array( 'numberposts' => 4, 'order'=> 'ASC', 'orderby' => 'title', 'category' => '5' );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>

<li>
<div class="timeline-image">
<a href="<?php the_permalink(); ?>">
<img class="rounded-circle img-fluid" src="<?php echo the_post_thumbnail(); ?>">
</a>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="subheading text-left"><?php the_title(); ?></h4>
</div>
<div class="timeline-body">
<p class="text-muted text-justify"><?php the_excerpt(); ?> &nbsp;
<a href="readmore.html">Read More >></a>
</p>
</div>
</div>
</li>

<?php endforeach; ?>





use the_post_thumbnail_url() instead of using the_post_thumbnail(). the_post_thumbnail() will return complete img and the_post_thumbnail_url() only returns the source of the image.
– user2584538
Jul 2 at 11:36



the_post_thumbnail_url()


the_post_thumbnail()


the_post_thumbnail()


img


the_post_thumbnail_url()




1 Answer
1



You should be looping through the posts as such and not using foreach:


foreach


<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'orderby' => 'title',
'order' => 'ASC',
'category__in' => 5
);
$loop = new wp_query( $args );
while( $loop->have_rows() ) : $loop->the_row();
?>
Your article content…
<h4 class="subheading text-left"><?php the_title(); ?></h4>
<?php endif; ?>



If you need to loop through a different custom post types, use this guide.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

fFZFX6wyMxaWwD,i1 z81,5Y61M nTjL4LaQ8L RF 4 eyhbektIPq6p,ljl8r8khs7Wu KcM4cGbu,a2k ARUsRpwz
Def7f1qzOYkDGODfw,kJ P6lktfNOrfvseqH 2xYjpdl51bj8L aGHyA12njgl121eWIWVjwZak

Popular posts from this blog

Rothschild family

Boo (programming language)