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.

Post "number"

June 24, 2010 5:56am

Subscribe [4]
  • #1 / Jun 24, 2010 5:56am

    beseku

    12 posts

    I’m trying to show the post number, (if I have 101 posts total, the latest post will be #101 - not the ID), within the weblog loop, which is paginated. Since I can’t figure out how to access the page variable outside of the paginate loop, how can I do this?

  • #2 / Jun 24, 2010 7:47am

    Wouter Vervloet

    758 posts

    Hi Ben,

    There’s a variable available called {absolute_count}. That will probably be what you’re looking for.

    Greetz,
    Wouter

  • #3 / Jun 24, 2010 8:19am

    beseku

    12 posts

    Hmm, {absolute_count} goes the wrong way, and there isn’t an {absolute_total} to subtract it from, as far as I know.

  • #4 / Jun 24, 2010 8:44am

    Wouter Vervloet

    758 posts

    What do you mean with “goes the wrong way”?

  • #5 / Jun 24, 2010 1:14pm

    Mark Bowen

    12637 posts

    You would probably need to use some PHP to get what you want :

    <?php
    $count = "{count}";
    $total_results = "{total_results}";
    $new_count = ($total_results - $count) + 1;
    echo $new_count;
    ?>

    You’ll need to turn on PHP parsing for the template in which you are doing this in and make sure it is in Output mode but that should hopefully do it for you.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #6 / Jun 25, 2010 1:45am

    beseku

    12 posts

    @Mark Bowen - {total_results} is only for the page you are on, so if you are paginating 20 entries, it will always say 20.

    @Wouter Vervloet - {absolute_count} gives the latest entry 1 and the oldest entry 101. I want it the other way around.

  • #7 / Jun 25, 2010 2:51am

    Wouter Vervloet

    758 posts

    If that’s the case, use Mark’s example and substitute {count} for {absolute_count}.

    <?php
      $count = "{absolute_count}";
      $total_results = "{total_results}";
      $new_count = ($total_results - $count) + 1;
      echo $new_count;
    ?>

    Greetz,
    Wouter

  • #8 / Jun 25, 2010 2:52am

    Focus Lab Dev Team

    1129 posts

    Ben

    I read this a few times over and also don’t understand what you’re trying to do. Can you provide a code sample to give some context to what you’re looking for?

  • #9 / Jun 25, 2010 5:23am

    beseku

    12 posts

    I want to display the following, imagine the list is paginated to show five posts, and there are 22 posts in total. The most recent is displayed at the top.I want to get the number in brackets.

    First Page:
    - “Post Written Today” (#22)
    - “Post Written Yesterday” (#21)
    - “Post Written 2 Days Ago” (#20)
    - “Post Written 3 Days Ago” (#19)
    - “Post Written 4 Days Ago” (#18)

    Second Page:
    - “Post Written 5 Days Ago” (#17)
    - “Post Written 6 Days Ago” (#16)
    - “Post Written 6 Days Ago” (#15)
    - “Post Written 7 Days Ago” (#14)
    - “Post Written 8 Days Ago” (#13)

    Third Page:
    - “Post Written 8 Days Ago” (#12)
    - “Post Written 9 Days Ago” (#11)
    - “Post Written 9 Days Ago” (#10)
    - “Post Written 10 Days Ago” (#9)
    - “Post Written 10 Days Ago” (#8)

    Fourth Page:
    - “Post Written 11 Days Ago” (#7)
    - “Post Written 12 Days Ago” (#6)
    - “Post Written 12 Days Ago” (#5)
    - “Post Written 15 Days Ago” (#4)
    - “Post Written 15 Days Ago” (#3)

    Fifth Page:
    - “Post Written 18 Days Ago” (#2)
    - “Post Written 19 Days Ago” (#1)

    Off the variables available, only {absolute_count} is ‘outside’ of pagination. In the example above, on all but the last page, {total_results} will show 5. On the last page it will show 2. You also cannot get access to the pagination variables, (not outside of {pagination} which affects the display).

    @ Wouter, I replied to Mark that {total_results} only shows the count per page. Why would using a different variable with it change that fact?

  • #10 / Jun 25, 2010 5:33am

    Focus Lab Dev Team

    1129 posts

    Ahh I see now.

    Check out this tiny Extension from Barrett Newton. It gives you a new variable for the absolute total results of the weblog:entries results.

    http://barrettnewton.com/site/products/absolute_total_results/

    You can take that variable (which will be the same for each entry) and subtract that entry’s count plus 1 thus giving you the number you need. Eg:

    {absolute_total_results} - {absolute_count} + 1

    First Page:
    - “Post Written Today” 22 - 1 + 1 = 22 (redundant, could be avoided with a conditional if desired)
    - “Post Written Yesterday” 22 - 2 + 1 = 21
    - “Post Written 2 Days Ago” 22 - 3 + 1 = 20
    etc


    It might be a bit convoluted but it should work. That being said, it’s 4am here and I may be overlooking an easier approach 😉

  • #11 / Jun 25, 2010 5:34am

    Wouter Vervloet

    758 posts

    Oh… sorry about that. You’ll need an add-on for that called Absolute Total Results.

    Edit: What Erik said…

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

ExpressionEngine News!

#eecms, #events, #releases