PHP code example of davodm / dgcontent-ci
1. Go to this page and download the library: Download davodm/dgcontent-ci library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
davodm / dgcontent-ci example snippets
$dgContent = new \DGContent\Libraries\Content();
$params = [
'limit' => 5,
'offset' => 0,
'category' => 'Technology',
'tags' => 'JavaScript,Node.js'
];
$posts = $dgContent
->setCacheDuration(7200)
->getPosts($params);
if ($posts['posts']) {
foreach ($posts['posts'] as $post) {
echo esc($post['title']) . '<br>';
}
} else {
echo "No posts found.";
}
[
'id' => "xxx",
'title' => 'Post Title',
'slug' => 'post-title',
'featuredImage' => 'https://example.com/image.jpg',
'images' => [ // Images in the content
'https://example.com/image1.jpg',
'https://example.com/image2.jpg'
],
'content' => 'Post content',
'category' => [
'title' => 'Category Title',
'slug' => 'category-slug'
],
'tags' => ['Tag 1', 'Tag 2'],
'site' => [ // Based on processed result
'title' => 'Site Title',
'slug' => 'site-slug',
'url' => 'xxx.com',
],
'stats'=> [
'views' => 100,
'likes' => 10,
'dislikes' => 2
],
'language' => 'en', // Could be null or not present
'source' => 'https://example.com', // Could be null or not present
'author' => 'Author Name', // Could be null or not present
'createdAt' => \CodeIgniter\I18n\Time Object, // Based on processed result
'updatedAt' => '2024-10-14T22:26:23Z', // If it's not processed
]