Changing The Default Post Display

Customize how posts display on your Oncord powered website

The <data:repeater> tag is used to display posts throughout Oncord powered websites. This tag loops through a nominated data source and renders the content between the opening and closing tags for each returned element.

A Simple Example

See the below example of an <data:repeater> tag. The below code will produce a list <ul> of all posts of a certain post category.

<ul> <data:repeater datasource="\Components\Website\Posts::getAllForCategory(1)" as="post"> <li>[? $post['post_title'] ?]</li> </data:repeater> </ul>

You can display any post field using the above method, for a complete list of default post fields see the API reference here (scroll to the bottom of the page to see fields).

Generated Post Category Pages

When an admin user creates a new post category, a page is automatically generated which contains a <data:repeater> tag. On the generated pages the "datasource" attribute of the data repeater is automatically set to retrieve data from the newly created post category.

Before altering the default post display configuration, it's worth further examining the page which is generated when an admin user creates a new post category (eg. news). The following code is automatically added to a post category page upon creation:

<h1>News</h1> <data:repeater datasource="\Components\Website\Posts::getAllForCategory(3)" as="post"> <data:template component="\Components\Website\Posts" templatetype="list" /> </data:repeater>

Explaining The Above Code

Line 1: This heading is automatically set to the post category title when the post category is created.

Line 2: An opening <data:repeater> tag. This tag acts similar to a for loop, retrieving everything from a nominated data source and displaying the code between the opening and closing tags (line 3) for each returned element. In the above case the data source will retrieve all posts that have a category id of "3". Each post category is assigned a unique id. Select a post category through the admin panel to determine its id.

Line 3: The code on this line will render the post list display, which is accessible on the post configuration admin panel page (explained below). 

Altering The Post Display Configuration

  1. Navigate to Dashboard > Website > Designs.
  2. Below the relevant website design, under the Dynamic Displays dropdown, select the Posts List option.
  3. You can choose from a selection of prebuilt post displays, or customise source.

The following code is used by default for the post list display configuration:

<table cellspacing="0" cellpadding="10" border="0" style="width: 100%;"> <tr valign="top"> <logic:if test="$post['post_icon']"> <td valign="top" width="100"> <a href="[? $post['post_content_url'] ?]"><standard:image alt="[? $post['post_title'] ?]" src="[? $post['post_icon'] ?]" width="160" /></a> </td> </logic:if> <td valign="top"> <p style="margin: 0px; display: inline-block;"><strong><a href=""></a></strong><br /> <small></small></p> <div style="clear: both;"></div> <logic:if test="$post['post_content_url']"><a href="">Read More</a>&hellip;</logic:if> </td> </tr> </table>

Each post is referenced by the variable $post. PHP can be used to display various fields associated with the post. For a full list of post fields see the API reference here (scroll to the bottom of the page).