It is not straightforward to pass a variable to a template part. However, when you are in a loop, WP has a counter called current_post
that you can use in this way in your template part:
global $post;
$ranking = $post->$current_post + 1; // +1 because the counter starts at 0
Related Posts:
- how to display full post with pagination on home page
- page.php showing loop of posts and not page content
- Exclude category from
- how to handle the loop using filling bootstrap grid structure?
- Cant’ Grab WordPress Built-in Posts Through Loop
- I can’t find the relevant part of the loop in my theme file. How do I find the full content with “More…”
- Moved a website and excerpts don’t work for old posts
- Post are not showing up
- How to show the posts list into a static page? Problems to use the loop into a static page
- wordpress taxonomy results
- what template-part to call, to have my post in the center of the page?
- The post order is different for logged-in and non-logged-in users? [closed]
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- WordPress Ajax load doesn’t work
- Print Current Post Index number within Loop
- rewind_posts() – what actually the use of it, and where using is required or preferred?
- How to show list of posts by author and category?
- Override the default number of posts to show for a single loop?
- Single Page WordPress Theme – Using page templates
- WordPress Number of Posts Not Changing With posts_per_page
- Find most recent authors
- How do I change the gallery that is inserted in the post?
- Get the author of the latest revision
- Strange switch_to_blog() issue
- Multiple loops in same page, without duplicate content
- Posts Page Featured Image [closed]
- loop not displaying posts on custom template page
- How to Display Post View Count
- Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
- The correct way to call posts with ajax
- Convert a complex webpage into WP theme
- Converting multiple loops into one single loop with pagination
- How would I get 1 latest post from a query for 5 posts?
- Alternating post layout
- Check to see if specific loop has less than certain amount of posts
- Admin Notices don’t display on the admin screen for certain post
- I am unable to publish/update post
- Custom WordPress Theme: Publish Date and Display Date for posts right beside each other
- Adding specific post category between posts in loop
- Multiple loops are not reset
- Blog page not working
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- get_the_excerpt() is not working as expected – returns wrong text
- Pausing and Resuming WP_Query results
- Post Loop Missing Most Recent Post
- Sharing post from archive page (loop) doesn’t work
- Start WP Pagination From Number 1 in URL
- Disable sticky option for specific categories
- Use two different post_per_page limits with infinite scroll
- Highlight static blog page link in header
- Wrong post title displayed from loop
- Change all author links in Blog roll
- Showing categories and subcategories with posts
- Get the amount of posts on a current page
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- older blog posts not showing in new theme
- How to get posts published on the latest date?
- Page and post loop same template
- WordPress Query Posts From Category Post on Static Page
- Loop through posts? Want to remove extra newlines in actual post HTML/content on backend
- WP_Query: Show 10 posts in date order, first three random
- How include css class based on post ( in loop ) slug?
- WordPress Loop: How to display recent posts in multiple divs
- How to display posts on custom page without declaring a posts page in reading settings?
- Cannot implement byline into posts container in single.php
- Custom WP_Query not working correctly
- WP_Query of Category Not Showing First Post
- How come this loop is not working? [closed]
- Change default post style to columns
- How to add a post class on every post. (on homepage)
- posts going to 2 pages/categories only show up in 1
- Using the loop to set locations for all posts on a single google map
- Separate top level categories on archive-product.php by meta
- While loop in functions.php outputting the_title() of each post on frontpage
- Shortcode for Comments and Comment Boxes in Post Loop
- created post displaying differently on front end
- Permalink Short code showing unnecessary link text inside the loop
- Display specific posts based on an ID of another post
- How to distinguish pages created by woocommerce?
- how to call recent post content in a loop ( only the content before read more tag)
- Integrate video and iframe in a post type gallery
- How to put the WordPress blog into theme
- Posts are not showing up on next page.
- Displaying a specific sub-category’s posts from wp_query
- How to make post button to a random post
- Blog styling in SASS
- Advanced Post Display/Pagination/Ordering
- Keep post format class with isotope filter
- Make assigning post to a specific category equivalent to assigning it to all categories
- How to inject a post within a loop
- Get most recent posts by category that aren’t first overall [duplicate]
- Sort by category and then date?
- Loop not allowing infinite scroll after post per page limit
- Customise the appearance of 4 specific post ID’s within the loop?
- How do I create a template page to show 3 blog posts?
- Wp_query WooCommerce products
- posts_per_page – Repeats only first posts ‘post__in’ array
- blog post displaying within older post – loop issue?
- No matching template found when using single.php