I’m trying to make a mod in my WordPress homepage. I have this code (index.php):
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content'); ?>
<?php endwhile; ?>
Unfortunately this displays part or all the post content but not the attached images. How can I change it in order to display them? I don’t want to use the featured image but only the attached ones.
I actually found a new WordPress function by researching your question. It’s important to know that there are so many different ways to implement what you are asking for and leaving the following code in the form I am inserting below isn’t ideal. This should only be considered a starting point.
Best practice would be to move it into the
content.php
file (as @Nilambar mentioned in a comment on your question). Maybe even creating a new file, by duplicatingcontent.php
and calling itcontent-attached-media.php
and using it by changing theget_template_part
line toget_template_part( 'content', 'attached-media' )
.Herewith the code to get you started though: