Skip Navigation

[Resolved] Help using logic to know if there are more than a certain number of posts

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

Problem:

In the nested views, I want to show a "More" link in child post view if that category has more than 3 posts:

Solution:

You can enable pagination in child post view, and use shortcode [wpv-pagination] to display the "More" link, see example here:

https://toolset.com/forums/topic/help-using-logic-to-know-if-there-are-more-than-a-certain-number-of-posts/#post-1714345

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-pagination

This support ticket is created 4 years, 5 months 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 2 voices.

Last updated by liatG 4 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1713225

I'm trying to create a View that's limited to a certain number of blog posts, and if there are more blog posts in that category than the limit, I want to show a link to all blog posts in that category.
Here is an example (scroll to the bottom): hidden link
Where it says "Related Posts".
Here is the category view: hidden link
Here is the nested view with the individual posts: hidden link (right now not limited to any number of posts but I would limit it to 3 or 5)

Example (in this example, category A has 20 posts, category B has 3 posts):
"Related Posts: Category A
- post 1
- post 2
- post 3
see all posts in Category A

"Related Posts: Category B
- post 1
- post 2
- post 3"

Can you suggest a way to accomplish this?
Thanks!

#1713345

Hello,

Please provide your website credentials in below private message box, I need to check your website settings, thanks

#1714345

Thanks for the details, I have done below modifications in your website:
1) Edit parent taxonomy view:
hidden link
in section "Loop item in Related Categories 2 for Post Page", add attribute "term_slug" to the view's shortcode, pass term slug to child post view:
[wpv-view name="posts-for-individual-category-groups-view" term_slug="[wpv-taxonomy-slug]"]

2) Edit the child post view:
in section "Pagination and Sliders Settings":
hidden link
- enable option "Pagination enabled with manual transition and page reload"
- Display 3 items per page

in section "Loop Editor", add line 10:

[wpv-pagination]<a href="<em><u>hidden link</u></em> name="term_slug"]">Show more link here ...</a>[/wpv-pagination]

It will check if there is pagination(more than 3 posts), then display a term archive page link

Please check if it is what you want.

More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-pagination
This shortcode displays the pagination controls. The pagination controls will only be displayed if there are multiple pages to display.

#1715135

Woohoo, this was exactly what I was hoping for! And I would have never been able to figure it out on my own. Thank you so much!!

#1715155

Thank you so much, Luo, I learned a lot about passing through information to the child View, I had no idea how to do that!
I know you guys don't normally help with styling, but I'm trying to get that "see all posts" link up under the

  • items (but aligned to the left of the page) so that it shows that the "see more" link is related to those posts. I tried several styling ideas but couldn't get it to work. Any suggestions?
    Thank you!
    Liat
  • #1715523

    Dear Liat,

    I have checked the URL you mentioned above again:
    hidden link

    It seems that you have already fixed it with CSS codes, is this problem resolved? please let me know if you need more assistance for it.

    Luo

    #1716697
    Screenshot_Liat 2020-07-23 at 6.01.44 PM.jpg

    I could not get the words to left-align. They are indented and get lost with the rest of the list. I was trying some ideas to get the line to left-align to the page but it didn't work. Any suggestions? Thank you!!

    #1716815

    You can try one of below two options:

    1) move those codes outside HTML UL tag, for example, edit the child post view:
    hidden link
    Modify line 9~10, from:

    	</ul>
          <div style="padding-left: -1 em;">[wpv-pagination]<a href="/knitting-topic/[wpv-attribute name="term_slug"]">See all [wpv-attribute name="term_name"] posts here</a>[/wpv-pagination]</div>
    

    To:

          <div style="padding-left: -1 em;">[wpv-pagination]<a href="/knitting-topic/[wpv-attribute name="term_slug"]">See all [wpv-attribute name="term_name"] posts here</a>[/wpv-pagination]</div>
    	</ul>
    

    2) Use CSS codes, for example:
    <div style="padding-left: -1 em; margin-left: -1em;">
    hidden link

    #1718275

    My issue is resolved now. Thank you!

    I removed the

      list and just used Font Awesome icons for the bullets. Then I could format each line how I wanted:

      	<!-- wpv-loop-start -->
      		<wpv-loop>
      			<div style="margin-left: 1.5em;"><i class="fas fa-caret-right"></i>&nbsp;&nbsp;&nbsp;[wpv-post-body view_template="loop-item-in-posts-for-individual-category-groups-view"]</div>
      		</wpv-loop>
      [wpv-pagination]<a href="/knitting-topic/[wpv-attribute name="term_slug"]">See all [wpv-attribute name="term_name"] posts here</a>[/wpv-pagination]
      	<!-- wpv-loop-end -->