Copied to clipboard

Flag this post as spam?

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


  • Eran 292 posts 436 karma points
    Aug 10, 2010 @ 00:49
    Eran
    0

    Howto Display most Popular posts?

    hello guys,

    i want to create macro that display the most commented posts (the most popular, only the top 5).

    i know how to count comments for posts:

     <xsl:variable name="numberofcomments" select="count(BlogLibrary:GetCommentsForPost($post/@id)//comment)"/>

    i know how to loop on 5 posts:

    <ul id="popular-posts">
         <xsl:for-each select="$currentPage/ancestor-or-self::node//node [string(data [@alias='umbracoNaviHide']) != '1' and @nodeTypeAlias='BlogPost']">
            <xsl:sort select="@createDate" order="descending" />
            <xsl:if test="position()&lt;= 5">
                      <li>
                    <xsl:variable name="text" select="umbraco.library:StripHtml(./data[@alias='bodyHeader'])" />           
                    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="umbraco.library:TruncateString($text,50,'...')" disable-output-escaping="yes"/></a>
                </li>                            
                </xsl:if>          
        </xsl:for-each>
    </ul>

    but i dont know how to connect the dots..

    Thanks!

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 10, 2010 @ 00:55
    Chriztian Steinmeier
    2

    Hi eran,

    You should be able to just use the number of comments as the sort option:

    <xsl:sort select="count(BlogLibrary:GetCommentsForPost(@id)//comment)" data-type="number" order="descending" />
    

    /Chriztian

    EDIT 2013-10-04: Added the data-type attribute which is needed to get the sorting correct.

  • Eran 292 posts 436 karma points
    Aug 10, 2010 @ 11:02
    Eran
    0

    Thanks, i will check it soon as possible (and will not forget to mark the solution).

    Eran.

  • Alexandru 112 posts 272 karma points
    Oct 04, 2013 @ 10:22
    Alexandru
    0

    Can you please share your final solution to this? I am also trying to get this to work on my blog.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 04, 2013 @ 12:31
    Chriztian Steinmeier
    2

    @Alexandru I've updated my answer to include the missing data-type attribute

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Oct 04, 2013 @ 12:32
    Alexandru
    0

    Cheers!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies