{init_articles}
Articles in Saurus CMS are handled by two functions:
- {init_articles} returns a list of articles with common attributes like "title" and timestamp.
- {init_article} gives you access to whole set of fields of specific article including article's body and lead text.
Usage
{init_articles [parameter = value ..]}
Returns
Array of objects stored in variable defined by parameter "name".
Parameters
| name | Defines the variable which stores the list of article objects returned. Default value is "articlelist". | string | |
| parent | ID of an object who's child articles are retrieved. Default value is the current object's ID which is usually the ID parameter in site URL. You can also define multiple ID-s by comma separating them. | comma separated integers | |
| buttons | Defines a list of actions displayed in v-shaped context menu. Default value is "new,edit,hide,move,delete". You can use any combination of those to restrict some of the actions by user. | comma separated string | |
| position | Position acts as a filter which allows you to group objects on web layout. Default value is 0. | int | |
| on_create | Enables you to set default values when new article is created. | comma separated string | |
| publish: By default, objects are set to be hidden/unpublished when created by user. You can force publishing by using on_create="publish". Default value is "hide". | 4.0.2 | ||
allow_comments: sets the check box for enabling comments. | 4.5.3 | ||
| classes | In addition to articles, {init_articles} can also return link objects. Use classes="article, link" to retrieve these as well. | comma separated string | |
| limit | This lets you limit the number of database rows to return. | int | |
| start | Results are retrieved starting from first row by default. You can set any other number to achieve paging for example. You must also define parameter "limit" when using "start". Default value is 0. | int | |
| order | Sort order of returned objects. This defines the "order by" clause in SQL sentence, you can use use any fields from tables obj, obj_obj and obj_artikkel. Example: order="date desc". | string | |
| profile | Allows to filter out articles by given profile. The value must match exactly the profile name defined in the site's administration area. | string | |
| where | Additional filtering criteria for SQL "where" clause. Example: where="title='My headline'". When including any profile fields in the criteria, be sure to add "profile" parameter for the tag. | string | |
| select | additional table fields to return using SELECT SQL syntax. | string | 4.0.8 |
| rows_on_page | When defining rows_on_page, you can achieve paging simply by using using "page" parameter in URL. | int | 4.0.8 |
Attributes
| Common attributes | |||
|---|---|---|---|
| id | ID of the object. | int | |
| parent_id | ID of the parent object in site hierarchy. | int | |
| href | Hyperlink address to the object in format of ?id=123. When aliases are used, returns alias name in public view instead. | string | |
| title | Title of the object. | string | |
| buttons | Displays v-shaped context menu for authorized editors. | html | |
| class | Class name of the object. Possible values are: "section, article, link, image, comment, poll, document, article's list, link list, login-box, subject, album, iframe-box, event" | string | |
| comment_count | Number of comments. | int | 4.0.6 |
| last_commented_time | Time of last comment in format dd.mm.yyyy hh:ii. | datetime | 4.0.6 |
| created_time | Time of creation of the object in format of dd.mm.yyyy hh:ii. | datetime | 4.0.3 |
| fcreated_time | Time of creation of the object in database default format, eg yyyy-mm-dd hh:ii. | datetime | 4.0.3 |
| created_user_id | ID of the user who initially created the object. | int | 4.0.3 |
| created_user_name | Name of the user who initially created the object. | string | 4.0.3 |
| changed_time | Time of last saving of the object in format dd.mm.yyyy hh:ii. | datetime | 4.0.3 |
| fchanged_time | Time of last saving of the object in database default format, eg yyyy-mm-dd hh:ii. | datetime | 4.0.3 |
| changed_user_id | ID of the user who saved the object last. | int | 4.0.3 |
| changed_user_name | Name of the user who saved the object last. | string | 4.0.3 |
| is_selected | Returns 1 when article belongs to the parent branch of current object. | boolean | |
| Specific attributes | |||
| date | Article's default profile has date/time field which can be freely modified by the user. This attribute returns the date value in format of dd.mm.yyyy. | date | |
| fdate | Same as "date" attribute but in database format of yyyy-mm-dd | date | |
| datetime | Article's default profile has date/time field which can be freely modified by the user. This attribute returns the date and time value in format of dd.mm.yyyy hh:mm. | datetime | 4.4.1 |
| fdatetime | Same as "datetime" attribute but in database format of yyyy-mm-dd hh:mm:ss. | datetime | 4.4.1 |
| author | The "author" field in article's default profile which can be freely modified by the user. | string | |
| show_headline | Equals 1 when "Show headline" is checked by the user. | boolean | 4.1.0 |
| forum_allowed | Equals 1 when "Allow comments" is checked by the user. | boolean | 4.1.0 |
| <attribute> | Returns value of specific profile field. The value is set only if parameter "profile" is used for {init_articles}. | 4.0.8 |
General tags
| <name>_newbutton | Outputs action button for creating new object. | html | |
| <name>_count | Number of returned objects. When parameter "limit" is set, equals value of "limit". | int | |
| <name>_counttotal | Total number of objects found, not affected by "limit" parameter. | int |
Examples
Display list of headings of all available articles in current section.
{init_articles name="article_list"}
<ul>
{foreach from=$article_list item="article"}
<li>{$article->title}</li>
{/foreach}
</ul>
Display list of headings of all available articles in current section. In editor's environment, show v-shaped context menus and button for creating new article when none exist. Make article headings links to article's detail view.
{init_articles name="article_list"}
<ul>
{foreach from=$article_list item="article"}
<li>{$article->buttons}<a href="{$article->href}">{$article->title}</a></li>
{foreachelse}
<li>{$article_list_newbutton}</li>
{/foreach}
</ul>
Retrieve last 10 articles from section with ID 123. This technique is widely used to display last news headlines in web homepage.
{init_articles name="article_list" parent="123" limit="10" order="date desc"}
What next
To get access to article's body and lead text, check out function {init_article}.
