• So I’m displaying a thumbnail gallery using the_post_thumbnail on my custom category page. Underneath each post_thumbnail I have the post_title. Right now instead of showing the post title it is showing the name of the image attached to the post. This is a problem because a lot of the images have a 2 at the end (EG post name 650L, image named 650L2) So the 650L2 is what is showing up underneath my post_thumbnails. How would I go about having the post TITLE display as opposed to the featured image name? Here is my thumbnail code as of now:

    <?php echo get_post(get_post_thumbnail_id())->post_title; ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Can you show us the full template file?
    Maybe [untested]:

    <?php
    $thumb = get_post( get_post_thumbnail_id() );
    if ( $thumb ) {
    	echo get_the_title( $thumb->post_parent );
    }
    ?>

    Thread Starter bluedrag

    (@bluedrag)

    <?php
    /**
     * The template for displaying Category Archive pages.
     *
     * @package Toolbox
     * @since Toolbox 0.1
     */
    
    get_header(); ?>
    
    <?php global $q_config; ?>
    
    		<section id="primary">
    			<div id="content" class="product_gallery" role="main">
    
    			<h1 class="cat_title">
    			<?php include 'incategory.php'; ?>
    			</h1>
    
    			<?php while ( have_posts() ) : the_post(); ?>
    
    			<div class="product_thumbnail">
    			<a href="<?php the_permalink() ?>">
    			<?php //the_post_thumbnail grabs the post's "featured image" this feature has added theme support in the child theme functions.php ?>
    			<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnail')); ?>
    			</a>
    
    			<?php //This piece of code figures out the corrosponding post_title of the featured image ?>
    			<p class="post_caption">
    			<?php echo get_post(get_post_thumbnail_id())->post_title; ?>
    			</p>
    			</div> <!-- product_thumbnail -->
    
    			<?php endwhile; // end of the loop. ?>
    
    			<br class="clear" />
    			</div><!-- #content -->
    		</section><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    Moderator keesiemeijer

    (@keesiemeijer)

    Couldn’t you use the post title by using the_title():
    http://codex.wordpress.org/Function_Reference/the_title
    or get_the_title().
    http://codex.wordpress.org/Function_Reference/get_the_title

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying post_title on Category page’ is closed to new replies.