0

For my client site, I am planning to enable link post image to post a link on blog list page, the site uses custom WordPress theme developed by the previous developer.

For blog post list page he created as content.php and for the single post he created content-page.php

Even if I add the featured image I can't able to see that featured image, only the image inside of the post is showing.

How to achieve this?

Here is the code for content.php

<?php
/**
 * Template part for displaying posts
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Blog
 */

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php
        if ( is_single() ) :
            the_title( '<h1 class="entry-title">', '</h1>' );
        else :
            the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '"  rel="bookmark" >', '</a></h2>' );
        endif;

        if ( 'post' === get_post_type() ) :  ?>
        <h4 class="meta text-muted">
            <?php bfablog_posted_on(); ?>
        </h4><!-- .entry-meta -->
        <?php
        endif; ?>
        <!-- AddThis Button BEGIN -->
    <div class="addthis_inline_share_toolbox_mzc3" style="margin-bottom:20px;" data-title="<?php the_title() ?>" data-url="<?php the_permalink(); ?>" </div>
        <!-- AddThis Button END -->

    </header><!-- .entry-header -->

    <div class="entry-content">


        <?php
                     the_content( sprintf (
                /* translators: %s: Name of current post. */
                wp_kses(__( 'Read more', 'bfablog' ), array( 'span' => array( 'class' => 
array() ) ) ),

                the_title( '<span class="screen-reader-text">"', '"</span>', false )
            ) );


               wp_link_pages( array(
                            'before' => '<div class= "page-links">'. esc_html__('Pages:', 'bfablog'
),

                           'after'  => '</div>',
            ) );
        ?>

    </div><!-- .entry-content -->

    <footer class="entry-footer">
        <?php bfablog_entry_footer(); ?>
    </footer><!-- .entry-footer -->
</article><!-- #post-## -->
<hr>

<script type="text/javascript">
  var addthis_config = {
    ui_language: "{{ site.lang }}"
  };
  var addthis_share =
  {
     // ... members go here
  }
</script>

<!-- Go to www.addthis.com/dashboard to customize your tools -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-586c401922d76d24"></script>

Here is the code for content-page.php

<?php
/**
 * Template part for displaying page content in page.php
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package BfA_Blog
 */

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>

    </header><!-- .entry-header -->

    <div class="entry-content"><hr>
        <?php
            the_content();


            wp_link_pages(array(
                'before' => '<div class="page-links">' . esc_html__('Pages:','bfablog'),
                'after'  => '</div>',
            ) );
        ?>
    </div><!-- .entry-content -->


    <?php if ( get_edit_post_link() ) : ?>
        <footer class="entry-footer">
            <?php
                edit_post_link(
                    sprintf(
                        /* translators: %s: Name of current post */
                        esc_html__( 'Edit %s', 'bfablog' ),
                        the_title( '<span class="screen-reader-text">"', '"</span>', false )
                    ),
                    '<span class="edit-link">',
                    '</span>'
                );
            ?>
        </footer><!-- .entry-footer -->
    <?php endif; ?>
</article><!-- #post-## -->
1
  • Please refrain from adding bitly links, I removed it from the post as the question can be explained even without it. If you think it's required please add the site URL not the bitly one
    – bravokeyl
    Commented Sep 7, 2017 at 11:00

2 Answers 2

0

Just to be clear, you want to show the featured image and link it to the single post page? The content.php is the loop being used to display the content. So this is the place where you want to place the featured image.

To show the featured image in the archive or posts list, edit content.php. In the header tag of the article, Do this.

   if ( is_single() ) :
        the_post_thumbnail('large'); // If you want to show the featured image in the single post page
        the_title( '<h1 class="entry-title">', '</h1>' );
    else :
        the_post_thumbnail('large'); // If you want to show the image in the archive. You can change the location if before or after title
        the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '"  rel="bookmark" >', '</a></h2>' );
    endif;

Steps to edit the content.php

First, this answer is based on the notion that your client is using a featured image. If not, then I can no longer understand what you guys are trying to achieve :(

  1. Login to Wordpress
  2. Appearance -> Editor
  3. Find and click content.php in the right side of the page
  4. Backup the current codes in there and paste the code in the pastebin below.

https://pastebin.com/cEAFHntg

Hope this works for you, if not it is best to find a developer.

17
  • thanks for reply , now i want to link the post in the post images that shows in the archive or posts list, how edit the (content.php is the loop being used to display the content) ?? Commented Sep 7, 2017 at 10:21
  • thanks for reply ,I am new to wordpress development, now clients dont wants to use featured image , they just asking with the current blog post list view page , if i click the image that should open the post page,i dont know how to edit the (content.php is the loop being used to display the content) ?? Commented Sep 7, 2017 at 10:36
  • i have enabled the code you provided but its not working properly, can you see the site again? and find the problem Commented Sep 7, 2017 at 11:01
  • You did not provide a link. Commented Sep 7, 2017 at 11:04
  • i have enabled your code but some links showing in the posts and featured image not showing on single post page site url: blog.biblesforamerica.org Commented Sep 7, 2017 at 11:07
0

Your previous developer haven't called featured image in listing page and not even in single page. Here is the code to add featured image and linked to single post page.

<div class="featured-image">
  <a href="<?phpthe_permalink(); ?>">
  <img src="<?php the_post_thumbnail_url( $size ); ?>" alt="" />
  </a>
</div>

You can place this code above or below the title where ever you want and you can style the way you want. Cheers!

6
  • thanks for reply umer shoukat , now i want to link the post in the post images that shows in the archive or posts list, how edit the (content.php is the loop being used to display the content) ?? Commented Sep 7, 2017 at 10:22
  • You can place same code with in the loop of your archive template or where ever you are listing your posts. Don't forget to mark answer as correct. :) Commented Sep 7, 2017 at 10:28
  • I am new to wordpress development, now clients dont wants to use featured image , they just asking with the current blog post list view page , if i click the image that should open the post page, i dont know how to Commented Sep 7, 2017 at 10:33
  • The solution is already there. I am so sorry but i can't help more than this. You're not capable of understand things. You better find a developer for this. it's a 5min task for correct person. Thanks Commented Sep 7, 2017 at 10:46
  • if i am not capable of understand things , as the senior developer you need to help Bro umer ? you should not blame not tease Commented Sep 7, 2017 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.