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.

How do I display the ordinal number of a post in a particular weblog?

July 19, 2008 7:47pm

Subscribe [3]
  • #1 / Jul 19, 2008 7:47pm

    rockbeatspaper

    9 posts

    I would like to list some meta data with each post from a specific weblog like so:

    * Post 1 of 4
    * Post 2 of 4
    * Post x of y, etc…

    So I want to know the position of each post within its corresponding weblog.

    Thanks for any help!!

  • #2 / Jul 19, 2008 8:10pm

    PXLated

    1800 posts

    If you are listing the entries in chronological order (by date), wouldn’t they be that way already so it would just be adding…
    Post {count} of {total_results}

  • #3 / Jul 19, 2008 8:15pm

    rockbeatspaper

    9 posts

    Yes, but {count} is only returning the order number from the query, not the order that it was posted

  • #4 / Jul 19, 2008 9:24pm

    PXLated

    1800 posts

    As mentioned though, if you are using the sort variable in the weblog:entries tag for chronological they’d be in the order by when they were posted, 1st, 2nd, etc., so the count should reflect that. Is there something I’m not understanding/getting.

  • #5 / Jul 20, 2008 1:22am

    rockbeatspaper

    9 posts

    Gotcha, that is what I thought too.  But no matter what sort order I put on the entries tag, the number that {count} renders is the same.

    You can see what I am trying to accomplish here:  http://thenew.c3greensboro.com

    Look in the two entries under the First Experiences area on the home page.  I am trying to work out the Experience No. X at the bottom of each entry.

    Thanks so much for your attention to this!!

  • #6 / Jul 20, 2008 3:48am

    PXLated

    1800 posts

    I see Experience $1 and #2 - Is not that correct?

  • #7 / Jul 20, 2008 4:52am

    rockbeatspaper

    9 posts

    No.  John and Britten Peele were entered into the database first, so they should be #1.  And then when I enter a third entry, John and Britten will fall off, Paul and Elizabeth Geisen should move to the right, and the new entry should display in the first spot as #3. (None of that is animation, just me describing what will take place when I have more than 2 entries in the DB)

  • #8 / Jul 20, 2008 5:19am

    PXLated

    1800 posts

    Ok, then there will be a problem as the {count} variable is based on what’s displayed and you’re displaying in descending order. So {count} won’t work, If you always have just the latest two, the count will always be #1 & #2 in the wrong sequence.
    —————
    There isn’t a standard tag way to do it that I know of. I believe you’d need to query the database for all entries by date/ascending and determine the number from that array for those two displayed entries. I don’t have any query mojo so don’t know how exactly you’d do it. The query wouldn’t be too bad with a few entries but once you get a lot it could be problematic because you have to get them all I believe.
    —————

    If you want to go that route, hopefully someone with some php or query skills will pop in.

  • #9 / Jul 20, 2008 5:26am

    PXLated

    1800 posts

    Another way I suppose would be to use a standard weblog:entries tag to get all entries and just not display it. Set it (css) to display hidden or none. Use the {total-results} from that as a variable for some php math. The two displayed entries will always be the total_results and total-1 if there are always just two displayed. A query is probably better though.

  • #10 / Jul 20, 2008 5:33am

    Ingmar

    29245 posts

    If you never delete an entry, it would be as simple as using the entry_id. Otherwise, you’d have to count all entry_ids smaller or equal to the current one. Makes sense?

    SELECT COUNT(entry_id) FROM exp_weblog_titles WHERE entry_id <= '{entry_id}' AND status <> 'closed'

    You’ll probably want to use the query module, and need to repeat that for every entry in your weblog:entries loop.

  • #11 / Jul 20, 2008 5:45am

    PXLated

    1800 posts

    Ingmar - Would that apply if you have multiple weblogs and you only need this for one of them?

  • #12 / Jul 20, 2008 5:57am

    Ingmar

    29245 posts

    Yes. Depending on your preferences, you could restrict the count to one weblog only, or count them all, but only have a subset of them displayed, like “entry #99”, “entry #103” and so on (entries 100 - 102 would be in a different weblog, not shown on this template).

    Basically, all you’d need to do is add another WHERE clause:

    ... WHERE entry_id <= '99' AND status <> 'closed' AND weblog_id = '3'
  • #13 / Jul 20, 2008 4:48pm

    rockbeatspaper

    9 posts

    Thanks for all the help guys, but let me be sure that I am explaining my issue correctly.  Here is my code block:

    {exp:weblog:entries weblog="firstexperiences" disable="member_data|pagination|categories|trackbacks" dynamic="off" limit="2"}
            <div class="experience trans-black-40 span-6{switch="| last"}">
              <a href="#" title="">{video}</a>
              <h4>{title}</h4>
    <p>          <a href="#" title="Watch it now">Watch it now ></a><br />
              {entry_date format="%m.%d.%y"}<br />
    Experience No. {entry_id}<br />
            </div> <!-- experience ends --><br />
            {/exp:weblog:entries}

    Right now, I am using {entry_id}, but obviously that is not going to render the results I am wanting.  The two entries that I have currently displaying on my dev site should be displaying as Experience No. 2 & Experience No. 1 (in desc order).  So when I add the next post in the firstexperiences weblog, the numbers should shift to Experience No. 3 & Experience No. 2 (again in desc respective order).

    No variation of {count} or query has worked so far, nor do I think it will.  I need to know, of the total number of entries in the firstexperiences weblog, the ordinal position of each post.  If the solution is always respective to the QUERY I am looping through, then I will ALWAYS get results such as 1 of 2 & 2 of 2.  But I needs positions relative to the order in the database, not the query result set.

    I hope that helps.

    Thank you again!

  • #14 / Jul 20, 2008 5:45pm

    Ingmar

    29245 posts

    Well, this is working fine for me, unless I completely misunderstood what you are looking for:

    {exp:weblog:entries weblog="default_site" status="not closed"}
       {exp:query sql="
          SELECT COUNT(entry_id) AS ordinal FROM `exp_weblog_titles` 
          WHERE entry_id <= '{entry_id}' AND status <> 'closed' AND weblog_id='1'"}
             entry #{ordinal} - entry_id: {entry_id} - {title} 
    
       {/exp:query}
    {/exp:weblog:entries}
  • #15 / Jul 20, 2008 6:26pm

    rockbeatspaper

    9 posts

    Ingmar…. you are a life-saver!!!

    Thank you, thank you!!

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

ExpressionEngine News!

#eecms, #events, #releases