WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] No image showing in single post (7 posts)

  1. iversoncru
    Member
    Posted 1 year ago #

    My problem is that the posts Images are not shown. It is supposed to be simple T.T but i dont get it.

    This is my code inside single.php

    <div id="single_post">
    	<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    		<h2><?php the_title(); ?></h2>
    		<h3><?php the_time('F jS, Y') ?></h3>
    		<?php the_post_thumbnail('full');?>
    		<p><?php the_content(); ?></p>
    	<?php endwhile; ?>
    	<nav>
    		<?php previous_post_link('%link', '< Previous ' , in_same_cat, 'excluded_categories'); ?>
    		<?php next_post_link('%link', ' Next > ', in_same_cat, 'excluded_categories'); ?>
    	</nav>
      </div>
  2. iversoncru
    Member
    Posted 1 year ago #

    the images were attached to the posts from the Media Library. This means:
    I created a post and published it.
    Then i went to the Media Library and Add a new image.
    From the Media Library i clicked "attach" to attach the image to the post.

    I dont know whats happening, i was supposed to be easy o.O

  3. iversoncru
    Member
    Posted 1 year ago #

    i have also tried this code

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    	<?php echo $post_id = get_the_ID();?>
    	<h2><?php the_title(); ?></h2>
    	<h3><?php the_time('F jS, Y') ?></h3>
    	<?php echo wp_get_attachment_image($post_id, 'full');?>
    	<p><?php the_content(); ?></p>
    <?php endwhile; ?>
    <nav>
    	<?php previous_post_link('%link', '< Previous ' , in_same_cat, 'excluded_categories'); ?>
    	<?php next_post_link('%link', ' Next > ', in_same_cat, 'excluded_categories'); ?>
    </nav>
  4. CarletonU
    Member
    Posted 1 year ago #

    Based on the first piece of code, sounds like you just need to do one more thing, set the image as a featured image. Edit the post and along the right hand side, underneath the categories and tag widgets you should see an area to set a featured image.

    If the featured image widget is not available it may not be registered in your functions file. To do that you need to add the following to your functions.php file:

    add_theme_support( 'post-thumbnails' );

    For more information about the post thumbnail see this codex entry

  5. iversoncru
    Member
    Posted 1 year ago #

    Thanks a lot CarletonU for your answer and your time.

    For the first price of code...

    I had already added the line:
    add_theme_support( 'post-thumbnails' );

    But i kept attaching the image from the Media Library. Now i do as you said, and it is working!

    Thanksssssssssssssss a looooot

  6. CarletonU
    Member
    Posted 1 year ago #

    Awesome, glad I could help! Don't forget to mark this topic as resolved

  7. iversoncru
    Member
    Posted 1 year ago #

    Sure!! thanks again

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.