Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Show page list on homepage

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1165 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Show page list on homepage Link to this post

    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!

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Show page list on homepage Link to this post

    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

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Show page list on homepage Link to this post

    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.

    1165 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.