Forum

Thread tagged as: Question, Problem, Blog

Image in blog post not showing.

For some reason images I add to blog posts are not displaying, wondering if someone could point out to me why this is the case as I can't work it out. I have images in a freeform post template, using blocks, that are working and as far as I can see I've done nothing different.

I also have an additional field with no labels, that seems to display any tags that I've applied to a post. Immediately below it is a field labelled Tags that I add the tags into.

This is my post.html.

<article class="h-entry">

    <div class="page-header cover <perch:if exists="image"><perch:blog id="theme" label="Cover Photo Colour" type="select" options="dark,light" order="3" />" style="background-image: url(<perch:blog id="image" type="image" label="Cover Photo" order="2" />);background-size: cover;"</perch:if>">
    <div class="container question-title">
        <h1><perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" /></h1>
    </div>
</div>

<div id="intro">
    <div class="container">
    <perch:blog id="excerpt" type="textarea" label="Excerpt" markdown="true" order="5" size="s" />
    </div>
</div>

<div id="content" class="container">

    <perch:if exists="post_image"><img src="<perch:blog id="image" type="image" width="500" crop="true" />" /></perch:if>

    <div class="description e-content">
        <perch:blog id="postDescHTML" type="textarea" label="Post" editor="markitup" markdown="true" size="xxl autowidth" required="true" />
    </div>

    <div class="author">

    <perch:if exists="author_image">
        <img src="<perch:blog id="author_image" type="image" label="Image" />" width="60" />
    </perch:if>

    <p class="meta">Posted 

        <perch:if exists="authorGivenName">
            by <a href="/blog/archive.php?author=<perch:blog id="authorSlug" type="text" />"><span class="p-author h-card"><perch:blog id="authorGivenName" type="hidden" /> <perch:blog id="authorFamilyName" type="hidden" /></span></a>
        </perch:if>

        on <time class="dt-published" datetime="<perch:blog id="postDateTime" type="date" label="Date" time="true" format="Y-m-d H:i:s" divider-before="Meta information" />"><perch:blog id="postDateTime" type="date" time="true" format="%d %B %Y" /></time>.</p>

        <p>This post has been tagged <perch:blog id="postTags" /></p>


    </div> <!-- Close Author -->
</div> <!-- Close Container -->
</article>
Phil Bowell

Phil Bowell 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which of the images aren't working, and at what point do they fail?

The Post image isn't displaying. I can see the image upload in the new post screen, and add the image but they don't display in the post.

Drew McLellan

Drew McLellan 2638 points
Perch Support

On the page itself? What output do you get?

Does editing work ok?

Yeh, the image doesn't display on the post itself. If I go into the edit post screen I can see the image is attached.

This is the page source, it's as if it's not seeing the image is there.

<article class="h-entry">

    <div class="page-header cover ">
    <div class="container question-title">
        <h1>This is a post</h1>
    </div>
</div>

<div id="intro">
    <div class="container">
    <p>This is the excerpt</p>
    </div>
</div>

<div id="content" class="container">

    <div class="description e-content">
        <p>This is the content.</p>
    </div>

    <div class="author">

        <img src="/perch/resources/img2117.jpg" width="60" />

    <p class="meta">Posted 

            by <a href="/blog/archive.php?author=phil-bowell"><span class="p-author h-card">Phil Bowell</span></a>

        on <time class="dt-published" datetime="2015-05-26 13:46:00">26 May 2015</time>.</p>

        <p>This post has been tagged </p>

    </div> <!-- Close Author -->
</div> <!-- Close Container -->
</article>

The image should appear above <div class="description e-content"> but for some reason isn't.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

<perch:if exists="post_image"><img src="<perch:blog id="image" type="image" width="500" crop="true" />" /></perch:if>

You are checking for a image with an id of post_image.

The image actually has an id of image.

I think Perch is doing what you asked it to do.

Ah thanks Rachel. Silly mistake.

I've just discovered how I made it though. The author section at the bottom is showing fields in the edit post screen, which I was confusing with the post image.

<div class="author">

    <perch:if exists="author_image">
        <img src="<perch:blog id="author_image" type="image" label="Author Image" />" width="60" />
    </perch:if>

    <p class="meta">Posted 

        <perch:if exists="authorGivenName">
            by <a href="/blog/archive.php?author=<perch:blog id="authorSlug" type="text" />"><span class="p-author h-card"><perch:blog id="authorGivenName" type="hidden" /> <perch:blog id="authorFamilyName" type="hidden" /></span></a>
        </perch:if>

        on <time class="dt-published" datetime="<perch:blog id="postDateTime" type="date" label="Date" time="true" format="Y-m-d H:i:s" divider-before="Meta information" />"><perch:blog id="postDateTime" type="date" time="true" format="%d %B %Y" /></time>.</p>

        <p>This post has been tagged <perch:blog id="postTags" /></p>


    </div> <!-- Close Author -->

There is one for the author image, a field which I can't work out where it's coming from and also one for the tags (with another labelled tags underneath it). This is something that I've obviously done, could you explain why this is happening and what I should be doing so this doesn't happen please?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

I don't understand what you mean? Your template is under your control, we don't add anything to it and if you want to remove things from the default you can just remove them.

Sorry, I'm not being very clear.

That piece of code is pulling in information about the post to display at the bottom of the page. It looks like this:

Post Author

It shows the author image, author name, date the post was created and any tags (although there are none on this post). So it seems to be working. However, at the bottom of the edit post screen I have this:

Perch post edit screen

It's giving me the fields for the information that's being pulled in automatically and I don't understand why. I wondered if you could help me to understand it please?

Alternatively, is there a better way of getting this information and displaying it at the bottom of the post as this doesn't do exactly what I wanted (i.e. the date and tags are not links)? I had previously been trying to do it with a template but I couldn't get it to work (See this thread).

I'm new to Perch, and basically anything that's not html/css, so I'm still learning how it works and best practices etc.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, ok. Any Perch tags in the master template (post.html in this case) are turned into edit fields. The Blog app should really know about those author fields and ignore them, so we'll look into that.

You can set type="hidden" on the tags to hide them from the edit form.

Thanks Drew, I'll add that in.