public static function posts()
    {
        if (!getConfig('sitemap.posts')) {
            return [];
        }

        $table = TableRegistry::get('MeCms.PostsCategories');
        $url = Cache::read('sitemap', $table->getCacheName());

        if (!$url) {
            $alias = $table->Posts->getAlias();
            $categories = $table->find('active')
                ->select(['id', 'lft', 'slug'])
                ->contain($alias, function (Query $q) use ($alias) {
                    return $q->find('active')
                        ->select(['category_id', 'slug', 'modified'])
                        ->order([sprintf('%s.modified', $alias) => 'DESC']);
                })
                ->order(['lft' => 'ASC']);

            if ($categories->isEmpty()) {
                return [];
            }

            $latest = $table->Posts->find('active')
                ->select(['modified'])
                ->order([sprintf('%s.modified', $alias) => 'DESC'])
                ->firstOrFail();

            //Adds posts index, categories index and posts search
            $url[] = self::parse(['_name' => 'posts'], ['lastmod' => $latest->modified]);
            $url[] = self::parse(['_name' => 'postsCategories']);
            $url[] = self::parse(['_name' => 'postsSearch'], ['priority' => '0.2']);

            foreach ($categories as $category) {
                //Adds the category
                $url[] = self::parse(
                    ['_name' => 'postsCategory', $category->slug],
                    ['lastmod' => array_value_first($category->posts)->modified]
                );

                //Adds each post
                foreach ($category->posts as $post) {
                    $url[] = self::parse(['_name' => 'post', $post->slug], ['lastmod' => $post->modified]);
                }
            }

            Cache::write('sitemap', $url, $table->getCacheName());
        }

        return $url;
    }
public static function posts()
    {
        if (!getConfig('sitemap.posts')) {
            return [];
        }

        $table = TableRegistry::get('MeCms.PostsCategories');
        $url = Cache::read('sitemap', $table->getCacheName());

        if (!$url) {
            $alias = $table->Posts->getAlias();
            $categories = $table->find('active')
                ->select(['id', 'lft', 'slug'])
                ->contain($alias, function (Query $q) use ($alias) {
                    return $q->find('active')
                        ->select(['category_id', 'slug', 'modified'])
                        ->order([sprintf('%s.modified', $alias) => 'DESC']);
                })
                ->order(['lft' => 'ASC']);

            if ($categories->isEmpty()) {
                return [];
            }

            $latest = $table->Posts->find('active')
                ->select(['modified'])
                ->order([sprintf('%s.modified', $alias) => 'DESC'])
                ->firstOrFail();

            //Adds posts index, categories index and posts search
            $url[] = self::parse(['_name' => 'posts'], ['lastmod' => $latest->modified]);
            $url[] = self::parse(['_name' => 'postsCategories']);
            $url[] = self::parse(['_name' => 'postsSearch'], ['priority' => '0.2']);

            foreach ($categories as $category) {
                //Adds the category
                $url[] = self::parse(
                    ['_name' => 'postsCategory', $category->slug],
                    ['lastmod' => array_value_first($category->posts)->modified]
                );

                //Adds each post
                foreach ($category->posts as $post) {
                    $url[] = self::parse(['_name' => 'post', $post->slug], ['lastmod' => $post->modified]);
                }
            }

            Cache::write('sitemap', $url, $table->getCacheName());
        }

        return $url;
    }
public static function posts ( ) { if ( ! getConfig ( 'sitemap.posts' ) ) { return [ ] ; } $ table = TableRegistry :: get ( 'MeCms.PostsCategories' ) ; $ url = Cache :: read ( 'sitemap' , $ table -> getCacheName ( ) ) ; if ( ! $ url ) { $ alias = $ table -> Posts -> getAlias ( ) ; $ categories = $ table -> find ( 'active' ) -> select ( [ 'id' , 'lft' , 'slug' ] ) -> contain ( $ alias , function ( Query $ q ) use ( $ alias ) { return $ q -> find ( 'active' ) -> select ( [ 'category_id' , 'slug' , 'modified' ] ) -> order ( [ sprintf ( '%s.modified' , $ alias ) => 'DESC' ] ) ; } ) -> order ( [ 'lft' => 'ASC' ] ) ; if ( $ categories -> isEmpty ( ) ) { return [ ] ; } $ latest = $ table -> Posts -> find ( 'active' ) -> select ( [ 'modified' ] ) -> order ( [ sprintf ( '%s.modified' , $ alias ) => 'DESC' ] ) -> firstOrFail ( ) ; //Adds posts index, categories index and posts search $ url [ ] = self :: parse ( [ '_name' => 'posts' ] , [ 'lastmod' => $ latest -> modified ] ) ; $ url [ ] = self :: parse ( [ '_name' => 'postsCategories' ] ) ; $ url [ ] = self :: parse ( [ '_name' => 'postsSearch' ] , [ 'priority' => '0.2' ] ) ; foreach ( $ categories as $ category ) { //Adds the category $ url [ ] = self :: parse ( [ '_name' => 'postsCategory' , $ category -> slug ] , [ 'lastmod' => array_value_first ( $ category -> posts ) -> modified ] ) ; //Adds each post foreach ( $ category -> posts as $ post ) { $ url [ ] = self :: parse ( [ '_name' => 'post' , $ post -> slug ] , [ 'lastmod' => $ post -> modified ] ) ; } } Cache :: write ( 'sitemap' , $ url , $ table -> getCacheName ( ) ) ; } return $ url ; }
Returns posts urls
@return array
@uses MeCms\Utility\SitemapBuilder::parse()
Returns posts urls