WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Is there a way to number archive posts (17 posts)

  1. TransPersonal
    Member
    Posted 5 years ago #

    Is there any php code that I can use to number the post titles that appear in the archive section.

  2. MichaelH
    Member
    Posted 5 years ago #

    How would that number happen? A sequential number? Does the same number always have to be associated with the same post?

  3. whooami
    Member
    Posted 5 years ago #

    Is there any php code that I can use to number the post titles that appear in the archive section.

    Number how? random numbers? sequentuial numbers? fake numbers? chinese numbers? what?????

    Ive done both ascending and descending sequential numbering of posts, and included paging. It was quite easy to do.

  4. t31os
    Member
    Posted 5 years ago #

    I'm not sure how much it matters but i'd be interested to see an example of paged sequential numbering in the archive.

    Would you care to give an example whooami? :) Please :)

  5. whooami
    Member
    Posted 5 years ago #

    paged, ordinal numbering? youve never seen that????

  6. t31os
    Member
    Posted 5 years ago #

    First page

    1. post
    2. post

    Second page

    3. post
    4. post

    Yes have seen it, just not sure i remember seeing that behaviour in WP by default... or am i experiencing a terrible blonde moment?

  7. whooami
    Member
    Posted 5 years ago #

    it doesnt do it by default, no, youre right :)

  8. t31os
    Member
    Posted 5 years ago #

    So would you care to enlighten me on how you'd handle paging archive results as per my basic example above?...

    Seen lots of methods for paging (some beyond me), i'd be interested to see how you do it...

  9. whooami
    Member
    Posted 5 years ago #

    you should understand this :)

    <?php if (empty($paged)) { $my_post_count = 1;} else { $my_post_count = ($paged*$posts_per_page)-($posts_per_page-1); } ?>

    Mind you I pulled that out of a file I havent used in 2 years.

    I toyed with doing this again, when I redid v-i, and the code I used there was slightly different, I *think*..

  10. t31os
    Member
    Posted 5 years ago #

    I've not worked with $paged or $posts_per_page in WordPress.

    I assume they are global WP variables that track the page/post results, or count so to speak... so we don't end up on pages for no results etc...

    I'll check the codex...

    p.s. what's v-i? :)

  11. whooami
    Member
    Posted 5 years ago #

    v-i == my site.

    its really simple,

    take the above, add a little of this:

    <?php echo $my_post_count; $my_post_count++; ?>

    and youre off.

  12. t31os
    Member
    Posted 5 years ago #

    I've no need for numering archives yet myself, having only 10 or so posts, it seems a little pointless, but i'll bear the above in mind when need be...

    I'll let the OP have his thread back, i'm sure he has questions.... ;)

  13. TransPersonal
    Member
    Posted 5 years ago #

    I meant sequential numbers and no the same numbers don't always have to be associated with the posts, sorry if I wasn't clear earlier.

    Whooami:

    I tried adding this:

    <?php echo $my_post_count; $my_post_count++; ?>

    to my archives.php. And it works but for some reason the first post is not counted. Beginning from the second post the numbering starts. Also the numbers don't have a period after them , so now they are 1 2 3 instead of 1. 2. 3.

    sorry but the only php I know is copy pasting the code :(

  14. MichaelH
    Member
    Posted 5 years ago #

    Could reverse that:

    <?php $my_post_count++; echo $my_post_count; ?>

  15. TransPersonal
    Member
    Posted 5 years ago #

    Thanks MichaelH!

    That worked great now the numbering starting from the first post. Any idea though how I can get a period after each number, e.g. 1. 2. 3. ?

    Thanks for your help.

  16. MichaelH
    Member
    Posted 5 years ago #

    <?php $my_post_count++; echo $my_post_count . '.'; ?>

  17. TransPersonal
    Member
    Posted 5 years ago #

    Perfect, thanks a lot Michael!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.