How to display an image before post title?

Topics: Controls, Themes
Mar 9, 2012 at 8:03 PM

I want to display small images before page titles. Is there any way?

Mar 9, 2012 at 9:23 PM

This post might help get you started.

Mar 10, 2012 at 9:52 AM

It discusses of putting images in the post and not what I desire. I want to prefix post title with an image.

Mar 10, 2012 at 11:27 AM
Edited Mar 10, 2012 at 11:39 AM

Yes it does and it shows one way of inserting images into posts, it's a good start. The exact placement of the images is up to you.

Take the Standard theme as an example, in the theme folder you have the file PostView.ascx, this file controls what you see in your posts.

<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="false" Inherits="BlogEngine.Core.Web.Controls.PostViewBase" %>
//You could add something like this
<script runat="server">

protected string getMyImage()
{       
    //code that returns HTML markup for my image as a string
    //for whatever the image is
}

</script>
<div class="post xfolkentry" id="post<%=Index %>">

  /**** Image placement here before the heading ****/

  <% getMyImage()%>  

  /**** Method body for getMyImage() can be added with script tags or in code behind file ****/

  <h1><a href="<%=Post.RelativeLink %>" class="taggedlink"><%=Server.HtmlEncode(Post.Title) %></a></h1>
  <span class="author">by <a href="<%=VirtualPathUtility.ToAbsolute("~/") + "author/" + BlogEngine.Core.Utils.RemoveIllegalCharacters(Post.Author) %>.aspx"><%=Post.AuthorProfile != null ? Post.AuthorProfile.DisplayName : Post.Author %></a></span>
  <span class="pubDate"><%=Post.DateCreated.ToString("d. MMMM yyyy HH:mm") %></span>
  
  <div class="text"><asp:PlaceHolder ID="BodyContent" runat="server" /></div>
  <div class="bottom">
    <%=Rating %>
    <p class="tags">Tags: <%=TagLinks(", ") %></p>
    <p class="categories"><%=CategoryLinks(" | ") %></p>
  </div>

  <div class="footer">    
    <div class="bookmarks">
      <a rel="nofollow" title="Index <%=Index %>" target="_blank" href="http://www.dotnetkicks.com/submit?url=<%=Server.UrlEncode(Post.AbsoluteLink.ToString()) %>&amp;title=<%=Server.UrlEncode(Post.Title) %>">Submit to DotNetKicks...</a>
    </div>
    
    <%=AdminLinks %>
    
    <% if (BlogEngine.Core.BlogSettings.Instance.ModerationType == BlogEngine.Core.BlogSettings.Moderation.Disqus)
       { %>
    <a rel="nofollow" href="<%=Post.PermaLink %>#disqus_thread"><%=Resources.labels.comments %></a>
    <%}
       else
       { %>
    <a rel="bookmark" href="<%=Post.PermaLink %>" title="<%=Server.HtmlEncode(Post.Title) %>">Permalink</a> |
    <a rel="nofollow" href="<%=Post.RelativeLink %>#comment"><%=Resources.labels.comments %> (<%=Post.ApprovedComments.Count %>)</a>   
    <%} %>
    </div>
</div>