PHP code example of contentpulse / contentpulse-php

1. Go to this page and download the library: Download contentpulse/contentpulse-php 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/ */

    

contentpulse / contentpulse-php example snippets


use ContentPulse\Http\ContentPulseClient;

// Minimal: uses CONTENTPULSE_BASE_URL (env/constant) or defaults to https://contentpulse.io
$client = new ContentPulseClient(apiKey: 'your-api-key');

// Or override explicitly:
$client = new ContentPulseClient(
    apiKey: 'your-api-key',
    baseUrl: 'https://contentpulse.io',
);

use ContentPulse\WordPress\Support\ContentPulseEndpointResolver;

$apiBaseUrl = ContentPulseEndpointResolver::resolveApiBaseUrlFromEnvironment();
$appBaseUrl = ContentPulseEndpointResolver::resolveAppBaseUrlFromEnvironment();
$publishEndpoint = ContentPulseEndpointResolver::buildPublishWordPressEndpoint($apiBaseUrl, $contentId);
$contentUrl = ContentPulseEndpointResolver::buildContentUrl($appBaseUrl, $contentId);

use ContentPulse\Core\DTO\ContentFilters;

$feed = $client->getContentFeed(new ContentFilters(
    websiteId: 1,
    perPage: 20,
));
foreach ($feed->items as $item) {
    // $item contains content metadata and structure
}

use ContentPulse\Rendering\HtmlRenderer;

$renderer = new HtmlRenderer();
$html = $renderer->renderAll($content->sections);

use ContentPulse\Rendering\SectionNormalizer;

$normalizer = new SectionNormalizer();
$normalized = $normalizer->normalize($rawSections);

use ContentPulse\Core\DTO\SeoMeta;

$seo = SeoMeta::fromArray($content->seo_metadata);
$html = $seo->toHtml(); // Renders <title>, meta description, og:*, twitter:*

use ContentPulse\Publishing\PublishPayloadBuilder;
use ContentPulse\Rendering\HtmlRenderer;

$builder = new PublishPayloadBuilder(new HtmlRenderer());
$payload = $builder->buildForWordPress($content);
// or
$payload = $builder->buildForShopify($content);
bash
composer