Forum

Thread tagged as: Question

Help with code

I'm having a problem upgrading my template for the new Blog app. Everything is working fine, except for image resize and cropping. Here is my code. What have I done wrong?

post.html code

<article class="h-entry">
    <h1>
        <a href="<perch:blog id="postURL" type="hidden" />" rel="bookmark" class="p-name">
            <perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" />
        </a>
    </h1>
    <p class="meta">
        <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>
        <perch:if exists="authorGivenName">
            by <span class="p-author h-card"><perch:blog id="authorGivenName" type="hidden" /> <perch:blog id="authorFamilyName" type="hidden" /></span>
        </perch:if>    
        <perch:categories id="categories" set="blog" label="Categories" display-as="checkboxes">
            <a href="archive.php?cat=<perch:category id="catSlug" type="slug" />" class="p-category">
                <perch:category id="catTitle" type="text" />
            </a>
        </perch:categories>

    </p>
    <perch:if exists="image">
        <div>
            <img src="<perch:blog id="image" type="image" width="540" height="360" crop="true" label="Image" order="4" />" alt="<perch:blog id="postTitle" />" />
        </div>
    </perch:if>
    <div class="description e-content">
        <perch:blog id="postDescHTML" type="textarea" label="Post" order="2"  html="true" editor="redactor" size="xxl autowidth" required="true" />
    </div>
</article>
<perch:blog id="excerpt" type="textarea" label="Excerpt"  html="true" editor="redactor" order="3" suppress="true" size="s" />
<perch:blog id="image" type="image" width="50" height="50" crop="true" suppress="true" />

post_in.html

<perch:before>
<ul class="hfeed"></perch:before>
    <li class="hentry">
        <h2><a href="post.php?s=<perch:blog id="postSlug" />" rel="bookmark" class="entry-title"><perch:blog id="postTitle" /></a></h2> 
       <perch:if exists="image"><img src="<perch:blog id="image" type="image" width="540" height="360" crop="true" />" alt="<perch:blog id="postTitle" />" /></perch:if>
        <p class="entry-published date"><perch:blog id="postDateTime" format="%B %d %Y" /></p>
        <div class="description entry-summary">
        <perch:blog id="excerpt" encode="false" />
    <br />
    <br />
        </div>
    </li>
<perch:after>
    </ul>

    <perch:if exists="paging">
        <div class="paging">
            Page <perch:blog id="current_page" /> of <perch:blog id="number_of_pages" />
            <perch:if exists="not_first_page">
                <a href="<perch:blog id="prev_url" encode="false" />">Previous</a>
            </perch:if>
            <perch:if exists="not_last_page">
                <a href="<perch:blog id="next_url" encode="false" />">Next</a>
            </perch:if>
        </div>
    </perch:if>
</perch:after>
Kelly Crossley

Kelly Crossley 0 points

  • 6 years ago

I've found the image needs to be larger in both respects to the height and width for this to work correctly.

If I upload a 500x300 image which is set in the template to be 600x200 I'll end up with a 500x200 image.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What result are you getting?

Weird. I just tried uploading the original image again, which is 960 x 636, and It's working fine. But, while we're on the subject does my code look okay?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

The image template tag looks fine.