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.

Archive

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

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

Latest Pages Widget - Hide Blog


Reply

4 Posts   2028 Views

Avatar
1

1 December 2008 at 7:35pm Community Member, 5 Posts

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!

Avatar
Nivanka

2 December 2008 at 3:46pm Community Member, 395 Posts

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;
   }
}

Avatar
1

4 December 2008 at 7:05pm Community Member, 5 Posts

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?

Avatar
Nivanka

4 December 2008 at 8:05pm Community Member, 395 Posts

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;
   }
}