Increasing number of latest posts in Summary

Increasing number of latest posts in Summary

Postby jeffj on Sun Jun 29, 2008 1:38 am

I am hoping to be able to increase the quantity of "Latest Posts" in the Summary index page from only 1 post to 2+ posts for each blog. I've tried several things, but nothing does the trick. I've looked through this file, but can't figure out how to adjust it to show what I want it to show:
../class/summary/dao/summarystats.class.php

It could be an issue of increasing the number of posts per blog (from "1" to whatever), but I'm not sure if this can be changed... or perhaps it's related to extending the "recent" parameter beyond the default of 7 days. I'm not sure.

Can anyone point me in the right direction of what file(s) to edit and with what code? Thanks.

- jeff
A2 Blog Centre | News and stories from the Asian Access community... powered by LifeType
jeffj
 
Posts: 71
Joined: Mon May 26, 2008 8:10 am
Location: Tokyo, Japan
LifeType Version: v1.2.8

Re: Increasing number of latest posts in Summary

Postby jondaley on Sun Jun 29, 2008 7:37 am

You are in the right place - just need to figure out the right bit of code to change. I am not sure what you want to do though - do you want it to not force the 1 post per blog? That is easy - just comment out the foreach loop below the SQL query in that function that removes the extra posts from each blog. The default case used to be show all posts in all blogs, and people complained because if one guy writes a bunch of posts, no other blog shows up on the summary page.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Increasing number of latest posts in Summary

Postby jeffj on Sun Jun 29, 2008 9:13 am

Jon, I guess that's what I want -- not to force 1 post per blog.

We have a several bloggers (12-15) on 5 different blogs, but no one really posts that often. (So we don't ever run the risk of having 1 blogger monopolize the Summary page.) Therefore, we usually only have a total of 1-2 posts listed in the Summary at any one time. Ultimately, I'd like to have more posts listed in the Summary page.

I'd like to either have the most recent (1) post in each blog regardless of how old it is... or have 2+ posts per blog (and keep the 7-day drop-off or even extend the drop-off period to be about 14 days).

- jeff
A2 Blog Centre | News and stories from the Asian Access community... powered by LifeType
jeffj
 
Posts: 71
Joined: Mon May 26, 2008 8:10 am
Location: Tokyo, Japan
LifeType Version: v1.2.8

Re: Increasing number of latest posts in Summary

Postby jeffj on Sun Jun 29, 2008 10:12 am

Plus, I just noticed I have a new problem. One blog which has been active status -- but fairly inactive in terms of posts lately -- is now going to be used regularly by a new blogger. In preparation for this new blogger, I made a sample post in this blog to see if it would flow into the summary page, Latest Posts section, as it had before upgrading from 1.1.3.

However, the sample post caused the whole summary list of Latest Posts to be completely empty. The summary page is entirely normal, except that the Latest Posts section has no posts in it. When I edited that sample post to be a "draft," the summary page was fine and 2 other posts from other blogs again appeared in the Latest Posts section.
A2 Blog Centre | News and stories from the Asian Access community... powered by LifeType
jeffj
 
Posts: 71
Joined: Mon May 26, 2008 8:10 am
Location: Tokyo, Japan
LifeType Version: v1.2.8

Re: Increasing number of latest posts in Summary

Postby jondaley on Sun Jun 29, 2008 3:58 pm

Having an empty latest posts is odd - I am not sure how that would happen.

The 7 day limit is editable - maybe you would be happy simply making that larger - then you would see one post per blog, but put the deadline to 30 days or something.

I think that constant is either defined at the top of the file (maybe called something-FENCE?) or else you should be able to search for a "7" easily enough.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Increasing number of latest posts in Summary

Postby jeffj on Mon Jun 30, 2008 9:35 am

Actually, I found the place to adjust the default time period that entries drop off...
../class/summary/dao/summarystatsconstants.class.php

<?php
/**
* maximum number of items that will be shown per page in the summary
*/
define( "SUMMARY_DEFAULT_ITEMS_PER_PAGE", 25 );
define( "SUMMARY_DEFAULT_PAGE_SHOW_MAX", 15 );
define( "ALL_GLOBAL_ARTICLE_CATEGORIES", 0 );

/**
* By default show posts from the last 30 days, but please edit this constant
* should you wish to display older data. Just bear in mind that the bigger this
* figure, the bigger the performance hit on your database will be.
*/
define( "SUMMARY_DEFAULT_TIME_FENCE", 30 );
?>

It was already set to "30" days, so I adjusted it up further, which helps in our case, as some bloggers don't post very frequently.

Since we only have 5 total blogs, I would still be interested to know exactly how to increase the default number of posts per blog from 1 to 2. That way, I'll get 10 posts in the summary page. Thanks.
A2 Blog Centre | News and stories from the Asian Access community... powered by LifeType
jeffj
 
Posts: 71
Joined: Mon May 26, 2008 8:10 am
Location: Tokyo, Japan
LifeType Version: v1.2.8

Re: Increasing number of latest posts in Summary

Postby jondaley on Mon Jun 30, 2008 9:49 pm

If you change:
Code: Select all
$blogs[$blog->getId()] = $blog;
to
Code: Select all
$blogs[] = $blog;
you will get all of the posts.
To get up to two posts from each blog, you need a bit of fancier code. Something like this (though I didn't test it so I might have gotten it wrong:

Change:
Code: Select all
            $blogs = Array();
            $blogsDao = new Blogs();
            while( $row = $result->FetchRow()) {
                $blog = $blogsDao->getBlogInfo( $row["blog_id"] );
                $blogs[$blog->getId()] = $blog;
            }


to:
Code: Select all
            $blogs = Array();
            $blogsDao = new Blogs();
            $blogCount = Array();
            while( $row = $result->FetchRow()) {
                $blog = $blogsDao->getBlogInfo( $row["blog_id"] );
                if($blogCount[$blog->getId()] < 2){
                   $blogs[] = $blog;
                   $blogCount[$blog->getId()]++;
                }
            }
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Increasing number of latest posts in Summary

Postby jondaley on Tue Jul 01, 2008 9:07 am

I just noticed a bug in the code I posted, so if you already grabbed it, you'll want to get it again.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Increasing number of latest posts in Summary

Postby jeffj on Sat Jul 05, 2008 10:05 pm

@jon:

Replacing the code you suggested didn't seem to work for me. On my summary page, not only did it not return more than 1 entry per blog under "Latest Posts" in the left column, but it also wiped out everything under Search + Login + "Most Active Blogs" in the right column.

Any thoughts?
A2 Blog Centre | News and stories from the Asian Access community... powered by LifeType
jeffj
 
Posts: 71
Joined: Mon May 26, 2008 8:10 am
Location: Tokyo, Japan
LifeType Version: v1.2.8

Re: Increasing number of latest posts in Summary

Postby jondaley on Sun Jul 06, 2008 8:33 am

It sounds like you must have replaced the wrong code? I don't think it should have touched the most active stuff at all. I think each section has a different function.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Increasing number of latest posts in Summary

Postby jeffj on Sun Jul 06, 2008 10:38 am

I edited the code you listed above, which is found in ../class/summary/dao/summarystats.class.php. You're right that that it does appear in the section which "returns an array of the most active blogs."

Just under that section, though, there is the section of that file which "returns an array of most recent posts."
Code: Select all
        /**
         * returns a list with the most recent articles, but only one per blog so that
         * one blog cannot clog the whole main page because they've posted 100 posts today. Posts that were posted
       * in categories not shown in the main page of each blog will not be shown!
         *
         * @param maxPosts The maximum number of posts to return
         * @return An array of Article objects with the most recent articles.
         */
        function getRecentArticles( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES, $maxPosts = 0 )
        {
            lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );

         $prefix = $this->getPrefix();

         $query = "SELECT a.id AS id, a.blog_id AS blog_id
                 FROM {$prefix}articles a,
                      {$prefix}blogs b
                 WHERE a.date >= ".$this->_startTime." AND a.date <= ".$this->_now."
                       AND a.blog_id = b.id
                       AND b.status = ".BLOG_STATUS_ACTIVE."
                       AND a.status = ".POST_STATUS_PUBLISHED."
                     AND b.show_in_summary = '1'
                     AND a.in_summary_page = '1'";

         if($globaArticleCategoryId != ALL_GLOBAL_ARTICLE_CATEGORIES)
            $query .= " AND a.global_category_id = '".Db::qstr($globaArticleCategoryId)."'";
            
         $query .= " ORDER BY a.date DESC";

            if( $maxPosts <= 0 )
               $maxPosts = $this->_summaryPageShowMax;

      // the multiplier here isn't a very elegant solution but what we're trying to avoid
      // here is a situation where if the limit is '10', then a blog posting 10 articles in one
      // go would use all these 10 'slots' in the result set. Then when the list of posts is
      // post-processed, there would only be one article left... which is definitely not
      // what we'd like
            $query .= " LIMIT 0,".$maxPosts * 15;

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

            if( !$result )
                return Array();

            $blogs = Array();
            $posts = Array();
            $i     = 0;

         $articles = new Articles();
            while( ($row = $result->FetchRow()) && ($i < $maxPosts) ) {
                if (!in_array($row["blog_id"], $blogs))
                {
                    $blogs[] = $row["blog_id"];
                    array_push( $posts, $articles->getArticle($row["id"]) );
                    $i++;
                }
            }

            $result->Close();           

            return $posts;
        }

        function getPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES,
                                       $page = -1,
                                       $itemsPerPage = SUMMARY_DEFAULT_ITEMS_PER_PAGE )
        {
            lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );

         $prefix = $this->getPrefix();

         $query = "SELECT a.id AS id
                 FROM {$prefix}articles a,
                      {$prefix}blogs b
                 WHERE a.date <= ".$this->_now."
                       AND a.blog_id = b.id
                       AND b.status = ".BLOG_STATUS_ACTIVE."
                       AND a.status = ".POST_STATUS_PUBLISHED."
                     AND a.in_summary_page = '1'
                     AND b.show_in_summary = '1'";

         if($globaArticleCategoryId != ALL_GLOBAL_ARTICLE_CATEGORIES)
            $query .= " AND a.global_category_id = '".Db::qstr($globaArticleCategoryId)."'";            

         $query .= " ORDER BY a.date DESC";

            $result = $this->Execute( $query, $page, $itemsPerPage );
           
            if( !$result )
                return Array();

            $posts = Array();
         $articles = new Articles();
            while( $row = $result->FetchRow() ) {
      // if we call Articles::getArticle() we'll be using the cached data
      // if it was already there, instead of mapping the whole row here
                array_push( $posts, $articles->getArticle( $row["id"] ));
            }

            $result->Close();

            return $posts;
        }

        function getNumPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES )
        {
            lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );

         $prefix = $this->getPrefix();


         $query =" a.date <= ".$this->_now."
                      AND a.blog_id = b.id
                       AND b.status = ".BLOG_STATUS_ACTIVE."
                       AND a.status = ".POST_STATUS_PUBLISHED."
                     AND b.show_in_summary = '1'
                     AND a.in_summary_page = '1'";

         if($globaArticleCategoryId != ALL_GLOBAL_ARTICLE_CATEGORIES)
            $query .= " AND a.global_category_id = '".Db::qstr($globaArticleCategoryId)."'";            

            return( $this->getNumItems( "{$prefix}articles a, {$prefix}blogs b", $query, "a.id" ));
        }

Seems to me that I need to edit something in this section.

- jeff
A2 Blog Centre | News and stories from the Asian Access community... powered by LifeType
jeffj
 
Posts: 71
Joined: Mon May 26, 2008 8:10 am
Location: Tokyo, Japan
LifeType Version: v1.2.8

Re: Increasing number of latest posts in Summary

Postby jondaley on Sun Jul 06, 2008 10:04 pm

correct, that is the function I was talking about.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Increasing number of latest posts in Summary

Postby jeffj on Mon Jul 07, 2008 8:44 am

@jon:

Ok, maybe I'm missing something here.
  • The code you posted for me to replace is actually found in the Most Active Blogs section, not the Most Recent Posts section. Replacing the exact code you listed with the new code you suggested resulted in errors.
  • The code in the Most Recent Posts section does not match the original code you advised should be replaced.
  • So although I know what section needs adjusting, I'm not sure about what string to replace.
Could you be a little more specific? Thanks!

- jeff
A2 Blog Centre | News and stories from the Asian Access community... powered by LifeType
jeffj
 
Posts: 71
Joined: Mon May 26, 2008 8:10 am
Location: Tokyo, Japan
LifeType Version: v1.2.8

Re: Increasing number of latest posts in Summary

Postby jondaley on Mon Jul 07, 2008 11:33 am

Ah, sorry. I was looking at the wrong place. I'll try again:

Code: Select all
             $blogs = Array();
            $posts = Array();
            $i     = 0;

            $articles = new Articles();
            while( ($row = $result->FetchRow()) && ($i < $maxPosts) ) {
                if (!in_array($row["blog_id"], $blogs))
                {
                    $blogs[] = $row["blog_id"];
                    array_push( $posts, $articles->getArticle($row["id"]) );
                    $i++;
                }
            }


to:
Code: Select all
             $blogs = Array();
            $posts = Array();
            $blogCount = Array();
            $i     = 0;

            $articles = new Articles();
            while( ($row = $result->FetchRow()) && ($i < $maxPosts) ) {
                if($blogCount[$row["blog_id"]] < 2){
                    $blogCount[$row["blog_id"]]++;
                    $blogs[] = $row["blog_id"];
                    array_push( $posts, $articles->getArticle($row["id"]) );
                    $i++;
                }
            }
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Re: Increasing number of latest posts in Summary - SOLVED!

Postby jeffj on Mon Jul 07, 2008 11:22 pm

Perfect! That's exactly what I wanted... the two most recent posts per blog on the summary page. Plus, earlier in this thread, I was able to extend the range beyond the default 30 days.

Thanks! Maybe these two customizations will be helpful for others.

- jeff
A2 Blog Centre | News and stories from the Asian Access community... powered by LifeType
jeffj
 
Posts: 71
Joined: Mon May 26, 2008 8:10 am
Location: Tokyo, Japan
LifeType Version: v1.2.8


Return to Templates

cron