I am using the blogposts resource to output my blogposts and added pagination to render three posts at a time. This is working as it is suppose to. But with the blogposts resource I have also added fields="tag" subresource="tags
So I can render the tags associated with each blogpost.
But I am not being able to output this part. This is code I have used:
{% if globals.get.limit %}
{% assign limit = globals.get.limit | convert: "number" %}
{% else %}
{% assign limit = 3 %}
{% endif %}
{% if globals.get.skip %}
{% assign skip = globals.get.skip | convert: "number" %}
{% else %}
{% assign skip = 0 %}
{% endif %}
{% assign resource = "blogposts" fields="tag" subresource="tags"%}
{module_data resource="{{resource}}" version="v3" template="" limit="{{limit}}" skip="{{skip}}" collection="bpost"}
{% assign moduloCheck = bpost.totalItemsCount | modulo :limit %}
{% if moduloCheck == 0 %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit | minus: 1 %}
{% else %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit %}
{% endif %}
{% assign currentPage = globals.get.skip|divided_by:limit %}
<hr />
{% for item in bpost.items %}
<h2>{{item.postTitle}}</h2>
<p>{{item.postBody}}</p>
<p>Skapad <span>{{item.releaseDate | date: "yyyy-MM-dd \ hh:mm:ss tt"}}</span></p>
<p><a href="{{item.postUrl}}">Kommentera</a></p>
<br />
<ul>
{% for item in bpost.items -%}
<li><a href="/retreivepostsbytag.html?tagid={{item.tag.id}}"># {{item.tag.tagName}}</a></li>
{% endfor -%}
</ul>
<hr />
{% endfor %}
<span>Sida:
{% for pageNum in (0..totalPages) %}
{% if pageNum == currentPage %}
{{ pageNum | plus: 1 }}
{% else %}
<a href="{{ globals.get.id }}?skip={{ pageNum|times:globals.get.limit }}&limit={{ limit }}">{{ pageNum | plus: 1 }}</a>
{% endif %}
{% endfor %}
</span>
Heres a test page I am trying to implement this code upon: testpage
Thanks, -Sohail
The subresource request for the tag data needs to happen once for each post, like so:
Also, your
resource
variable was only ever being set toblogposts
, the other part (fields="tag" subresource="tags"
) was getting discarded. I'd change it to this, for clarity:EDIT: Here's your code, modified to include the changes: