PHP code example of davaxi / ghost

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

    

davaxi / ghost example snippets




$client = new Davaxi\Ghost\Client();
$client->loadFromEnvironment();




$client = new Davaxi\Ghost\Client();
$client->setApiUrl('YOUR_GHOST_API_URL');

// If you are using Admin APIs
$client->setAdminApiKey('YOUR_ADMIN_API_KEY');

// If you are using Content APIs
$client->setContentApiKey('YOUR_CONTENT_API_KEY');




$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\AdminApi\Posts($client);
$response = $service->find(['YOUR_PARAMS']);
$response = $service->findById('POST_ID');
$response = $service->findBySlug('POST_SLUG');
$response = $service->create(['YOUR_POSTS_DATA']);
$response = $service->createOne(['YOUR_POST_DATA']);
$response = $service->update('POST_ID', ['YOUR_POST_DATA']);
$response = $service->delete('POST_ID');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\AdminApi\Pages($client);
$response = $service->find(['YOUR_PARAMS']);
$response = $service->findById('PAGES_ID');
$response = $service->findBySlug('PAGES_SLUG');
$response = $service->create(['YOUR_PAGES_DATA']);
$response = $service->createOne(['YOUR_PAGES_DATA']);
$response = $service->update('PAGE_ID', ['YOUR_PAGE_DATA']);
$response = $service->delete('PAGE_ID');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\AdminApi\Tags($client);
$response = $service->find(['YOUR_PARAMS']);
$response = $service->findById('TAGS_ID');
$response = $service->findBySlug('TAGS_SLUG');
$response = $service->create(['YOUR_TAGS_DATA']);
$response = $service->createOne(['YOUR_TAGS_DATA']);
$response = $service->update('TAG_ID', ['YOUR_TAG_DATA']);
$response = $service->delete('TAG_ID');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\AdminApi\Webhooks($client);
$response = $service->find(['YOUR_PARAMS']);
$response = $service->findById('WEBHOOKS_ID');
$response = $service->findBySlug('WEBHOOKS_SLUG');
$response = $service->create(['YOUR_WEBHOOKS_DATA']);
$response = $service->createOne(['YOUR_WEBHOOKS_DATA']);
$response = $service->update('WEBHOOK_ID', ['YOUR_WEBHOOK_DATA']);
$response = $service->delete('WEBHOOK_ID');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\AdminApi\Themes($client);
$response = $service->upload('path/to/your/theme/zip/file');
$response = $service->activate('YOUR_THEME_NAME');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\AdminApi\Images($client);
$response = $service->upload('path/to/your/image/file');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\AdminApi\Site($client);
$response = $service->get();



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\ContentApi\Posts($client);
$response = $service->find(['YOUR_PARAMS']);
$response = $service->findById('POST_ID');
$response = $service->findBySlug('POST_SLUG');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\ContentApi\Pages($client);
$response = $service->find(['YOUR_PARAMS']);
$response = $service->findById('PAGE_ID');
$response = $service->findBySlug('PAGE_SLUG');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\ContentApi\Authors($client);
$response = $service->find(['YOUR_PARAMS']);
$response = $service->findById('AUTHOR_ID');
$response = $service->findBySlug('AUTHOR_SLUG');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\ContentApi\Tags($client);
$response = $service->find(['YOUR_PARAMS']);
$response = $service->findById('TAG_ID');
$response = $service->findBySlug('TAG_SLUG');



$client = new Davaxi\Ghost\Client();

// ...

$service = new Davaxi\Ghost\Service\ContentApi\Settings($client);
$response = $service->get();