This quickstart will walk you through the basics of integrating NewsCred Platform API with your Wordpress site.
Start by downloading the Wordpress package of NewsCred. The package contains two simple PHP scripts
Once the download is complete, unzip/untar it and copy the files to your Wordpress themes directory i.e. {wordpres_root}/wp-content/themes/{theme-name} where {theme-name} is the name of the theme you are currently using.
You'll need a valid API Access Key to make API calls in production, you can request one here. For development and testing purposes, you can use this API Access Key: c4bcc3f7c9bf9ec159f51da0a86ca658.
Open up the file newscred_template.php in your text editor and locate the following line at the top
define('NEWSCRED_ACCESS_KEY','XXXX');
Replace XXXX with the access key, save the file and close it.
Now let's create a new page that will use this template to show contents pulled from NewsCred Platform.
The page is now ready, it's time to see it in action!
Type in the permalink of the page in your browser, and pass the name of the topic as 'query' parameter to the page. For example, If you are looking for the topic Barack Obama type in the http://www.myblogsite.com/newscred?query=obama
You should be able to see brief description of the topic on the page, along with related topics, news articles and images.
Let's take a look under the hood to see what's happening here.
If you open the newscred_template.php file in a text editor, you'll notice the following lines at the top
/*
Template Name: NewsCred Template
*/
require_once('newscred.php');
define('NEWSCRED_ACCESS_KEY','XXXX');
$query = $_REQUEST['query'];
try
{
$topics = NewsCredTopic::search(NEWSCRED_ACCESS_KEY, $query);
if(!empty($topics))
{
$related_topics = $topics[0]->getRelatedTopics();
$related_articles = $topics[0]->getRelatedArticles();
$related_images = $topics[0]->getRelatedImages();
}
}
catch(Exception $e)
{
die ($e->getMessage());
}
The code within the try/catch block is making request to the NewsCred platform and fetching the contents, using the wrapper(newscred.php). You can feel free to add/change these methods and their parameters and explore the capabilities of the platform. The PHP quickstart can help you with this. Also, you can modify the HTML of this file to make the content match with your site's layout.
We've only scratched the surface of what's possible with the NewsCred Platform API in this QuickStart.
For next steps, we recommend that you take a look at our exhaustive API Reference with more than 150 code samples to get you off on the right track.
If you need any help getting started, have any questions or feedback, feel free to drop us a line at
platform@newscred.com anytime. Cheers!