Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Latest Pages Widget - Hide Blog

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1950 Views
  • 1
    Avatar
    Community Member
    5 Posts

    Latest Pages Widget - Hide Blog Link to this post

    Is there a way to hide blog entries from the Latest Pages Widget? How/where would I go about doing this, if it is possible? Thanks!

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Latest Pages Widget - Hide Blog Link to this post

    Hi just replace the LatestPagesWidget.php's content with the following and see.

    <?php

    class LatestPagesWidget extends Widget {
       static $db = array();

       static $title = "Latest Pages";
       static $cmsTitle = "Latest Pages";
       static $description = "Shows the 5 latest pages to be added/edited on the site";

       function LatestPages() {
          $pages = DataObject::get('SiteTree', 'ClassName != `BlogEntry`', '`LastEdited` DESC', '', 5);
          $return = new DataObjectSet();
          foreach($pages as $page) {
             $versioned = Versioned::get_version("SiteTree", $page->ID, $page->Version);
             $author = Member::get_one("Member", "ID = " . (int)$versioned->AuthorID);
             $return->push(new ArrayData(array('Page' => $versioned, 'Author' => $author)));
          }
          return $return;
       }
    }

  • 1
    Avatar
    Community Member
    5 Posts

    Re: Latest Pages Widget - Hide Blog Link to this post

    I tried it (finally) but when I loaded the website I got this error:

    Error

    The website server has not been able to respond to your request

    Your suggestion is the only thing I changed, and I flushed the cache just to be sure since that often saves me. Not this time. What should I try next?

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Latest Pages Widget - Hide Blog Link to this post

    try with this code

    <?php

    class LatestPagesWidget extends Widget {
       static $db = array();
       
       static $title = "Latest Pages";
       static $cmsTitle = "Latest Pages";
       static $description = "Shows the 5 latest pages to be added/edited on the site";
       
       function LatestPages() {
          $pages = DataObject::get('SiteTree', 'ClassName != "BlogEntry" AND ClassName != "BlogHolder"', '`LastEdited` DESC', '', 5);
          $return = new DataObjectSet();
          foreach($pages as $page) {
             $versioned = Versioned::get_version("SiteTree", $page->ID, $page->Version);
             $author = Member::get_one("Member", "ID = " . (int)$versioned->AuthorID);
             $return->push(new ArrayData(array('Page' => $versioned, 'Author' => $author)));
          }
          return $return;
       }
    }

    1950 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.