ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Order by date and view_count_one

July 02, 2008 5:05pm

Subscribe [1]
  • #1 / Jul 02, 2008 5:05pm

    sv

    21 posts

    Moderator’s note: Moved to Howto.

    I am trying to find a way to display a list of entries sorted by the month they were published and then the number of views for each article in descending order…

    JUNE 2008
    Article Z (234)
    Article X (202)
    Article Y (123)

    MAY 2008
    Article B (405)
    Article C (309)
    Article A (124)

    I can do this by calling each month separately and ordering by view_count_one, but that leads to extra code for each month.

    When I try to simplify the code like this, using the {date_heading} tag and calling multiple “orderby” commands…

    {exp:weblog:entries weblog="whatever" orderby="date|view_count_one" sort="desc|desc" year="2008" rdf="off" dynamic="off"}
    {date_heading display="monthly"}

    {entry_date format="%F %Y"}

    {/date_heading}
    {title} ({view_count_one})
    {/exp:weblog:entries}

    ...I get only halfway. The entries are sorted by month, but within each month they are also sorted by date, not by view_count_one.

    I suspect this is a logic problem. Any ideas?

  • #2 / Jul 02, 2008 5:33pm

    grantmx

    1439 posts

    This is totally untested and just a stab at it, but try adding a second weblog:entires tag just to sort the view count titles. Like so:

    {exp:weblog:entries weblog="whatever" orderby="date" year="2008" rdf="off" dynamic="off"}
    
    {date_heading display="monthly"}
    <h4>{entry_date format="%F %Y"}</h4>
    <p>{/date_heading}</p>
    
    <p>{exp:weblog:entries weblog="whatever" orderby="view_count_one"}<br />
    <a href="http://{comment_entry_id_auto_path}">{title}</a> ({view_count_one})<br />
    {exp:weblog:entries}</p>
    
    <p>{/exp:weblog:entries}

  • #3 / Jul 02, 2008 10:08pm

    sv

    21 posts

    No, that does not work. It throws the display into some sort of endless loop, repeating the last three months’ of entries.

  • #4 / Jul 03, 2008 3:52am

    Justin Hurlburt

    344 posts

    Greetings,

    In lieu of giving the answer away easily, here is a snippet, tip, and parameter that might help out.

    I see a tag that only fires monthly, and my little friend embed:

    {embed="group/template" year="{entry_date format="%Y"}" month="{entry_date format="%n"}"}
  • #5 / Dec 17, 2008 4:39pm

    FortySeven Media

    130 posts

    Very cool, but what if I’m using the display by hourly date heading and want to order my titles alphabetically under that? That parameter doesn’t seem to work. Any ideas?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases