PHP Templating API: getNews()
Posted by Mark [Elevated X Support], Last modified by Mark [Elevated X Support] on 26 October 2017 07:45 PM


The getNews() function gets a list of news entries that are present in the system. Based on the arguments that are passed to it will determine which and how many news entries are returned.

Sample Usage:

$newsobj = $api->getNews();

$newsobj = $api->getNews(["id" => 1]);

$newsobj = $api->getNews([
"page" => 1,
"id" => 1,
"numperpage" => 20,
"subsiteid" => 1,
"sort" => "date",
"sort_reverse" => "1",
"newerthan" => "2000-01-01",
"olderthan" => "2010-01-01",
"tag_filter" => ["one", "two", "three"],
"tag_exclude" => ["four", "five", "six"],
"areatype" => "members",

echo "\nNumber of news entries returned: " . $newsobj->newscount;
echo "\nNumber of news entries total: " . $newsobj->newstotal;
echo "\nNumber of pages: " . $newsobj->numpages;
echo "\nNews:\n";

Returning Attributes:

This function call will return a StdObject object with the following attributes:


This is a multi-dimensional array that returns any news entries that match search criteria.


The number of news entries within the news attribute.


A total number of pages that are available. For instance, if settotal = 400 and the system has a numperpage value of 20, this value will be 20.


A total number of sets that are available, regardless of pagination.



This paginates the news entries. This way, if you specify "page" => 2, it will show a different list of news entries than if you specify "page" => 1.

This is useful if the page you're calling this function on is paginated and you want to show different entries on page 2 of your page than page 1.

By default, the system sets this value to 1 if not specified when passing along to the system.


This filters the results by news id. If set, this will only return a news entry of the specified id, if it is available for release and is present on the current site.


If specified, determines the maximum number of results to show.

By default, the system looks at the value of "Number of entries per page" in Plugins -> News -> Configure in your admin panel.


If specified, limit news entries belonging to a specified all-access subsite ids. If this value is set to 0, show news entries from all sites.

By default, the system will detect if the current area belongs to an all-access subsite, and use that value.

Note: If you specify a non-zero value for subsiteid, all-access must be available within this system. Otherwise, an Exception will be triggered.


Specify sorting order of news entries.

Valid values are: title, date, random.

By default, the system will sort by date.

Note: Doing a database sort by random creates a temporary table within mysql, and may result in reduced performance. Only choose this sorting option when absolutely necessary.


If this is set to 1, reverse the sorting order as specified within "sort"


If this value is set, only show news entries that are newer than the specified date.


If this value is set, only show news entries that are older than the specified date.


If set, only show sets that belong to the specified categories.

By default, the system looks at the value of "Use Categories" in "Index.php Config Options" on the Global Settings page in your admin panel.

Example values:

"tag_filter" => ["one,two"]
"tag_filter" => [["one,two"]];
"tag_filter" => [["one", "two"]];

Fetch news entries that belong to either tags labelled "one" or "two"

"tag_filter" => [["one"],["two"]];
"tag_filter" => "one,two";
"tag_filter" => ["one", "two"];

Fetch sets that belong to both tags labelled "one" and "two"

"tag_filter" => = [["one", "two"],["three", "four"]];

Fetch sets that belong either tags "one", or "two" AND ALSO belong to either tags "three" or "four".


If set, do not show sets that belong to the specified categories.

"tag_exclude" => "five,six"

This will exclude any news entries that belong to either tag "five" or "six".


If specified, filter news entries based on whether or not they should be displayed based on the specific area type.

Valid values: members, public, mobile

By default, the system will try to determine what area type the end-user is currently in, and filter entries by that value. For example, if the user is on a desktop devices, it will only show blog entries that are set to show on desktop devices.

(0 vote(s))
Not helpful

Comments (0)