This PHP code enables you to add a custom class to the first post on any archive page loop.
The code, which works in any theme, only adds your custom class to the 1st post on the 1st page only so.
This means that the 2nd and subsequent pages of your paginated archive will remain uneffected andthe classonly added to one post in the entire loop.
You can use the code in:
- A template file, using the WordPress Template Hierachy
- Your functions file with conditional tag
On top of this, you can use replicate the code to add custom classes to 2nd, 3rd and other posts in any archive loop.
Here’s the code for logged in members:
You need to pay to fully access this tutorial.
Enjoy unlimited access & coding support by registering.