Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to put code in Loop? Reply To: How to put code in Loop?

#240502
Atelierbram
Participant

We will have to start digging a bit deeper: in your single.php file on line-number 14 there is this code-snippet:

<?php get_template_part( 'content', get_post_format() ); ?>

The first piece get_template_part is a WordPress implementation in a custom syntax of the so called “PHP include”.

The second piece get_post_format tells the template engine to look for a file which starts with “content”, then a hyphen and then the name of the “post format“.

If there is no post-format set, then it probably defaults to something like content-single.php.

So the file which is included, and which you will have to look for now is either content-single.php or content-aside.php, content-gallery.php and so on.

Now in this file you can do what I wrote about before: put this snippet in:

<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail();
}
?>

and in functions.php

add_theme_support( 'post-thumbnails' );