Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I looked into this – the [loop] cannot sort by date of last comment, but maybe you can achieve the result you want using [comments]. I added a couple parameters in the newest plugin update.

    For example, to list 5 posts sorted by date of last comment:

    [comments count="5"]
      [comment link]
    [/comments]

    This will display each post title linked to the comment. For more detailed control..

    [comments count="5"]
      <a href="[comment url]">[comment title]</a>
    [/comments]

    Please refer to the documentation, under Settings -> Custom Content -> Comments.

    Thread Starter arniarni

    (@arniarni)

    Hi,

    May be my question was not clear.
    I have a list of posts (loop) sorted by date or by title etc. I need display this list sorted by date of last comment. In this way the post with nearest date and time of comment will on top position of list, next – on second…

    Your example in loop can add the link to last comment in each post. It is great, thaks for this hint, but not enough.

    Now I use next structure of code (with your link) where I can display date, time and link of last comment in each post but don’t uderstand how can sort posts by this date and time:

    [loop type="post" category="forum" order="DESC" orderby="date" cache="true" update="true"]
       [field title-link]
       Posted: [field date] | Updated: [field modified]
       No of comments: [comment count]
       Last: [comments count="1"][comment date] <a href="[comment url]">Link</a>[/comments]
    [/loop]

    Regards,
    Arni

    Plugin Author Eliot Akira

    (@miyarakira)

    Yes, I see what you mean – you’re already using the loop, and would like to sort by comment date. Ideally, it would be nice if there was a simple parameter: orderby="comment-date".

    The loop uses a native WordPress way to query posts, and they don’t offer this functionality of sorting by comment date. What would be necessary is to get all posts, and sort them manually before the loop starts. I’ll look into putting this together for the next update.

    Thread Starter arniarni

    (@arniarni)

    it would be great. Thank you.

    Regards,
    Arni.

    Plugin Author Eliot Akira

    (@miyarakira)

    In the latest update, I added a parameter to sort by comment date.

    [loop type="post" orderby="comment-date"]
      [field title]
      [comments count="1"]
        [comment title] - [comment date]
      [/comments]
    [/loop]

    Please let me know how it works for you.

    Thread Starter arniarni

    (@arniarni)

    Hello,

    Great! It works!
    Thank you! Very nice! This question is closed.

    Is it possible to solve the second question about comment link (I asked above)? Posts have same parameter [field title-link] but comments haven’t same ability. Will be useful when excerpt of comment would have an own link to this comment in loop.
    For example: now I use this code:
    [comment content length="100"]
    but want to see this content with link and shortcode might be as example below:
    [comment content-link length="100"]
    Can you look for this feature?

    Regards,
    Arni

    Plugin Author Eliot Akira

    (@miyarakira)

    Do you mean you would like to the whole excerpt to be a link? So, a shorter version of:

    <a href="[comment url]">[comment content length="100"]</a>

    Sure, I can add that in the next update.

    Thread Starter arniarni

    (@arniarni)

    Wow, great! It works! I wrote about this effect.
    Thank you! But if it is not hard, add the parameter to shortcode, it will be easier for using.

    Plugin Author Eliot Akira

    (@miyarakira)

    I added this in the new update. ??

    Similar question:

    I have a [-loop] within a [loop] which works fine. The outer loop is for cycling through “research areas” and the inner loop is “publications.” So in the inner [-loop], I am pulling the list of publications for each research area. The problem is that the list of publications generated by the inner [-loop] are not sorting properly according to their “date_published” custom field. BTW, sorting worked fine in another page where the query involved a single [loop].

    p.s. i am using [c] together with easy bootstrap shortcode. below is my page”

    [loop type="research_area" ]
    [ebs_panel style="panel-default" class="ceage_projects"]
      [ebs_panel-header]
        [field title]
      [/ebs_panel-header]
    
      [ebs_panel-content]
             [ebs_table width="100%" style =" table-hover" responsive ="false" class="presentation_table"]
               [ebs_table_head]
                 [ebs_th_column]Date[/ebs_th_column]
                 [ebs_th_column]Publication Title[/ebs_th_column]
               [/ebs_table_head]
               [ebs_table_body]
                [pass field_loop="connected_publications"]
                 [-loop type="publication" id="{FIELD}" orderby="meta_value_num" key="publication_date" order="DESC"]
                   [ebs_table_row]
                      [ebs_row_column][field publication_date date_format="m/Y"][/ebs_row_column]
                      [ebs_row_column]<a href="[field url]">[field title]</a> </br> &lsqb;[field type]&rsqb;[/ebs_row_column]
                   [/ebs_table_row]
                 [/-loop][/pass]
               [/ebs_table_body]
             [/ebs_table]
      [/ebs_panel-content]
    [/ebs_panel]
    [/loop]
    Plugin Author Eliot Akira

    (@miyarakira)

    I see, this is because of [pass field_loop] – it takes a comma-separated list in the field, and passes each item separately, in the order that is listed. So, there is one loop created per item.

    Could you try the following?

    [pass field="connected_publications"]
      [-loop type="publication" id="{FIELD}" ...]
        ...
      [/-loop]
    [/pass]

    This will pass the whole field to the loop, which should then order them by the specified parameters.

    Eliot sir!

    Works! – just like you said. Thank you for the prompt response.

    Plugin Author Eliot Akira

    (@miyarakira)

    Great, I’m glad to hear it. ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Sorting in posts loop’ is closed to new replies.