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   2052 Views

Avatar
1

Community Member, 5 Posts

1 December 2008 at 7:35pm

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

Community Member, 398 Posts

2 December 2008 at 3:46pm

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

Community Member, 5 Posts

4 December 2008 at 7:05pm

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

Community Member, 398 Posts

4 December 2008 at 8:05pm

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