Support » Fixing WordPress » Can Hashtag results show image from post instead of title?

  • Hello,
    I’d like to be able to click on a recurring hashtag from my posts and show the image from each post instead of each post title. Is that possible? Currently if I click on the tag, it shows a list of my post titles, each clickable, that I can delve into to see the full post along with the image. I’m hoping to show the image, which would then be clickable to see the full post…

Viewing 9 replies - 1 through 9 (of 9 total)
  • If you’re referring to the featured image from each post, it should be possible by modifying the tag.php template in your child theme.

    If you can tell us your site url or what theme you’re using, we can give some more specifics.

    Thread Starter griswolddad

    (@griswolddad)

    I’m using the WordPress 2014 theme. My url is http://www.griswolddad.com.

    Thread Starter griswolddad

    (@griswolddad)

    <?php
    /**
    * The template for displaying Tag pages
    *
    * Used to display archive-type pages for posts in a tag.
    *
    * @link http://codex.wordpress.org/Template_Hierarchy
    *
    * @package WordPress
    * @subpackage Twenty_Fourteen
    * @since Twenty Fourteen 1.0
    */

    get_header(); ?>

    <section id=”primary” class=”content-area”>
    <div id=”content” class=”site-content” role=”main”>

    <?php if ( have_posts() ) : ?>

    <header class=”archive-header”>
    <h1 class=”archive-title”><?php printf( __( ‘Tag Archives: %s’, ‘twentyfourteen’ ), single_tag_title( ”, false ) ); ?></h1>

    <?php
    // Show an optional term description.
    $term_description = term_description();
    if ( ! empty( $term_description ) ) :
    printf( ‘<div class=”taxonomy-description”>%s</div>’, $term_description );
    endif;
    ?>
    </header><!– .archive-header –>

    <?php
    // Start the Loop.
    while ( have_posts() ) : the_post();

    /*
    * Include the post format-specific template for the content. If you want to
    * use this in a child theme, then include a file called called content-___.php
    * (where ___ is the post format) and that will be used instead.
    */
    get_template_part( ‘content’, get_post_format() );

    endwhile;
    // Previous/next page navigation.
    twentyfourteen_paging_nav();

    else :
    // If no content, include the “No posts found” template.
    get_template_part( ‘content’, ‘none’ );

    endif;
    ?>
    </div><!– #content –>
    </section><!– #primary –>

    <?php
    get_sidebar( ‘content’ );
    get_sidebar();
    get_footer();

    Thanks. If you haven’t already created a child theme, I’d suggest doing so via the steps here: http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme

    Doing so will allow you customize how the them looks, and still update the Twenty Fourteen theme as needed.

    Thread Starter griswolddad

    (@griswolddad)

    Sorry. I need to admit my noobness. You can’t just edit the tag.php file is copied above? You first have to create a child theme?

    Once the child theme is created, what steps will I need to take to have the hashtag search show the associated images rather than the post titles?

    Creating and activating child theme very strongly recommended.

    While you could just edit the tag.php file, but you’ll lose that customization the next time the Twenty Fourteen theme updates. Editing the main theme files and forgoing updates is discouraged, because you’ll miss out on any security, performance, or coding standards changes that come with those updates.

    I’ll be able to give you the specific changes you need to make to the child theme files tonight once I sort them out on my development server.

    Once you’ve created the child theme, copy tag.php to it from the Twenty Fourteen theme.

    Then delete lines 37-43 and replace them with the following:

    /*
    						 * Just display the featured image for each post in the tag archive, and link it to the post
    						 */
    			?>
    
    						<div class="tag-archive-featured-images"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('Full Size'); ?></a></div>
    
    			<?php

    The entire child theme tag.php file should be as follows:

    <?php
    /**
     * The template for displaying Tag pages
     *
     * Used to display archive-type pages for posts in a tag.
     *
     * @link http://codex.wordpress.org/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Twenty_Fourteen
     * @since Twenty Fourteen 1.0
     */
    
    get_header(); ?>
    
    	<section id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
    
    			<?php if ( have_posts() ) : ?>
    
    			<header class="archive-header">
    				<h1 class="archive-title"><?php printf( __( 'Tag Archives: %s', 'twentyfourteen' ), single_tag_title( '', false ) ); ?></h1>
    
    				<?php
    					// Show an optional term description.
    					$term_description = term_description();
    					if ( ! empty( $term_description ) ) :
    						printf( '<div class="taxonomy-description">%s</div>', $term_description );
    					endif;
    				?>
    			</header><!-- .archive-header -->
    
    			<?php
    					// Start the Loop.
    					while ( have_posts() ) : the_post();
    
    						/*
    						 * Just display the featured image for each post in the tag archive, and link it to the post
    						 */
    			?>
    
    						<div class="tag-archive-featured-images"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('Full Size'); ?></a></div>
    
    			<?php 
    
    					endwhile;
    					// Previous/next page navigation.
    					twentyfourteen_paging_nav();
    
    				else :
    					// If no content, include the "No posts found" template.
    					get_template_part( 'content', 'none' );
    
    				endif;
    			?>
    		</div><!-- #content -->
    	</section><!-- #primary -->
    
    <?php
    get_sidebar( 'content' );
    get_sidebar();
    get_footer();

    In the child theme style.css, you’ll wand to add something like the following:

    .tag-archive-featured-images {
    margin: 10px 0;
    }

    That will put some vertical space between each of the images. Adjust the 10px to taste.

    Hope that helps.

    Thread Starter griswolddad

    (@griswolddad)

    OK. I’ve done all that. Thank you for your help. 1 last question, it still isn’t working. So I want to make sure I’m using the right terminology. “Featured” image per post…I’ve not manually set anything as “Featured”. Simply, each post has an image in it through adding media. Is that the same thing as “featured”…or do I need to do something to the images themselves?

    Ah, I see that now. Unfortunately there’s just no good way to automatically show the first image in the post content, but we can still make this work.

    A featured image will have to be set for each individual post. You can do that manually, but it would probably be a bit of a pain to be honest.

    If you install/activate this plugin, it will automatically set the first image in each post as the featured image: https://wordpress.org/plugins/autoset-featured-image/

    One thing to note is that this will update all of your posts to include a featured image for each post. This is not easily reversible. If for some reason you decide you hate having featured images for your posts, you’ll have to remove them manually, one by one.

    I’d recommend looking at the Twenty Fourteen demo before deciding if you want to include featured images (the large images above the titles) for all of your posts: https://twentyfourteendemo.wordpress.com/

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Can Hashtag results show image from post instead of title?’ is closed to new replies.