• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Get the total number of posts in the blog

Contributor ,
Sep 03, 2015 Sep 03, 2015

Copy link to clipboard

Copied

The How-tos article outlines how to

List top posts by number of comments

but with the displayed code we just can't get to work....something seems to missing

Has anybody implemented it? and/or could post the complete code?

Thanks in advance

Hartmut

TOPICS
Developer

Views

455

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Sep 04, 2015 Sep 04, 2015

Hi Mihai,

Thanks for your reply and your directions

We had a deeper look into it and it seems that the <p> </p> marks are not the issue, but whenever an image (as it is often the case in blog posts), or generally any other html tag, is partially included in the 60 character truncated body, the sorting script breaks.

The <p>{{ i.body | truncate:60, "..." }}</p>

could be replaced by

{{ i.body | strip_html | truncate:60, "..." }} // delete all html markup, then truncate to 60 char

or

<p>{{ i.metaDescript

...

Votes

Translate

Translate
Adobe Employee ,
Sep 03, 2015 Sep 03, 2015

Copy link to clipboard

Copied

Hey Hartmut,

What specifically doesn't work, the sorting or the rendering of the blog posts?

Please make sure you load jQuery before the script if you put it inline, if not, then add the script to an external file that's loaded after jQuery.

Is it possible you can share the link?

Thanks,

Mihai

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 03, 2015 Sep 03, 2015

Copy link to clipboard

Copied

Hi Mihai,

The sorting seems to be the problem

Below, please see the code on page: Blog posts by # of comments

Thanks

<!DOCTYPE html>

<html>

    <head>    

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

     

        <title>Blog posts by # of comments</title>

        <meta name="description" content="Blog posts by # of comments" />

</head>

    <body>

{module_blog render="item" filter="item" itemId="8197" collection="myBlog" template=""}

{% for b in myBlog.items -%}

    {module_blogpostlist render="collection" blogId="8197" rowCount="{{ b.totalPosts }}" collection="mostCommented" template=""}

     

    {% if mostCommented.items -%}

    <!-- BEGIN MOST TALKED ABOUT -->

    <h2>Most Talked About</h2>

    <div id="blogpostlist" style="display:none">

        {% for i in mostCommented.items -%}

        <div data-comment-number="{{ i.commentsCount }}" class="postitem">

            <div class="col-md-3" style="font-size:50px;">

                {{ i.commentsCount }}

            </div>

            <div class="col-md-9">

                <h3><a href="{{ i.url }}">{{ i.title }}</a></h3>

                <p>{{ i.body | truncate:60, "..." }}</p>

            </div>

        </div>

        {%endfor%}

    </div>

    <!-- END MOST TALKED ABOUT -->

    {%endif%}

{%endfor%}

     

             

<script type="text/javascript">

        // Set a variable to the wrapper div where your list items reside

        var $wrapper = $('#blogpostlist');

        // Set a variable to the following string for shorter code

        var $attr = 'data-comment-number';

        // Find the elements in the wrapper that contain the postitem class and sort them

        var sortedPosts = $wrapper.find(".postitem")

                                  .sort(function (a,b) {

            return b.getAttribute($attr) - a.getAttribute($attr);

        })

        // Clear the elements in the wrapper and then show it

        $wrapper.empty()

                .show();

        // For this example we want only 3 posts and let's put back the data in the wrapper using appendTo

        sortedPosts.slice(0,3)

                   .appendTo($wrapper);

</script> 

     

     

     

    </body>

</html>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Sep 03, 2015 Sep 03, 2015

Copy link to clipboard

Copied

Hi again,

Try replacing:

<p>{{ i.body | truncate:60, "..." }}</p>

with

{{ i.body | truncate:60, "..." }}


and check the post content as there seem to be some issues with that which wrecks the html.


E.g view-source:http://www.eworkswsi.com.cy/Test%20pages/blog-post-by-comments.html

Check line 213


M.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 04, 2015 Sep 04, 2015

Copy link to clipboard

Copied

Hi Mihai,

Thanks for your reply and your directions

We had a deeper look into it and it seems that the <p> </p> marks are not the issue, but whenever an image (as it is often the case in blog posts), or generally any other html tag, is partially included in the 60 character truncated body, the sorting script breaks.

The <p>{{ i.body | truncate:60, "..." }}</p>

could be replaced by

{{ i.body | strip_html | truncate:60, "..." }} // delete all html markup, then truncate to 60 char

or

<p>{{ i.metaDescription }}</p>  // use the posts metadescription

Thanks

Hartmut

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Sep 04, 2015 Sep 04, 2015

Copy link to clipboard

Copied

LATEST

Hi Hartmut,

That's true, will modify the docs to use the strip_html filter.

Thanks,

Mihai

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines