Skip Navigation

[Résolu] Feature post to display only on first page

This support ticket is created Il y a 6 années et 6 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par emilyT Il y a 6 années et 6 mois.

Auteur
Publications
#876324

Hi folks

I've used your article here https://toolset.com/documentation/user-guides/digging-into-view-outputs/ to set a featured post on the news archive which display differently to the rest of the posts. You can see it in action here:
lien caché

If you move to the second page of results (lien caché) the first post is featured here as well. I'd would like to adjust this so that the feature only displays on the first page of results and subsequent pages have just the three-column layout, is that possible?

This is how my loop looks:
<wpv-loop>
[wpv-item index=1]
<li class="col3">
[wpv-post-featured-image size="full"]
<div class="topcontent"><h2>[wpv-post-link]</h2>
[wpv-post-excerpt]
<p class="meta">[wpv-post-date] - [wpv-post-taxonomy type="category"]</p>
</div>

[wpv-item index=other]
<li class="col1">
[types field="one-column-image"][/types]
<h2>[wpv-post-link]</h2>
[wpv-post-excerpt]
<p class="meta">[wpv-post-date] - [wpv-post-taxonomy type="category"]</p>

</wpv-loop>

Many thanks, Emily

#878817

The Loop will iterate over each set of items that you have on each page.

If you have a code in your loop that features the first post, for example, this will run in each loop iteration and hence be the same logic on all pages.

What you can try is to use an HTML condition, in where you check the current page, and conditionally display featured code or just the standard grid.

Simplified, this looks like this:

<wpv-loop>
          		[wpv-item index=1]
          			[wpv-conditional if="( '[wpv-pager-current-page]' eq '1' )"]
                      This HTML is used if we are on the first page and first item
          			[/wpv-conditional]
          			[wpv-conditional if="( '[wpv-pager-current-page]' ne '1' )"]
                      This HTML is used for the first item on any other page
	            	[/wpv-conditional]
          		[wpv-item index=other]
                      This HTML is used for all other items no matter the page
</wpv-loop>

You can read more about conditional HTML here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

The ShortCode for the current page is explained here:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153244

#889454

Thanks Beda, that works perfectly!

Thanks again, Emily