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.

Blog Module

Discuss the Blog Module.

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

Pulling SS Blog from another pages


14 Posts   3388 Views

Bruce B

3 July 2011 at 11:19am Community Member, 145 Posts

In page.php, you need to move the LatestNews function. It should sit in the page class near the top of the code. Look for a single closing bracket } around line 10 and insert it just above that.


3 July 2011 at 3:57pm Community Member, 25 Posts

I moved it but sadly I'm still only seeing the no entries message. Any other suggestions?

class Page extends SiteTree {

   public static $db = array(

   public static $has_one = array(

function LatestNews($num=4) {
$news = DataObject::get_one("BlogHolder");
return ($news) ? DataObject::get("BlogEntry", "ParentID = $news->ID", "Date DESC", "", $num) : false;
class Page_Controller extends ContentController {

    * An array of actions that can be accessed via a request. Each array element should be an action name, and the
    * permissions or conditions required to allow the user to access it.
    * <code>
    * array (
    * 'action', // anyone can access this action
    * 'action' => true, // same as above
    * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
    * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
    * );
    * </code>
    * @var array
   public static $allowed_actions = array (

   public function init() {

      // Note: you should use SS template require tags inside your templates
      // instead of putting Requirements calls here. However these are
      // included so that our older themes still work

Bruce B

3 July 2011 at 4:11pm Community Member, 145 Posts

I just noticed. In page.php, the function is called LatestNews, but in its called LatestBlogPosts. That would account for the failure.


3 July 2011 at 4:24pm Community Member, 25 Posts

Bruce, that fixed it. Thanks so much!


23 August 2011 at 7:08am Community Member, 21 Posts

Along these lines, what would be the best way to extend this code to pull only blog posts with a specific tag? For example, to just pull posts tagged with "news" into a list on an "about us" page?

I see a ShowTag() function in BlogHolder.php, but that's looking for URL parameters. SelectedTag() in BlogTree.php appears to do the same thing. Entries() in BlogTree.php looks promising, but I'm not sure I can get there from here. Everything else I'm coming up with is pretty convoluted. I feel like I'm missing something, and this ought to be easier than I'm making it.


23 August 2011 at 7:25am (Last edited: 23 August 2011 7:26am), Community Member, 21 Posts

To follow up, I can make this work via SQL, borrowing some code from Entries() in BlogTree.php. But I feel dirty when I copy & paste code like this.

function LatestBlogPosts($num=5, $tag='') {
if($tag) {
$SQL_tag = Convert::raw2sql($tag);
$tagCheck = "AND \"BlogEntry\".\"Tags\" LIKE '%$SQL_tag%'";
} else {
$tagCheck = '';
$blogs = DataObject::get_one("BlogHolder");
return ($blogs) ? DataObject::get("BlogEntry", "ParentID = $blogs->ID ".$tagCheck, "Date DESC", "", $num) : false;