Jump to content

Field id displayed but want field title, date/time format incorrect


NooseLadder
 Share

Recommended Posts

Hi,

I'm (slowly) building a site in PW and need some help with displaying a field.

I have the following page structure:

Home

Events

Event1

Event2

Event3

Each event (Event1.2,3) is from a template called 'events' which includes a field called 'groups'. The field 'groups' is a page type, with input set as Multiple pages (PageArray). The Input Field Type is 'Select'. I have created the templates 'groups' and 'group_list' and pages

Group (from template groups)

Group1 (from template group_list)

Group2

Group3

On the display page I have this:

<?php
foreach($page->children as $event) {
echo "<div class='event_listing'>
<p><strong>{$event->title}</strong></p>
<p><strong>Group:</strong>{$event->groups}</p>
<p><strong>Starting:</strong>{$event->start_time}</p>
<p><strong>Ending:</strong>{$event->end_time}</p>
<p><strong>Description:</strong> {$event->element_description}</p>
<p><strong>Contact Name:</strong> {$event->contact_name}</p>
<p><strong>Telephone:</strong> {$event->telephone}</p>
<p><strong>Email:</strong> {$event->email_address}</p>
</div>";
}
?>

I have two problems:

1. The following displays the group id. How can I get the Group Title?

<p><strong>Group:</strong>{$event->groups}</p>

2. The following is showing a date and time but it is a string like this 1355835600. How do I get the date and time format correct?

<p><strong>Starting:</strong>{$event->start_time}</p>
<p><strong>Ending:</strong>{$event->end_time}</p>
Link to comment
Share on other sites

Hi Noose,

1) A page field which holds multiple pages is an array and therefore you need to loop through them

foreach ($event->groups as $group) {

echo "<p>$group->title</p>";

}

2) You need to set a date output on your date field in the admin area. You will be able to choose different outputs there.

  • Like 1
Link to comment
Share on other sites

Thanks onjegolders, I thought I had set the date/time format but on checking it was not so that is now fixed as well.

For anyone this may help the code is now:

foreach($page->children as $event) {
foreach($event->groups as $group) {
echo "<div class='event_listing'>
    <h2><strong>{$event->title}</strong></h2>
<p><strong>Group:</strong> {$group->title}</p>
<p class='fltlft'><strong>Starting:</strong> {$event->start_time}</p> 
<p><strong>Ending:</strong> {$event->end_time}</p> 
<p><strong>Description:</strong> {$event->element_description}</p>
<p class='fltlft'><strong>Contact Name:</strong> {$event->contact_name}</p>
<p class='fltlft'><strong>Telephone:</strong> {$event->telephone}</p>
<p><strong>Email:</strong> {$event->email_address}</p>
</div>
<div class='clearfloat'></div>";
}}
?>

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...