Perch CMS PHP自定义博客过滤

时间:2014-04-23 18:18:20

标签: php filtering perch

我正在使用Perch CMS,我有一个自定义博客过滤器,以显示同一类别中的相关帖子。我使用skip-template不将当前帖子显示为相关帖子之一。

以下是我的内容,但我仍然收到当前帖子。

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'
            ));


                }

        ?>

打印返回:

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
                            )

                    )

            )

    )

)

1 个答案:

答案 0 :(得分:1)

我的意思是这样的:

            $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>;

            }
相关问题