- This topic is empty.
-
AuthorPosts
-
April 10, 2016 at 10:36 am #240376
Doom_87
ParticipantHello. It would be great if someone here could help me because I keep looking and looking but can’t find a solution since I’m new to WordPress. I need to put a plugin’s code inside the theme’s loop but I don’t know where exactly I should place it. I don’t even know which theme file contains the loop. Is it the style.css?
Anyway, the plugin is for displaying featured images inside the posts and it’s this one:
https://wordpress.org/plugins/featured-image/
Until now I have been putting manually the shortcode before each post but I want it to be automated. The creator of the plugin says this is the code that must be placed inside Theme Loop:
<?php if ( function_exists(‘get_featured_img’) ) get_featured_img(); ?>
I tried to contact him but unfortunately he has not replied.
I hope you could help me!
Thanks.April 11, 2016 at 1:53 am #240422Atelierbram
ParticipantProbably in a
single.phptemplate (“single” stands for “single posts”), somewhere in thiswhilestatement. More info about the default WordPress loop<?php if (have_posts()) : while (have_posts()) : the_post(); ?> // stuff <?php if ( function_exists('get_featured_img') ) get_featured_img(); ?> // stuff <?php endwhile; ?>April 11, 2016 at 6:26 am #240428Doom_87
ParticipantThanks for answering.
Here’s my single.php so I hope you could point out easier where exactly to put it:April 12, 2016 at 1:38 am #240466Atelierbram
ParticipantI read through your initial question again, and are now thinking you don’t really need this plugin for what you want.
In your
functions.phpyou should have a line like this:add_theme_support( 'post-thumbnails' );Then in your
single.phpone can do something like:<div class="entry-content entry-single entry-text entry-blog"> <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail(); } ?> <?php the_content(); ?> </div><!-- .entry-content --> ?>See also: Featured Images & Post Thumbnails
If unsure, you can also always look into a barebones theme like Underscores
April 12, 2016 at 5:15 am #240472Doom_87
ParticipantThanks for the answer!
Here’s how my single.php looks like:
http://pastebin.com/Sv678HdAApril 13, 2016 at 2:29 am #240502Atelierbram
ParticipantWe will have to start digging a bit deeper: in your
single.phpfile online-number 14there is this code-snippet:<?php get_template_part( 'content', get_post_format() ); ?>The first piece
get_template_partis 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.phporcontent-aside.php,content-gallery.phpand 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.phpadd_theme_support( 'post-thumbnails' ); -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.