Pagination with each loop
-
is it possible add a pagination to a each loop results in a Pods template? I only have seen with php o shortcodes.
Thanks
-
The each loop doesn’t support pagination. You would need to change the each loop to a Pods shortcode and filter the results based on the current field.
[pods id="{@ID}" name="pod_name" field="rel_field" template="Your loop content template"]
Sub-shortcodes need to be enabled for this:
Cheers, Jory
Hi @keraweb
It works, the shortcode makes the loop, but don’t display all the fields and the links of the fields either. Does the “Your loop content template” need to be modified?
Thanks
Of course ?? That would be the name of the template in which you have your loop content.
You cannot use Pods shortcodes within templates since magic tags are parsed before shortcodes. A sub-loop should also be a separate template.See: https://docs.pods.io/displaying-pods/pods-shortcode/
Cheers, Jory
That would be the name of the template in which you have your loop content.
I meant the templates’s content, as it only displays the post_title without links or images
Thanks
Assuming that the template exists I would expect that it’s content would be used.
Could you share your code?
Cheers, Jory
Hi @keraweb
[each foto] ? <div class="grid-container"> <div class="grid-item pagination"> <a href="{@permalink}"><img src="{@post_thumbnail_url._src_relative.sizename}"></a> <div class="desc"><h4>{@post_title} </h4></div> </div> </div> [/each]
<style> * { box-sizing: border-box; }? .grid-container { width: 33.333%; float: left; padding: 0px 0px 0px 0px; object-fit: contain; margin-bottom: 10px; } .grid-item { height: 240px; width: 240px; object-fit: contain; } </style>
I have seen it now, If the code is a loop we don’t need the field”” in the shortcode, and works. But I’ve included limit=”6″ pagination=”true” in the shortcode and don’t display pagination.
If you add the field in the Pods shortcode you don’t need the [each] loop anymore as the shortcode already is the eachloop. This is the only way that pagination will work.
The way you’ve done it now doesn’t change anything from using a regular each loop, you basically just import an extra template.
The difference is that when you run the Pods shortcode with a field AND template it will load that template using the related object as context instead of the parent object you are including it from.
Simple example:
Main template:<h1>{@title}</h1> {@content} <div class="grid-container"> [pods id="{@ID}" name="pod_name" field="rel_field" template="Loop Template" pagination=1] </div>
Loop template (actual name)
<div class="grid-item pagination"> <a href="{@permalink}"> <img src="{@post_thumbnail_url._src_relative.sizename}"> </a> <div class="desc"><h4>{@post_title} </h4></div> </div>
Hope this helps!
Cheers, Jory
Hi @keraweb
Thanks for the codes. The <style> of class=”grid-item-pagination” is width: 33.333%; because is for a grip of 3 columns, with your code only one column displays.
The css problem is solved, anyway the pagination doesn’t work
[pods id="{@ID}" name="persona" field="foto" limit="3" template="Foto de persona per Shortcode" pagination="true" pagination="advanced"]
- This reply was modified 8 months, 4 weeks ago by jordiwordpress.
- This reply was modified 8 months, 4 weeks ago by jordiwordpress.
- This reply was modified 8 months, 4 weeks ago by jordiwordpress.
Him@keraweb,
Post are displayed the same as without pagination=”true” pagination=”advanced”
Nothing involved with the pagination is displayed.
I must give you my apologies as the direction I’ve pointed you to apparently doesn’t support pagination (yet).
The “field” function of a Pod always fetches all relationships and I don’t think it would be a quick fix to support querying by limit and offset.There is a different solution however.
Is this relationship a bi-directional relationship?
If so, you can query the results the other way around, example:[pods name="sub_pod_name" where="bidirectional_relationship_field.meta_value = {@ID}" pagination="advanced" template="Title" limit=5]
In this case the “{@ID}” magic tag will refer to the current post/object.
You need to rename “sub_pod_name” and “bidirectional_relationship_field” to the correct field names.Hope this helps!
Cheers, Jory
Hi @keraweb
Don’t work. Anyway I want to try with php. Can you share some reference o example?
Thanks
- The topic ‘Pagination with each loop’ is closed to new replies.