Having trouble with newspaper type theme in BE.Net

Topics: Controls
Jul 7, 2012 at 10:16 AM
Edited Jul 7, 2012 at 10:33 AM

I am porting a Wordpress theme to BE.Net. The Html portion of it is no trouble but where I am having a problem is in showing the image before the post a la WordPress. Using the informtation here http://blogengine.codeplex.com/discussions/348049 and at http://www.blogenginewall.com/post/2011/03/18/Display-Images-With-Posts-On-BlogEngine-Front-Page.aspx I can show the image and using the CSS in Wordpress make it small. But I end with a image being duplicated as BE.Net retrieves the Post Description which has the image in it. So i need to grab just the pos Description after the image. Any thoughts?

 

As a visual aid I want:

 IMAGE Thumbnail via CSS
 ----------------------------
 TITLE
 ----------------------------
 POST Desc (text)
 ---------------------------- 

 

But I end up with

 IMAGE thumbnail via CSS
 ----------------------------
 FULL SIZE IMAGE IN POST DESCRIPTION
 ----------------------------
 TITLE
 ----------------------------
 POST Desc (text)
 ----------------------------

Jul 7, 2012 at 12:24 PM
Edited Jul 7, 2012 at 12:38 PM

Just to clarify, you want the thumbnail to show in post lists (when viewing as excerpts) but not when viewing the full post ( or single post)?

Going on that assumption, in the PostView.ascx (and assuming it's not a razor theme) are you checking the settings, for example:

 

<%if(this.ShowExcerpt) { %>
  <!--Code to show thumbnail-->
<%} %>
Jul 11, 2012 at 3:09 AM

Hi Andy

I solved it. 

I use the following to grab the image:

    public string getImage(bool ShowExcerpt, string input)
    {

        if (!ShowExcerpt || input == null)
            return "";

        string pain = input;
        string pattern = @"<img(.|\n)+?>";

        System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, pattern,

        System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);

        if (m.Success)
        {
            string src = getSrc(m.Value);
            string img = string.Format("<div class='thumb'><div><img {0}  /></div></div>", src);
            return img;
        }
        else
        {
            return "";
        }
    }

I use the following to strip out the image from the excerpt and just return the text:

   public string getSubstringDesc()
    {
        string pattern = @"<img.*?src="".*?"".*?>";

        System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(Post.Description, pattern,

        System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);

        if (m.Success)
        {
           string l = m.Value;
           string s = Post.Description;
           s = s.Replace(l, "");
           return s;
        }
        else
        {
          return Post.Description;
        }
    }

Jul 11, 2012 at 2:36 PM

Glad you're sorted.

Just for general info, this is quite a robust and efficient regex for finding img tags.

@"<\s*img\b[^>]*>

Which can be shortened to

@"<img\b[^>]*>"

Since both Windows Live Writer and TinyMCE never have space after the opening tag.