Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Show page list on homepage


Reply


3 Posts   1228 Views

Avatar
NickJacobs

Community Member, 144 Posts

24 February 2009 at 10:43am

Hi, I want to be able to have a "teaser" list of other pages (with short description) displayed on the homepage of a site. I have created a "Show on Homepage" checkbox (in Page.php) but not really sure how to build the function to be able to access this for the homepage. Any help will be appreciated.

Cheers!

Avatar
Double-A-Ron

Community Member, 604 Posts

24 February 2009 at 11:10am

Hi mate,

Surely this isn't much different from how your navigation is built.

I do something similar, but it's a featured page (a tour). Only one, but I have access to everything to do with that page - teaser, images etc.

Maybe you can adapt this:

HomePage.php

class HomePage_Controller extends Page_Controller {

   // Get featured tour data
   function getFeaturedTour() {
      //return DataObject::get_one('Tour');
      return DataObject::get_one('Tour', 'TourLengthDays>0', false, 'RAND()');
   }
   
}

Where 'Tour' is the type of page. You probably want to use get instead of get_one, but I can't find it in the docs.

HomePage.ss

<% control getFeaturedTour %>
<div class="featured">
<div class="featured-top">
<div class="featured-btm">
<h4>Featured Tour</h4>
<a href="$Link">
$Photo2.SetWidth(205)
</a>
<h5 style="margin: 0px">
<a href="$Link" style="color:#023107">$Title</a>
<small>$TourLeavesFrom to $TourEndsAt - $TourLengthDays Days</small>
</h5>
<% if TourTeaser %>
<div style="font-weight: normal; text-align: justify; margin-right: 5px">$TourTeaser</div>
<p><a href="$Link">Click for details</a></p>
<% end_if %>
</div>
</div>
</div>
<% end_control %>

As you can see, I have access to all fields in the Page type.

Maybe a start. There may be an easier way with 2.3. The above is for 2.2.3

Cheers
Aaron

Avatar
NickJacobs

Community Member, 144 Posts

24 February 2009 at 2:14pm

Great...yeah I thought about it a bit more and came up with this:

in HomePage.php

function getHomePods(){
         return DataObject::get("Page","ShowInMenus = 1 AND ShowOnHomePage = 1", "", "",20);
      }

in HomePage.ss

<% control getHomePods %>
   
      <div class="pagepod">
      
      <div class="pagepodtext"><h2>$Title</h2>
      <p>$Content.LimitWordCountPlainText(25)<a href="$Link" class="moreinfo">more info</a></p>
      </div>
      <div class="pagepodimg">$TeaserImage.SetWidth(175)</div>
      
      <div class="clearer"></div>
      </div>

   <% end_control %>

I'll develop it as I go, but that works great for now. CHeers.