Blog Functions
The Blog and all of its content is accessible using a small family of Smarty functions. These methods allow advanced control over the sorting, filtering and paging behaviours and can be used alongside the Blog Ajax library in order to produce a dynamic and responsive article interface.
This article offers a brief overview of the functions available in the Aurora Front-end for accessing the Blog Posts from the Aurora Content section.
Introduction
Variable | Description | Usage |
---|---|---|
blog_total_comments | Retrieve the total number of approved comments | {$blog.id|blog_total_comments} |
blog_the_author | Retrieve the blog author, which will include their first name and last name | {$blog.page_author|blog_the_author} |
$config.blog_date_format | The date format you have decided on | {$blog.date_created|strtotime|date:"`$config.blog_date_format` @ `$config.blog_time_format`"} |
$config.blog_time_format | The time format you have decided on | {$blog.date_created|strtotime|date:"`$config.blog_date_format` @ `$config.blog_time_format`"} |
Blog Category IDs (blogGetCategoryIds)
You are able to fetch the IDs of all categories associated to a Blog using the blogGetCategoryIds Smarty function.
{blogGetCategoryIds blog_id=$page.id item="category_ids"}
{foreach from=$category_ids item="category_id"}
Category No. {$category_id}<br />
{/foreach}
Blog Categories (contentBlogCategoriesFind)
You are able to fetch a list of all blog categories available in Aurora using the contentBlogCategoriesFind Smarty function.
This is helpful when allowing your Blogs to be filtered by category, as illustrated in the example below.
Accepted Parameters
Parameter | Values | Default | Description | |
---|---|---|---|---|
item | String | blog_categories | This is the name of the variable you would like the results of your query placed in. For example, if you set this to "posts" then the items returned by this method will be loaded into a $posts template variable. | No |
page | Non-negative Integer | 1 | The number of the page of results you would like to have returned. The number of items returned per page defaults to the value specified in the "Posts per page" setting located under Store > Settings > Blog, but can be overridden using the "items_per_page" parameter if desired. | No |
items_per_page | Positive Integer | "Posts per page" setting located under Store > Settings > Blog | The number of content items to return per page. This should be used to retrieve a particular number of items instead of any 'limit' variable. So if you require a list of 50 Content Items, then simply set this to 50 and do not provide a 'page' value (or do provide a 'page' value but set it to 1). | No |
parent_category_id | Positive Integer | The Internal ID Aurora uses to identify a Content Category. This is the ID of the Content Category you would like to retrieve the children for, i.e. setting this field will not return the Content Category with this ID, but the categories within the Content Category with this ID. Set this to 0 (zero) in order to fetch the 'root' Content Categories. | No | |
order_by_ascending | Boolean | false | If set to 'true', then the content items are returned in Ascending order, otherwise they are returned in Descending order. In combination with the default value set for the "order_by" parameter, this method will return content items in descending date order, delivering the most recently created items first by default. | No |
Data Returned
Field | Values | Description |
---|---|---|
[ item ].x | Array( content_category ) | The data returned by this function is saved to the variable named in the item parameter. This data takes the form of an array of content_category (as described further down in this table). |
[ item ]_total_items | Non-negative Integer | The total number of items found by this function is saved to the variable named in the item parameter with the addition of "_total_items". For example, if you set item="posts" then your items will be found in a $posts template variable and the 'total items' will be stored in a $posts_total_items variable. This is commonly used for showing how many results there are matching a particular query/search when paging, e.g. "1-20 of 650" where 650 is the value returned within the total_items variable. |
[ item ]_more_available | Boolean | Whether or not there are more items to be returned that were not returned by this request is saved to the variable named in the item parameter with the addition of "_total_items". For example, if you set item="posts" then your items will be found in a $posts template variable and the 'more available' status will be stored in a $posts_more_available variable. This is commonly used for deciding whether or not to show the "Next Page" link when listing Content Items. |
[ item ]_number_of_pages | Non-negative Integer | The number of pages available for your request is saved to the variable named in the item parameter with the addition of "_number_of_pages". For example, if you set item="posts" then your items will be found in a $posts template variable and the 'more available' status will be stored in a $posts_number_of_pages variable. This is most useful when simply using the default value for items_per_page, so that your calling script(s) can generate their paging as needed without the need to know the specifics about the limits in play. |
content_category | Container | A container holding all of the category details. |
content_category.id | Positive Integer | The Internal ID Aurora uses to identify a Content Category. |
content_category.parent_category_id | Positive Integer | The Internal ID Aurora uses to identify a Content Category. This ID represents the category under which this category falls and will be 0 (zero) if it is not part of any other category, i.e. it is a 'root' Content Category. |
content_category.name | String | The free-test name for the Content Tag. |
content_category.url | String | The URL safe name for the tag, for use when including the category in URLs for filtering. |
content_category.description | String | The free-form text description of the Content Category. |
Example template code
<div class="ac_blog_category" data-content-field-name="type">
Category:
<select>
<option value="">All Categories</option>
{contentBlogCategoriesFind item="content_categories"}
{foreach from=$content_categories item="content_category"}
<option value="{$content_category.id}">{$content_category.name}</option>
{/foreach}
</select>
</div>
Listing Blog Posts (contentBlogFind)
This function is deprecated. Please use contentFind, which is documented here: Content Smarty Functions
Example URL: https://demo.auroracommerce.com/example-sub-blog
It is possible to list your Blog articles anywhere in Aurora using the contentBlogFind function.
Accepted Parameters
Parameter | Values | Default | Description | |
---|---|---|---|---|
item | String | blog_posts | This is the name of the variable you would like the results of your query placed in. For example, if you set this to "posts" then the items returned by this method will be loaded into a $posts template variable. | No |
page | Non-negative Integer | 1 | The number of the page of results you would like to have returned. The number of items returned per page defaults to the value specified in the "Posts per page" setting located under Store -> Settings -> Blog, but can be overridden using the "items_per_page" parameter if desired. | No |
items_per_page | Positive Integer | "Posts per page" setting located under Store -> Settings -> Blog | The number of content items to return per page. This should be used to retrieve a particular number of items instead of any 'limit' variable. So if you require a list of 50 Content Items, then simply set this to 50 and do not provide a 'page' value (or do provide a 'page' value but set it to 1). | No |
limit | Positive Integer | "Posts per page" setting located under Store -> Settings -> Blog | The number of content items to return in this request. The limit parameter has been made available for use along side the start parameter only, but it is recommended that the built-in paging (items_per_page and page) combination be used instead as this is far simpler in nature and provides better support for the automated paging values. | No |
start | Positive Integer | 1 | The number of the content item to start returning in this request. e.g. If 3 is provided, then the 3rd item in the result set will be the first to be returned. The start parameter has been made available for use alongside the limit parameter only, but it is recommended that the built-in paging (items_per_page and page) combination be used instead as this is far simpler in nature and provides better support for the automated paging values. | No |
search | String | The search term or phrase by which to search the Content items for by title, content and keywords. | No | |
search_field_called | String | The case-insensitive name of the Content Field to search. Aurora Content can be assigned any number of custom Fields in the Aurora Back-end. These fields can be used for filtering by this method. | No | |
search_field_for | String | The case-insensitive value to search for in the field described by the search_field_called parameter. This search will only search for an exact match. This means that it will search for "X" equals "Y", but will not for "X" begins "Y". | No | |
category_id | Positive Integer | The Internal ID Aurora uses to identify a Content Category. | No | |
parent_content_id | Non-negative Integer | The Internal ID Aurora uses to identify a Content Item (Blog Post/Content Page). This ID is used to find any 'child' content items that are configured to 'belong to' said 'parent' content item. If you wish to retrieve all 'root' Content Items (items with no parent) then set this parameter to 0 (Zero). This will only return the very next level of content items (children), e.g. if you have content pages set-up as follows, but provide the Parent ID for "Content 1" then you will only receive "Content 2" and not "Content 3": Content 1 > Content 2 > Content 3 To receive "Content 3" you would provide the ID of "Content 2". | No | |
exclude_content_id | Positive Integer | The Internal ID Aurora uses to identify a Content Item (Blog Post/Content Page). This ID is used to avoid returning the Content Item with the specified ID. This is most often useful when returning a list of articles that are 'related' to the current article being viewed, whereby you wish not to include the item already loaded in said results. | No | |
tags | Comma-delimited String | This comma-delimited string of tags will have Aurora return only content that have any one of the provided tags attached to it. Only Blogs currently have tags and so if this is provided for a request for a Content Page and not a Content Blog, then it will be ignored. | No | |
date_start | String | The date and time you would like the result to begin being returned. | No | |
date_end | String | The date and time you would like the result to stop being returned. | No | |
author_id | Integer | The Internal ID Aurora uses to identify a User. | No | |
order_by | date_created or title or views | date_created | The name of the field by which the Content should be ordered when returning the recordset. | No |
order_by_ascending | Boolean | false | If set to 'true', then the content items are returned in Ascending order, otherwise they are return in Descending order. In combination with the default value set for the "order_by" parameter, this method will return content items in descending date order, delivering the most recently created items first by default. | No |
Data Returned
Field | Values | Description |
---|---|---|
[ item ].x | Array( content_item ) | The data returned by this function is saved to the variable named in the item parameter. This data takes the form of an array of content_item (as described further down in this table). |
[ item ]_total_items | Non-negative Integer | The total number of items found by this function is saved to the variable named in the item parameter with the addition of "_total_items". For example, if you set item="posts" then your items will be found in a $posts template variable and the 'total items' will be stored in a $posts_total_items variable. This is commonly used for showing how many results there are matching a particular query/search when paging, e.g. "1-20 of 650" where 650 is the value returned within the total_items variable. |
[ item ]_more_available | Boolean | Whether or not there are more items to be returned that were not returned by this request is saved to the variable named in the item parameter with the addition of "_total_items". For example, if you set item="posts" then your items will be found in a $posts template variable and the 'more available' status will be stored in a $posts_more_available variable. This is commonly used for deciding whether or not to show the "Next Page" link when listing Content Items. |
[ item ]_number_of_pages | Non-negative Integer | The number of pages available for your request is saved to the variable named in the item parameter with the addition of "_number_of_pages". For example, if you set item="posts" then your items will be found in a $posts template variable and the 'more available' status will be stored in a $posts_number_of_pages variable. This is most useful when simply using the default value for items_per_page, so that your calling script(s) can generate their paging as needed without the need to know the specifics about the limits in play. |
content_item | Container | An array of fields pertaining to a single content item. |
content_item.id | Positive Integer | The Internal ID Aurora uses to identify Content. |
content_item.title | String | The title of the Blog. |
content_item.page_introduction | String | |
content_item.page_content | String | The main body of the content itself. |
content_item.page_comments | Non-negative Integer | The number of comments a Content Item has received. |
content_item.meta_title | String | |
content_item.meta_description | String | |
content_item.meta_keywords | String | |
content_item.date_created | The date this Post was created. | |
content_item.count_views | Non-negative Integer | The number of views this Post has received. |
content_item.comment_status | Whether or not the Blog is currently open for receiving comments. | |
content_item.page_filename | String | The filename used for a Blog's URL. |
content_item.permalink | String | The relative URL used to access an individual blog article on the Front-end. This will often differ from the "page_filename" value as the blog URLs are dependant on the Aurora config and even individual blog settings, as described in the Blog URL Structure article. |
content_item.content_complete_url | String | The relative URL for a blog entry. |
content_item.author | Container | This is a container for the Author data. |
content_item.author.id | Positive Integer | The Internal ID Aurora uses to identify Users. |
content_item.author.firstname | String | The first name of the User that is attributed with the creation of the Content Item. |
content_item.author.lastname | String | The last name (surname) of the User that is attributed with the creation of the Content Item. |
content_item.author.fields | Array( String ) | This is an associative array of fields associated to the Author of the Content Item. There will be one entry in this array for each field configured against the Author/User. These fields can vary wildly and are dependant on how Aurora is being used. |
content_item.author.fields.xxx | Variable | |
content_item.fields | Array( String ) | This is an associative array of fields associated to the Content Item. There will be one entry in this array for each field configured against the Blog. |
content_item.fields.xxx | Variable | |
content_item.tags | Array( content_tag ) | For more details regarding the fields available here, please see the content_tag variable in the Content Blog Tags article. |
content_item.categories | Array( content_category ) | For more details regarding the fields available here, please see the content_category variable in the Content Blog Categories article. |
Example template code
For some complete examples, please see the following template in the Aurora Demo Example Front-end Templates:
templates/example.com/blog/single.tpl.html
This template (or its content) can be included in any Front-end Template to list your Blog entries and supports all of the following via the Ajax provided by _js/blog.js:
- Paging (Next and Previous pages only)
- Filtering by:
- Content Category
- Date (Month)
- Content Field (Only one field can be filtered by at any one time)
- Sorted by:
- Date created
- Title
- Views
The following is a very simple example just to illustrate how the function works.
{contentBlogFind order_by="views" page=2 item="blog_posts" category_id=3 tags="tag one,tag two" order_by_ascending=0}
{foreach from=$blog_posts item=blog_post}
Blog ID: {$blog_post.id}<br \>
Date Created: {$blog_post.date_created}<br \>
Name: {$blog_post.title}<br \>
Views: {$blog_post.count_views}<br \>
Author: {$blog_post.author.firstname} {$blog_post.author.lastname}<br \>
{foreach from=$blog_post.fields key="field_key" item="field_value"}
{$field_key}: {$field_value}<br \>
{/foreach}
<hr \>
{/foreach}
ESI Varnish Cache Includes
If your site uses Varnish to cache its pages, then you may need to place your Blog listing template code in the blog/articles.tpl.html
template to allow Aurora to inject this information without Varnish caching it.
This template can be included as follows.
{include_esi file="blog/articles.tpl.html"}
{include_esi file="blog/articles_1.tpl.html"}
{include_esi file="blog/articles_2.tpl.html"}
{include_esi file="blog/articles_3.tpl.html"}
If you call the template anything else, it will be rejected by Aurora. This is a security measure. If you require any additional templates to be whitelisted, then please contact your Aurora Commerce Account Manager for a quote.
Listing the Months that have Blog Posts in them (contentBlogFindMonthsWithPosts)
Example URL: https://demo.auroracommerce.com/blog
It is possible to list the months containing Blog Posts (or sub-blog posts) anywhere in Aurora using the contentBlogFindMonthsWithPosts function.
Accepted Parameters
Parameter | Values | Default | Description | |
---|---|---|---|---|
item | String | months_with_posts | This is the name of the variable you would like the results of your query placed in. For example, if you set this to "posts" then the items returned by this method will be loaded into a $posts template variable. | No |
parent_content_id | Non-negative Integer | The Internal ID Aurora uses to identify a Content Item (Blog Post/Content Page). This ID is used to find any 'child' content items that are configured to 'belong to' said 'parent' content item. If you wish to retrieve all months with posts from any Blog then set this parameter to 0 (Zero). Otherwise, provide the ID of the sub-blog for which you would like to find the active months for. | No |
Data Returned
Field | Values | Description |
---|---|---|
[ item ].x | Array( month_data ) | The data returned by this function is saved to the variable named in the item parameter. This data takes the form of an array of month_data (as described further down in this table). |
month_data | Container | An array of fields pertaining to a single blog month. |
month_data.url | String | The URL that can be used (with the addition of the current Domain) to access the present months posts. This is only presently supported by the Main Blog section and not any Sub-blogs and so the URL will always begin with the Blog prefix (e.g. /blog/2015/03/) and cannot be used with Sub-blogs to access their posts. |
month_data.date | String | The string date representation of the present month. This string format cannot currently be changed so to present the date in another format please use the timestamp field with any of the Smarty date functions to produce your own date string. |
month_data.timestamp | UNIX Timestamp | The date of the present month as a UNIT Timestamp (the number of seconds since midnight Jan 1, 1970). |
month_data.total_posts | Non-negative Integer | The total number of Live posts found in the present month. |
Example template code
For some complete examples, please see the following template in the Aurora Demo Example Front-end Templates:
templates/example.com/blog/main.tpl.html
The following is a very simple example just to illustrate how the function works and can be used to build a select box of available months to filter your Blog by.
example.com/blog/main.tpl.html
{contentBlogFindMonthsWithPosts parent_content_id=$parent_blog_content_id item="blog_archive_list"}
<div class="ac_blog_date" data-content-field-name="type">
Date:
<select>
<option value="">All</option>
{foreach from=$blog_archive_list item="blog_period"}
<option value="{$blog_period.url}">{$blog_period.date} ({$blog_period.total_posts})</option>
{/foreach}
</select>
</div>
Depreciated Methods
As Aurora undergoes constant redevelopment, in an effort to improve and simplify its many interfaces, it is sometimes necessary to retire old methods in favour of new ones. The good news here though is that the old methods will continue to work until you decide to move over, and doing so is a completely transparent process.
The following Smarty Functions have been depreciated:
- blogGetPosts - Please use the new "contentBlogFind" function
Related Aurora Demo Example Files
example.com/blog/main.tpl.html example.com/blog/single.tpl.html
example.com/_js/blog.js
Updated over 2 years ago