Skip Navigation

[Resolved] Count the number of posts

This thread is resolved. Here is a description of the problem and solution.

Problem:
I would like to display the number 1 for the first post of the list, number 2 for the second one in the list, and number 3 for the third one.

Solution:
1. Please add the following code in your theme’s functions.php file:

add_shortcode('incrementor', 'incrementor');
function incrementor() {
static $i = 1;
return $i ++;
}

2. Then use [incrementor] shortcode in your Views loop.

This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Nicholas 7 years ago.

Assisted by: Noman.

Author
Posts
#586332
Screen Shot 2017-11-05 at 8.47.00 AM.png

Hello on my blog I display a list of the newest articles in the sidebar. The list can reach a max. of 3 articles.
The ordering is post date descending.

I would like to display the number 1 for the first post of the list, number 2 for the second one in the list, and number 3 for the third one.
How is this possible?

Use the post field iterator shortcode maybe?

Regards,
Nicholas

#586588

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Nicholas,

Thank you for contacting Toolset support. Please add the following code in your theme’s functions.php file:

add_shortcode('incrementor', 'incrementor');
function incrementor() {
static $i = 1;
return $i ++;
}

Then use [incrementor] shortcode in your Views loop.

Thank you

#586599

Thank you.