Perch Blog Section Display

  • Hi,

    I love perch, a great CMS that is perfect for what I use it for.

    I've done a few sites using perch, but the newest has introduced a quite a few new functions to me (members and blog). I have been stuck on this for a while now, but am probably just being an idiot. Sorry in advance.


    I have:

    Members app installed, with 2 tags: board & member

    Blog installed, with 3 sections: board, members and news

    Blog post page path: /news/post.php?s={postSlug}&p={sectionSlug}


    I have set up the blog-list , which works as planned [index.php]

    But I can't get individual posts to require the members to be logged in. I've tried the following, which make sense in my head...

    I'm sure there is an easy way to do it that I'm missing.

    [post.php]



    Again, I'm really sorry if I'm being stupid! Feel free to let me know if I'm doing anything that I shouldn't be.


    Many thanks,

    Fraser

  • drewm

    Approved the thread.
  • I think you want to keep it the same as your listing page.


    PHP
    1. <?php
    2.     if (perch_member_has_tag('board')) {
    3. perch_blog_custom([
    4.                 'filter' => 'postSlug',
    5.                 'match' => 'eq',
    6.                 'value' => perch_get('s'),
    7.      'section' => 'board-members',
    8.     ]);
    9. }

    ... and so on. If the requested post isn't in the section the member has access to then nothing will be returned.


    You don't want to rely on the section on the query string matching, as a user could change that.

  • Thank you for your help Drew. And thanks for creating such a great tool!

    That has solved the problem regarding access to blog posts. I've got it set up now with the different member levels which works as required.


    How would I do the same for the comments? I've tried inputting two templates (post.html & comment.html) with perch_blog_custom and had no success.

    I've also tried:

    Code
    1. perch_blog_custom([
    2. 'filter' => 'postSlug',
    3. 'match' => 'eq',
    4. 'value' => perch_get('s'),
    5. 'section' => 'board-members',
    6. 'template' => 'comment.html'
    7. ]);

    But this doesn't output the comments, just a bullet point.


    I don't understand why this doesn't work. If the member doesn't have the tag, why does it still perform the if statement?


    Thanks again for you help. Very grateful for your assistance.

  • The perch_blog_post_comments() function doesn't care what section a post is in, so that should always work the same way. I think you're missing some logic here though:

  • Thanks Drew. I only posted the start of the code, sorry. At this point I have the following... I've managed to hide the comments if no one is logged in (which is half the battle), but this still shows comments if members are logged in but don't have the correct tag ( for example if someone sends a link to the blog post ). Is there a way to change that?


  • Thanks Drew. I had the code below. It showed comments no matter what tag that they had (which now makes sense to me now that I realise how the functions work).


    I fixed the problem by creating individual posts and changing the blog post page path to:

    Code
    1. /news/{sectionSlug}/post.php?s={postSlug}



    Thank you for all of your help on this.