WordPress.org

Ready to get started?Download WordPress

Forums

Current post number? (14 posts)

  1. Aracelys
    Member
    Posted 3 years ago #

    So I would like to show the post number of the category.

    Ex:

    The CAR category have 34 post.
    Let say you click post #3.
    Now you viewing post #3.
    So!,. I would like to display something like this: ( 3 of 34 )

    Note: I would like to know how to display the #3 in the post page.

    I hope this makes sense.

  2. hedronist
    Member
    Posted 3 years ago #

    WP_Query has lots of goodies for you. While you are in The Loop you could do something like:

    print "(" . ($wp->query->current_post+1) ." of ". $wp_query->post_count . ")";

  3. Aracelys
    Member
    Posted 3 years ago #

    but with $wp->query->current_post+1,. I'm always getting ( 1 of 34 ) as result...

    Any idea why?

  4. hedronist
    Member
    Posted 3 years ago #

    It's because ... I can't type! :-( The variable name is $wp_query, not $wp->query.

    That should have been: $wp_query->current_post+1

    Sorry about that!

  5. Aracelys
    Member
    Posted 3 years ago #

    still giving me ( 1 ) as result :-/....

  6. hedronist
    Member
    Posted 3 years ago #

    Where are you putting the code? As I said in my initial reply, this must be "in the loop" for it to work correctly. I just put the above code into twenty-ten's loop.php file at line 129 (which handles the default display of posts, specifically their "posted on" date) and it worked exactly as desired.

    For any more help you must provide more specific information: link to site, theme name, and file you are modifying.

  7. Aracelys
    Member
    Posted 3 years ago #

    I'm creating a plugin.
    So is in the plugin folder

  8. hedronist
    Member
    Posted 3 years ago #

    OK, but where is the code being invoked? The global variable $wp_query is only meaningful in certain contexts. For the values I am referencing, they only have meaning when the the_loop is active, nowhere else.

  9. Aracelys
    Member
    Posted 3 years ago #

    the code get invoked within post pages only

    Ex: is_single()

    Sorry I'm new to all this :(

  10. hedronist
    Member
    Posted 3 years ago #

    It's OK to be new at something. I'm new to WP myself (but not to programming) and I missed two important things about your question. That's why my initial answer caused so much confusion.

    1. It's the number of posts assigned a category you were looking for, and
    2. the post's number <i>within category</i> that you wanted.

    The first part is somewhat easier to solve than the second because, although a post can be in more than one category, a category has an unambiguous number of posts assigned to it.

    Questions:

    1. How do you determine a post's number-within-category? Is it by date? Reverse date? Some other ordering criteria?
    2. If a post is in more than one category, which one(s) do you choose for display purposes? All of them? Just the current one (if that can be determined)?
  11. Aracelys
    Member
    Posted 3 years ago #

    1) I determine the post number by date of posted.

    2) If a post is in more than one category I will choose all of them.

    Thanks a lot for your help...

  12. hedronist
    Member
    Posted 3 years ago #

    So #1 means <i>ascending</i> date order, right?

    Does #2 mean you want something like: Categories: Car Parts (3 of 35), Hub Caps (5 of 61), Left Turn Signals (1 of 2) ?

  13. Aracelys
    Member
    Posted 3 years ago #

    yes :D

  14. hedronist
    Member
    Posted 3 years ago #

    OK. Let's take this conversation to email (because I hate the editor in these forums) and we can post the final answer back here to finish this thread out. Contact me at peter at techbuddy dot us

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.