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

Description:

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";
print_r($newsobj->news);

Returning Attributes:

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

news:

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

newscount:

The number of news entries within the news attribute.

numpages:

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.

newstotal:

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

Arguments:

page:

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.

id:

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.

numperpage:

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.

subsiteid:

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.

sort:

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.

sort_reverse:

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

newerthan:

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

olderthan:

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

tag_filter:

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".

tag_exclude:

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".

areatype:

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))
Helpful
Not helpful

Comments (0)