Adding a blog list in the standard template

Adding a blog list in the standard template

Postby ladenise on Wed Jan 30, 2008 7:35 am

Hello all,

I would like to add the list of existing blogs under the menu of a blog view.
But it seems that :
Code: Select all
{foreach from=$blogs item=blog}
          {$blog->getBlog()|strip_tags}
    {/foreach}

doesn't work in the standard template.

Could you help me please ?
ladenise
 
Posts: 3
Joined: Wed Jan 30, 2008 7:29 am

Postby jondaley on Wed Jan 30, 2008 12:46 pm

You are trying to get a list of all other blogs on the system inside one blog, rather than on the summary page?

Correct, the $blogs object does not exist when viewing a blog, since a "regular" blog doesn't need access to that.

The best way would be to write a plugin that returns all of the blogs.

I think all you need is a function that says:

Code: Select all
lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );

function getBlogs(){
  return new Blogs();
}
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Thx jondaley

Postby ladenise on Thu Jan 31, 2008 4:45 am

I found the solution later in the day but thanks for your help.
ladenise
 
Posts: 3
Joined: Wed Jan 30, 2008 7:29 am

Postby nOoOb on Thu Jan 31, 2008 8:40 am

Perhaps it could be kind to share that solution ?
Or was it exactly the solution jondaley mentionned ?
nOoOb
 
Posts: 10
Joined: Tue Jan 29, 2008 7:00 pm

Postby ladenise on Thu Jan 31, 2008 9:31 am

It was the exact solution:
<?php
lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );

class PluginBloglist extends PluginBase {

var $_prefix;

function PluginBloglist( $source ) {
$this->PluginBase( $source );

$this->id = "bloglist";
$this->author = "Denis Fingonnet";
$this->desc = "This plugin offers you to show a list of blogs.";
$this->version = "20080131";

$this->db =& Db::getDb();
$this->_prefix = Db::getPrefix();
}

function getBloglist() {
$blogs = new Blogs();
$siteBlogs = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE );
return $siteBlogs;
}

function getLastblogs() {
$where = " WHERE status = '" . Db::qstr(BLOG_STATUS_ACTIVE) . "'";

$query = "SELECT * FROM " . $this->_prefix . "blogs $where ORDER BY create_date DESC";

$result = $this->db->Execute($query);

if(!$result || ($result->RecordCount() == 0))
return false;

$blogs = Array();
while( $row = $result->FetchRow()) {
// map the row we just loaded
$blog = $this->mapRow( $row );
$blogs[$blog->getId()] = $blog;
}
$result->Close();

return $blogs;
}

function mapRow( $row ) {
// source class
lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );

// create new BlogInfo
$blogInfo = new BlogInfo( stripslashes($row["blog"]),
$row["owner_id"],
stripslashes($row["about"]),
unserialize($row["settings"]),
$row["id"] );

// load information about the blog status
$blogInfo->setStatus( $row["status"] );
// load information abotu the blog category id
$blogInfo->setBlogCategoryId( $row["blog_category_id"] );
// counters
$blogInfo->setTotalPosts( $row['num_posts'] );
$blogInfo->setTotalTrackbacks( $row['num_trackbacks'] );
$blogInfo->setTotalComments( $row['num_comments'] );
// mangled blog
$blogInfo->setMangledBlogName( $row['mangled_blog'], false );
$blogInfo->setCustomDomain( $row['custom_domain'] );
// show in summary or not
$blogInfo->setShowInSummary( $row['show_in_summary'] );
// create date and update date
$blogInfo->setCreateDate( $row['create_date'] );
$blogInfo->setUpdateDate( $row['last_update_date'] );

return $blogInfo;
}
}
?>
ladenise
 
Posts: 3
Joined: Wed Jan 30, 2008 7:29 am

Postby nOoOb on Thu Jan 31, 2008 7:00 pm

Thanks :)
nOoOb
 
Posts: 10
Joined: Tue Jan 29, 2008 7:00 pm

Re: Adding a blog list in the standard template

Postby brass on Tue Apr 15, 2008 11:42 pm

ladenise wrote:Hello all,

I would like to add the list of existing blogs under the menu of a blog view.
But it seems that :
Code: Select all
{foreach from=$blogs item=blog}
          {$blog->getBlog()|strip_tags}
    {/foreach}

doesn't work in the standard template.

Could you help me please ?


I'm unable to figure out how this works in the summary page. It works when I click the "Blogs" menu item, but when I put the foreach snippet in summary/index.template nothing happens. Can someone point me in a direction?
brass
 
Posts: 17
Joined: Sat Apr 08, 2006 9:30 am

Re: Adding a blog list in the standard template

Postby jondaley on Fri Apr 18, 2008 4:54 pm

That's because they use different views, blogslist.template uses class/summary/view/summarybloglistview.class.php which has the $blogs object assigned. That object isn't assigned in summarycachedview, which is what the front page uses.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch


Return to Templates

cron