• Resolved cybershot

    (@cybershot)


    I have used one version of code to get the image from the featured image, but I need the image place in a specific spot so I am looking to call the image outside of the_content(). My code right now returns the ID number, I don’t know why. In my searching, I have found others with this issue, but their fix did not work for me.

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
      register_post_type( 'OurMenu',
        array(
          'labels' => array(
            'name' => __( 'Menu' ),
            'singular_name' => __( 'Menu' )
          ),
    	  'capability_type' =>  'post',
          'public' => true,
    	  'supports' => array(
    	  'title',
    	  'editor',
    	  'excerpt',
    	  'trackbacks',
    	  'custom-fields',
    	  'revisions',
    	  'thumbnail',
    	  'author',
    	  'page-attributes',
    	  )
        )
      );
    }

    I also have this line in my functions.php but I don’t believe it is needed

    add_theme_support( 'post-thumbnails', array( 'post','OurMenu' ) );

Viewing 7 replies - 1 through 7 (of 7 total)
  • What code are you using to output the featured image, are you using the_post_thumbnail?

    <?php the_post_thumbnail();?>

    And what html gets generated by WordPress? Have you checked that the image with the correct path, name and size exists for the actual image tag that gets output on your website?

    Thread Starter cybershot

    (@cybershot)

    well, I have changed the code a few times. This is version 3.

    add_action('init', 'OurMenu');
    
    function OurMenu(){
    	$OurMenu_args = array(
    		'label'	=> __('Our Menu'),
    		'singular_label' =>	__('Our Menu'),
    		'public'	=>	true,
    		'show_ui'	=>	true,
    		'capability_type'	=>	'post',
    		'hierarchical'	=>	false,
    		'rewrite'	=>	true,
    		'supports'	=>	array('title', 'editor','page-attributes','thumbnail')
    		);
    		register_post_type('OurMenu', $OurMenu_args);
    }
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 132, 133, true );

    then in my template file, I have it set up right, I just need the featured image to show. I tried this

    $loop = new WP_Query( array( 'post_type' => 'OurMenu', 'posts_per_page' => 3 ) );
    			while ( $loop->have_posts() ) : $loop->the_post();
    			  echo '<div class="menupageContent">';
    			   get_the_post_thumbnail();
    			  ?><p class="textYellow arrow"><?php the_title(); ?></p><?php
    			  the_content();
    			  echo '</div>';
    			endwhile;

    I have tried
    get_the_post_thumbnail();
    get_the_post_thumbnail($id);
    get_the_post_thumbnail(the_ID(), 'thumbnail');
    get_the_post_thumbnail($loop->ID, 'thumbnail');

    nothing is working. In every case, there is no output for the image. One version does display the ID where the image should be. Just not the image. I have checked the database. I see the posts, but I do not see any row for featured image. The image does not show up in the content in the database. I can see the image under “featured Image” in the admin area when editing the post.

    use the_post_thumbnail function

    Thread Starter cybershot

    (@cybershot)

    Bingo! The image came popped up in the post rather small. Do you know how I can change the size of the image? it is suppose to be 132 by 133 but it’s getting put in as 83 by 84

    Thread Starter cybershot

    (@cybershot)

    resolved it. I changed

    the_post_thumbnail();
    to
    the_post_thumbnail("full");

    Thanks guys for the help

    Just wanted to say thanks for this thread. I just implemented a dynamic image slider that displays the featured images from my CPT Porftolio entries in about 15 mins!

    Thread Starter cybershot

    (@cybershot)

    Glad it helped you out. I am also glad you posted. I forgot about this post and could actually use the code again in another project I am doing. I am going to bookmark this page.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘help getting featured image from custom post type’ is closed to new replies.