0

I'm using Perch CMS where I have a custom blog filter to display a related post from within the same category. I am using skip-template to not show the current post as one of the related posts.

Below is what I have but I'm still getting the current post showing.

Perch docs: http://docs.grabaperch.com/docs/blog/page-functions/custom/

        <?php
            $categories = perch_blog_post_categories(perch_get('s'), array(
                'skip-template'=>true,


                ));

            if (count($categories)) {
            $cat_slugs = array();
            foreach($categories as $cat) {
            $cat_slugs[] = $cat['categorySlug'];
            }

            perch_blog_custom(array(

            'filter' => 'postSlug',
            'match' => 'neq',
            'value' => perch_get('s'),
            'category' => $cat_slugs,
            'count'=>3,
            'template'=>'blog/related.html',
            'section'=>'Recipes'
            ));


                }

        ?>

Print returns:

Array
(
[0] => Array
    (
        [image] => Array
            (
                [_default] => /perch/resources/img0178.jpg
                [path] => img0178.jpg
                [size] => 4555891
                [bucket] => default
                [w] => 4272
                [h] => 2848
                [sizes] => Array
                    (
                        [thumb] => Array
                            (
                                [w] => 150
                                [h] => 100
                                [path] => img0178-thumb@2x.jpg
                                [size] => 20250
                                [mime] => image/jpeg
                            )

                        [w725h483c1] => Array
                            (
                                [w] => 725
                                [h] => 483
                                [density] => 1
                                [path] => img0178-w725h483.jpg
                                [size] => 78864
                                [mime] => image/jpeg
                            )

                        [w50h50c1] => Array
                            (
                                [w] => 50
                                [h] => 50
                                [density] => 1
                                [path] => img0178-w50h50.jpg
                                [size] => 2137
                                [mime] => image/jpeg
                            )

                    )

            )

        [postID] => 28
        [postTitle] => Butternut Squash & Tahini Soup
        [postSlug] => butternut-squash-tahini-soup
        [postDateTime] => 2014-04-24 09:01:00
        [postDescRaw] => the content

        [postDynamicFields] => {"image":{"_default":"\/perch\/resources\/img0178.jpg","path":"img0178.jpg","size":4555891,"bucket":"default","w":4272,"h":2848,"sizes":{"thumb":{"w":150,"h":100,"path":"img0178-thumb@2x.jpg","size":20250,"mime":"image\/jpeg"},"w725h483c1":{"w":725,"h":483,"density":"1","path":"img0178-w725h483.jpg","size":78864,"mime":"image\/jpeg"},"w50h50c1":{"w":50,"h":50,"density":"1","path":"img0178-w50h50.jpg","size":2137,"mime":"image\/jpeg"}}}}
        [postTags] => Banana
        [postStatus] => Published
        [authorID] => 2
        [sectionID] => 5
        [postCommentCount] => 0
        [postImportID] => 
        [postLegacyURL] => 
        [postAllowComments] => 1
        [postTemplate] => post.html
        [perch_image] => Array
            (
                [_default] => /perch/resources/img0178.jpg
                [path] => img0178.jpg
                [size] => 4555891
                [bucket] => default
                [w] => 4272
                [h] => 2848
                [sizes] => Array
                    (
                        [thumb] => Array
                            (
                                [w] => 150
                                [h] => 100
                                [path] => img0178-thumb@2x.jpg
                                [size] => 20250
                                [mime] => image/jpeg
                            )

                        [w725h483c1] => Array
                            (
                                [w] => 725
                                [h] => 483
                                [density] => 1
                                [path] => img0178-w725h483.jpg
                                [size] => 78864
                                [mime] => image/jpeg
                            )

                        [w50h50c1] => Array
                            (
                                [w] => 50
                                [h] => 50
                                [density] => 1
                                [path] => img0178-w50h50.jpg
                                [size] => 2137
                                [mime] => image/jpeg
                            )

                    )

            )

    )

)
sarah3585
  • 637
  • 13
  • 37
  • 1
    It looks quite sensible to me. Not everything from perch_content_custom is implemented in perch_blog_custom, btw. But that's mostly sorting AFAIK. What happens when you use skip_template on perch_blog_custom(.., true) and print_r() the result? Also, what has helped me debug at some times is the "all" tag: http://docs.grabaperch.com/docs/templates/show-all/ – Urs Apr 24 '14 at 07:03
  • Thank you for the reply. I get : Array ( [perch_page_path] => /recipes/post.php ) – sarah3585 Apr 24 '14 at 18:24
  • Hmm can't be - I'll post what I mean in the reply field below – Urs Apr 24 '14 at 20:39

1 Answers1

1

I meant something like this:

            $categories = perch_blog_post_categories(perch_get('s'), array(
                'skip-template'=>true,
            ));

            if (count($categories)) {
            $cat_slugs = array();
            foreach($categories as $cat) {
            $cat_slugs[] = $cat['categorySlug'];
            }

            $r = perch_blog_custom(array(

            'filter' => 'postSlug',
            'match' => 'neq',
            'value' => perch_get('s'),
            'category' => $cat_slugs,
            'count'=>3,
            'skip-template'=>true,
            'section'=>'Recipes'
            ));

            echo '<pre>';
            print_r($r);
            echo '</pre>;

            }
Urs
  • 4,984
  • 7
  • 54
  • 116
  • Thank you for clarifying, have pasted result in the first post. I'm not sure if that helps? It should be skipping that post – sarah3585 Apr 24 '14 at 21:24
  • 1
    I've tried it at home. To me, it looks as if 'category' and 'filter' don't play along. Try uncommenting the `category` line and see if the neq-filter works and vice versa. If so, head over to the perch forum and tell Rachel and Drew... If it's really a bug/missing feature, but you need a solution quickly, you can still divide it into two steps. First: get all posts by category, skip template. Second, filter out the duplicate post manually from the array and render the result again. – Urs Apr 25 '14 at 07:12
  • The category filter is working fine. It seems to be the negative filter that's not playing. Even with category commented out – sarah3585 Apr 25 '14 at 07:48
  • with category commented out, do other filters work, like 'eq'? – Urs Apr 25 '14 at 08:18
  • Category commented out an filter changed to eq returns nothing. – sarah3585 Apr 25 '14 at 08:30
  • I've tried with some different filter types and that seems to work with category: 'filter' => 'postDateTime', 'match' => 'eqbetween', 'value' => '2014-04-22, 2014-04-24', – sarah3585 Apr 25 '14 at 09:15