• Resolved johngoold

    (@johngoold-1)


    A site I’m working on (https://stjohnsretiredcitizens.org) has images embedded in page titles. This works fine on ALL pages except the “News” page (which is the posts page). The image simply doesn’t show on the posts page (blog page?).

    I have also tried using the Featured Image. Again, this works fine on all pages except the posts page.

    I don’t really want to hack this to make it work. I have a child theme, but almost no CSS over-rides.

    Any ideas? This appears to be deliberate rather than a bug (i.e. it’s a particular two-column style with a right sidebar).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter johngoold

    (@johngoold-1)

    Part of why I’m having trouble resolving this issue is because of terminology and the way files are named, which sometimes seems (to me) to be contradictory or conflated.

    Here are my personal definitions of some terms, then I’ll ask my opening post question in different terms:

    Home Page (or just home) — the first page someone sees when surfing to your domain (a.k.a. Landing Page).

    Front Page — same as Home Page — I’m not sure this lines up with the WordPress Team’s definition (if not, what is their definition?).

    Posts Page (or blog page) — a page that displays your blog posts.

    The Home Page can also be the Posts Page, but doesn’t have to be (in my case, it is NOT).

    So, I have a static Front page and a separate page designated as the Posts page.

    Problem: The Posts page does not display its Featured Image. It also appears to strip any HTML tags from the Page Title (although manually browsing the database with phpMyAdmin shows the tags are there).

    [edit] Just found this statement in the template hierarchy document: “home.php
    The home page template, which is the front page by default. If you use a static front page this is the template for the page with the latest posts.”

    I’ll see if I can fix the behaviour by creating a home.php template file (though this is totally counter-intuitive to me ?? )

    • This reply was modified 7 years, 6 months ago by johngoold.
    Thread Starter johngoold

    (@johngoold-1)

    I have a solution to this problem, but am not ecstatic about it (it doesn’t use a WP function to obtain the URL of the Featured Image (and, in fact, because of that, I removed the featured image from the posts page).

    I copied the twentyseventeen header.php file to my child theme. In that file, twentyseventeen has the following code:

    <?php
    // If a regular post or page, and not the front page, show the featured image.
    if ( has_post_thumbnail() && ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) ) :
        echo '<div class="single-featured-image-header">';
        the_post_thumbnail( 'twentyseventeen-featured-image' );
        echo '</div><!-- .single-featured-image-header -->';
    endif;
    ?>

    Just after the opening PHP tag, I inserted the following code:

    // 2017-05-15 JRG show featured image on home page
    if ( is_home() && ! is_front_page() ):
        echo '<div class="single-featured-image-header">';
        echo '<img src="https://cornerstonehousingsociety.org/wp-content/uploads/2017/05/news.png" alt="" class="aligncenter" />';
        echo '</div><!-- .single-featured-image-header -->';
    endif;

    The twentyseventeen code uses the function has_post_thumbnail() which fails rather miserably when invoked on the posts page (and it doesn’t work when a single post is being displayed, which it appears intended to do). Note: the function twentyseventeen_is_frontpage() is a test for the “front page”, excluding the “home page”. The test I coded is almost the opposite (the home page unless it is the front page).

    Forgot to mention: The URL in my code is just a test site. Obviously, if you want to use this code yourself, you would need to use an appropriate URL for your img tag “src”.

    • This reply was modified 7 years, 6 months ago by johngoold. Reason: Afterthought
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Featured Image or Image in Title on POSTS Page’ is closed to new replies.