Developers

Drupal QuickStart

This QuickStart will walk you through the basics of accessing the NewsCred Platform API using the NewsCred Drupal 5 modules. Let's get started!

Note: These modules are compatible with Drupal 5.

Downloading the Drupal Modules

Start by downloading our NewsCred Drupal Modules. Once the download is completed, unzip/untar it and copy the newscred_drupal_0.x/modules/newscred folder to your {drupal_root}/sites/all/modules folder.

Now, copy the template files in the newscred_drupal_0.x/templates folder to your {drupal_root}/themes/{current_theme} folder, where {current_theme} is the name of the theme you're currently using, for example: garland.

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.

Understanding Modules

The NewsCred Drupal Modules consists of 3 different Drupal modules, here's what they do:

Topic Module - Creates nodes and blocks with topic related content from the NewsCred Platform.
Article Module - Creates nodes and blocks with article related content from the NewsCred Platform.
Category Module - Creates nodes and blocks with category related content from the NewsCred Platform.

Let's set things up by enabling these modules in your Drupal installation. To do this, log in to your Drupal Admin Panel and navigate to Administer > Site Building > Modules.

Under the package NewsCred, select NewsCred Topic, NewsCred Article and NewsCred Category and hit the Save configuration button like so:

If you have a commercial API Access Key, you can open the newscred.key.inc file and add it like this:

define('NEWSCRED_ACCESS_KEY','c4bcc3f7c9bf9ec159f51da0a86ca658');

Creating a Topic Page

Now that you're all set up, let's start building a simple NewsCred powered topic page!

Let's create a Barack Obama topic page that displays 20 Obama related articles in the main content area and 5 related topics, 2 related images and 10 related tweets in the right sidebar.

First, some explaining. Every object in the NewsCred Platform, except Category objects, is assigned a globally unique ID called a GUID. For instance, the GUID for the topic "Barack Obama" is 1e3f343e71de57fe9cc70b90c07e196e.

Now, open up the Drupal Admin Panel and navigate to Create content > NewsCred Topic page.

  1. In the Drupal form, enter Barack Obama in the Topic Name field.
  2. Enter 1e3f343e71de57fe9cc70b90c07e196e in the GUID field.
  3. Under Content Options, select the Show Related Articles checkbox.
  4. Under Related Article Options, enter 20 in the Pagesize field.
  5. Hit the Submit button.

Congrats, you'll now be redirected to your first NewsCred powered topic page! This is what you should see:

Next, let's add some content to the right sidebar. Navigate to Administer > Site building > Blocks.

  1. In the Drupal table, find the NewsCred Topic - Related Topics block.
  2. Select right sidebar in the Region dropdown list.
  3. Hit the Save blocks button.

Once your page is refreshed, the NewsCred Topic - Related Topics block should now be displayed under the Right sidebar section in the table. Click on the configure link next to it.

  1. Enter 1e3f343e71de57fe9cc70b90c07e196e in the GUID field.
  2. Enter 5 in the Number of topics field.
  3. Hit the Save block button.

Check out your Barack Obama topic page now by navigating to Content Management > Content > Barack Obama. You should now see 5 related topics in the right sidebar.

Navigate back to Administer > Site building > Blocks. Let's add 2 related images to the right sidebar.

  1. In the Drupal table, find the NewsCred Topic - Related Images block.
  2. Select right sidebar in the Region dropdown list.
  3. Select 1 in the Weight dropdown list to make appear below the related topics block.
  4. Hit the Save blocks button.

Once your page is refreshed, the NewsCred Topic - Related Images block should now appear under the Right sidebar section in the table. Click on the configure link next to it.

  1. Enter 1e3f343e71de57fe9cc70b90c07e196e in the GUID field.
  2. Enter 2 in the Number of topics field.
  3. Hit the Save block button.

Navigate to your topic page, you should now see 2 related images below the related topics in the right sidebar.

Navigate back to Administer > Site building > Blocks. Let's add 10 related tweets to the right sidebar.

  1. In the Drupal table, find the NewsCred Topic - Related Tweets block.
  2. Select right sidebar in the Region dropdown list.
  3. Select 2 in the Weight dropdown list to make appear below the related images block.
  4. Hit the Save blocks button.

Once your page is refreshed, the NewsCred Topic - Related Images block should now appear under the Right sidebar section in the table. Click on the configure link next to it.

  1. Enter 1e3f343e71de57fe9cc70b90c07e196e in the GUID field.
  2. Enter 5 in the Number of tweets field.
  3. Hit the Save block button.

Navigate to your topic page, you should now see 5 related tweets below the related images in the right sidebar.

That's it! You've just created a NewsCred powered Drupal topic page in a matter of minutes. For more information about which nodes and blocks are supported in the current versions of our NewsCred Drupal Modules see the following sections.

Dynamic Topic Pages

The dynamic pages are the ones in which you pass the topic name as part of the URL (for example http://yourserver.com/topic/[topic-name]). The module than extracts the name from the URL, searches the platform for the topic and creates the page with contents pulled from the platform. No GUID has to be specified. The URL preceding the topic name, which is 'topic' by default, is customizable. And so is the content on the page. You get a form similar to the NewsCred Topic page creation form, which lets you choose what and what not to show on the dynamic page. This is how you can do this

  1. Go to Administer > Site Configuration > NewsCred Topic Settings
  2. In the URL field, enter the preceding URL of your choice(Default is 'topic')
  3. From 'Content Option' fields, select what you want to show on the page(related topics, articles, videos, images and tweets etc.)
  4. Click 'Save configuration'

Now in your browser address bar, type http://[host-name]/[url]/[topic-name] or in case you don't have Clean URLs enabled type http://[host-name]/?q=[url]/[topic-name] and hit enter.

If your host is example.com, the preceding URL is 'topic' and the name of the topic itself is Barack Obama, then the full URL is http://example.com/topic/barack-obama or http://example.com/?q=topic/barack-obama

Remember you have to pass the topic name in a slugified form. That is the topic name must be lower cased, with all spaces replaced by '-'.

Configuring Optional Parameters

The optional parameters on content creation form lets you choose what content you want to show on the pages(articles, images, videos etc.). You can also control other criteria such as how many items to show, selecting specific sources for articles, specifying classification for topics and so on.

Content Options

  • 1. Show Related Topics - Check if you want to get the list of related topics
  • 2. Show Related Article - Check if you want to get the list of related articles
  • 3. Show Related Images - Check if you want to get the list of related images
  • 4. Show Related Videos - Check if you want to get the list of related videos(for topic pages only)
  • 5. Show Related Tweets - Check if you want to get Twitter conversation on a topic (for topic pages only)

Related Topic Options

  • 1. Topic classifications - Comma separated list of topic classifications. Click here for the list of topic classifications.
  • 2. Pagesize - Number of related topics to retrieve.(Default is 10)
  • 3. From Date - Beginning of date range for which articles are returned. Format: yyyy-mm-dd [hh:mm:ss]. Default is all dates.
  • 4. To Date - End of date range for which articles are returned. Format: yyyy-mm-dd [hh:mm:ss]. Default is current date.

Related Article Options

  • 1. Categories - Comma separated names of categories. Click here for the list of categories.
  • 2. Sources - Comma separated GUIDs of sources.
  • 3. Source Countries - Comma separated 2 character ISO 3166-1 Country Code of sources.
  • 4. Pagesize - Number of related articles to retrieve.(Default is 10)
  • 5. From Date - Beginning of date range for which articles are returned. Format: yyyy-mm-dd [hh:mm:ss]. Default is all dates.
  • 6. To Date - End of date range for which articles are returned. Format: yyyy-mm-dd [hh:mm:ss]. Default is current date.

Understanding NewsCred Nodes

If you are using PHPTemplate as the templating engine of your Drupal installation, the following should be the names of templates

  • node-newscred_topic.tpl.php - Template for topic page(also for dynamic topic pages).
  • node-newscred_article.tpl.php - Template for article page.
  • node-newscred_category.tpl.php - Template for category page.

Inside each template you have granular control over the content returned by NewsCred Platform. That's why instead of putting everything in a single $content variable, the modules populate a number of NewsCred objects as properties of the node.

  • $node->topic - The NewsCred Topic object. Available on a topic page.
  • $node->article - The NewsCred Article object. Available on an article page.
  • $node->category - The NewsCred Topic object. Available on a category page.
  • $node->topics - The topics related to the Topic/Article/Category. Available if 'Show Related Topics' option is selected in the content creation form.
  • $node->articles - The articles related to the Topic/Article/Category. Available if 'Show Related Articles' option is selected in the content creation form.
  • $node->images - The images related to the Topic/Article/Category. Available if 'Show Related Images' option is selected in the content creation form.
  • $node->videos - The videos related to the Topic. Available if 'Show Related Videos' option is selected in the content creation form.
  • $node->tweets - The Twitter conversation related to the Topic. Available if 'Show Related Tweets' option is selected in the content creation form.

Now if you want to show a list of related articles on the page, with their source and date specified, this is how you can do it in a template

<ul>
  <?php foreach($node->articles as $article){ ?>
    <li>
      <a href="<?php print $article->link ?>">

        <?php print $article->title?> 
        From <?php print $article->source ?> 
        Dated<?php print date('j F Y', strtotime($article->published_at))?> 
      </a>
    </li>

  <php ? } ?>
</ul>

Understanding NewsCred Blocks

The module has the following blocks that can be enabled and configured in Administer > Site Building > Blocks in the administration panel.

  • NewsCred Topic - Related Articles - Shows the related articles on a topic. Template - block-newscred_topic-articles.tpl.php
  • NewsCred Topic - Related Topics - Shows topics related to a topic. Template - block-newscred_topic-topics.tpl.php
  • NewsCred Topic - Twitter Buzz - Shows Twitter Conversations on a topic. Template - block-newscred_topic-tweets.tpl.php
  • NewsCred Topic - Related Images - Shows images related to a topic. Template - block-newscred_topic-videos.tpl.php
  • NewsCred Topic - Related Videos - Shows the related videos on a topic. Template - block-newscred_topic-images.tpl.php
  • NewsCred Article - Related Articles - Shows the related articles on a article. Template - block-newscred_article-articles.tpl.php
  • NewsCred Article - Related Topics - Shows topics related to a article. Template - block-newscred_article-topics.tpl.php
  • NewsCred Article - Related Images - Shows images related to a article. Template - block-newscred_article-videos.tpl.php
  • NewsCred Category - Related Articles - Shows the related articles on a category. Template - block-newscred_category-articles.tpl.php
  • NewsCred Category - Related Topics - Shows topics related to a category. Template - block-newscred_category-topics.tpl.php
  • NewsCred Category - Related Images - Shows images related to a category. Template - block-newscred_category-videos.tpl.php

Contact Us