Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Darren Wilson 234 posts 622 karma points
    Mar 09, 2015 @ 18:32
    Darren Wilson
    0

    Blog entries on homepage

    Hi Folks,

    I'm using the Fanoe theme and trying to display the blog entries on a page other than the blog overview page. I've tried a number of things here to no avail - any ideas will be greatly appreciated!

    I'm using Umbraco 7 and the built in blog that comes with Fanoe.

    Thanks in advance.

    Darren

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 09, 2015 @ 18:47
    Jan Skovgaard
    0

    Hi Darren

    What approaches have you been trying? Could you share some code?

    /Jan

  • Darren Wilson 234 posts 622 karma points
    Mar 09, 2015 @ 20:15
    Darren Wilson
    0

    Hi Jan,

    I've tried a number of different approaches as listed on the forum here - XLST and macros. Some date from a few years back.

    This macro didn't work:

    @{IPublishedContent newsNode = Umbraco.Content(1081);}

    @foreach (var newsItem in newsNode .Children().Take(4))
        {
            @{
            if (@newsItem.HasValue("newsThumb"))
            {
                var mediaItem = Umbraco.TypedMedia(@room.GetPropertyValue("newsThumb"));
                <img src="@mediaItem.GetPropertyValue("umbracoFile")"  />
            }
        }
        <p><a href="@newsItem.NiceUrl()">@newsArticle.Name</a></p>
        <p>@newsItem.GetPropertyValue("newsDescription")</p>
    }

    Neither did this XLST

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
        <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"
      exclude-result-prefixes="msxml umbraco.library">


        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>
    <xsl:param name="MaxNoChars" select="190" />
    <xsl:template match="/">

      <xsl:for-each select="$currentPage//ancestor-or-self::doTextpage[@isDoc and showOnHomepage = '1']">    
      <div class="redPanel">
        <h2><xsl:value-of select="@nodeName" /></h2>
        <p><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(umbraco.library:Replace(current()/bodyText, '&amp;nbsp;', '')), $MaxNoChars, '...')" /></p>
        <p><a href="{umbraco.library:NiceUrl(@id)}"> <img src="/img/btnMore.png" alt="read more" tooltip="Read more" align="right" /> </a></p>
        </div>
        </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 09, 2015 @ 20:37
    Jan Skovgaard
    0

    Hi Darren

    Ok, but if you write something like this then it should work

    @{
       //Fetch the blogposts from a certain node id
       var blogPosts = Umbraco.Content(1081);
    
      foreach(var blogPost in blogPosts.Children()){
         @blogPost.Id <br />
      }
    }
    

    Hope this helps.

    /Jan

  • Darren Wilson 234 posts 622 karma points
    Mar 09, 2015 @ 22:45
    Darren Wilson
    100

    Hi Jan,

    A bit of experimentation and this works:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
       
        @{
       //Fetch the blogposts from a certain node id
       var blogPosts = Umbraco.Content(1081);

      foreach(var blogPost in blogPosts.Children()){
             
            <div class="date">@blogPost.CreateDate.ToLongDateString()</div>
            <h2><a href="@blogPost.NiceUrl()">@blogPost.Name</a></h2>       
            <p>@Umbraco.Truncate(blogPost.Introduction, 200, true)</p>
             
      }
    }
    Thanks for the pointer in the right direction!

    Darren

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 10, 2015 @ 07:10
    Jan Skovgaard
    0

    Hi Darren

    You're welcome - Good you got it working. I only rendered the ID since I was not sure what content you wanted to render yourself - But be aware that the above code can be fragile if the blogposts node is ever deleted since it relies on that the id exists - It's probably not likely that it will be deleted but it's just never safe to make assumptions - But the liberty to do so also depends on who the editor is and how often the content is edited etc. etc. etc.

    Just thought I would mention it - Happy coding! :)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft