To bring image in Recent blog post

Topics: General
Sep 22, 2011 at 5:28 AM

Hi,

I have added several blog post and added image with the blog post..I placed a recent blog post in content zone and applied css and kept layer as homepage...Title,tags,comments,summary is coming except the image

please see the link.. this is word press theme..i want to bring image like this in the home page.

http://www.freshthemes.com/demo/channel/

 

Thanks

selva

Coordinator
Sep 22, 2011 at 5:41 AM

You need to override the parts.common.body.summary.cshtml template. Here is the one that I'm using:

@{ 
    Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem;
    var bodyHtml = Model.Html.ToString();
    var more = bodyHtml.IndexOf("<!--more-->");
    if (more != -1) {
        bodyHtml = bodyHtml.Substring(0, more);
    }
    else {
        var firstP = bodyHtml.IndexOf("<p>");
        var firstSlashP = bodyHtml.IndexOf("</p>");
        if (firstP >=0 && firstSlashP > firstP) {
            bodyHtml = bodyHtml.Substring(firstP, firstSlashP + 4 - firstP);
        }
    }
    var body = new HtmlString(bodyHtml); 
}
<p>@body</p>
<p>@Html.ItemDisplayLink(T("Read more...").ToString(), contentItem)</p>

 


Sep 22, 2011 at 6:13 AM
Edited Sep 22, 2011 at 6:16 AM

hi bertrandleroy,

Thank you a lot..its great.Its working..its bringing the image...but its getting all the content..i want  the image and with the first 200 characters.

@{ 
Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem;
var bodyHtml = Model.Html.ToString();
var more = bodyHtml.IndexOf("<!--more-->");
if (more != -1) {
bodyHtml = bodyHtml.Substring(0, more);
}
else {
var firstP = bodyHtml.IndexOf("<p>");
var firstSlashP = bodyHtml.IndexOf("</p>");
if (firstP >=0 && firstSlashP > firstP) {
bodyHtml = bodyHtml.Substring(firstP, firstSlashP + 4 - firstP);
}
}
var body = new HtmlString(bodyHtml);
}
<p>@body</p>
<p>@Html.ItemDisplayLink(T("Read more...").ToString(), contentItem)</p>

please how to modify this code..please help me

Thanks
selva
Coordinator
Sep 22, 2011 at 6:19 AM

Then you'll have to modify it to suit your needs. Or you can use <P> tags to delimit paragraphs (it will only take the first) or use <!--more--> to specify where you want the cut to happen. the problem with 200 characters is that it can happen in the middle of a word or worse, a tag.

Sep 22, 2011 at 6:42 AM
Edited Sep 22, 2011 at 6:43 AM

Hi bertrandleroy,

I tried but i couldn't the output. i am new to this techonology ..please explain me briefly..it will be good and helpfull to me..please.....

Thanks

selva

Coordinator
Sep 22, 2011 at 6:56 AM

I'm sorry but I'm not sure how to make myself clearer. I've given two ways you can control where the cut occurs: either make sure that your content has paragraphs (P tags) or insert a <!--more--> into the HTML view of the content editor.

Sep 22, 2011 at 7:05 AM

Hi bertrandleroy,

I cleared that issue by using substring..Thank you a lot..I am insterested in this technology...but i am getting struck up some where in learning..please give some ideas..

Thanks

selva