• 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.

Viewing 13 replies - 1 through 13 (of 13 total)
  • 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 . ")";

    Thread Starter Aracelys

    (@aracelys)

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

    Any idea why?

    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!

    Thread Starter Aracelys

    (@aracelys)

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

    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.

    Thread Starter Aracelys

    (@aracelys)

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

    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.

    Thread Starter Aracelys

    (@aracelys)

    the code get invoked within post pages only

    Ex: is_single()

    Sorry I’m new to all this ??

    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)?
    Thread Starter Aracelys

    (@aracelys)

    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…

    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) ?

    Thread Starter Aracelys

    (@aracelys)

    yes ??

    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

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Current post number?’ is closed to new replies.