• Resolved hasund

    (@hasund)


    Short:
    I want to create a variable that is assigned a different value for each post pulled from a query, so that I can append a specific text (dependant on the lists’ reversed chronological order) before each post title .

    Longer:

    I am using query_posts to display a list of five posts from a category. The reversed chronological order of these posts have a certain meaning, and for this reason I want to accompany each post-title with its own text, something like this:

    “third: post title by the author”
    “second: post title by the author”
    “first: post title by the author”
    etc

    What I could do is to do five get_posts in a row and just offset by one more every time, but by using that method the the_author-value is useless as it’s just being inherited from a previous query_posts (yes I use query_posts) and not this get_posts-query.

    And of course, running several queries like that is a silly way to do something that probably is an easy task. It’s just that I don’t know how to single out the different posts being pulled out of the loop. I want to assign a numeric value from 1 to 5 (or similar) to the posts, so that I’ll easily be able to identify which is which in order to make the list meaningful.

    I know how to create a variable for the first post, but not for the other four. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Assign a different value to each post in the loop’ is closed to new replies.