1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Order By Pub Date 0.5

Discussion in 'Plugins' started by Nick, Apr 1, 2010.

  1. Nick

    Nick Well-Known Member

    Order By Pub Date
    Version: 0.5
    Author: Nick Ramsay
    Created: 2010/03/28
    Last Updated:
    2010/08/07
    Tested on: Hotaru 1.3.0 ~ 1.4.0
    Plugins Required: Bookmarking
    Plug & Play: Yes
    Supported: Yes

    Description
    This plugin changes the default sorting order of the "top" pages to "date published" instead of "date posted". This applies to RSS feeds as well.

    Instructions
    1. Upload the "order_by_pub_date" folder to your plugins folder.
    2. Install it from Plugin Management in Admin.

    Thanks
    Thanks to Gunaxin Links for making this custom plugin available to the community.

    Revision History
    v.0.5 2010/08/07 - Nick - Sets the publish date if a post is manually set to "top"
    v.0.4 2010/05/28 - Nick - Updated for compatibility with the Bookmarking plugin
    v.0.3 2010/5/07 - Nick - Fixes for better caching in Hotaru 1.2
    v.0.2 2010/4/05 - Nick - "Best from" pages use post_pub_date instead of post_date.
    v.0.1 2010/3/28 - Nick - Released first version
     

    Attached Files:

    hangbowl and Gunaxin like this.
  2. Gunaxin

    Gunaxin Well-Known Member

    Installed and tested. Everything looks good. Thanks Nick!
     
  3. Gunaxin

    Gunaxin Well-Known Member

    Nick,

    Noticed a bug. Once something is on the front page, if someone votes it up, that automatically bumps that article to the top of the sort again. Once its made popular, subsequent votes shouldn't make it popular again, it should just remain where it is in the sort order.

    Also, I've noticed that the 24hrs, 7 days, 30 days etc are still sorted by submission time / date. It would make sense to also move these to popular time/date (also like Digg) since they are also reporting "Top". I find that the 24 hour sort rarely has very much in it, as its currently done. Would it be possible for this plugin to also effect the sorts on those items as well?
     
  4. Nick

    Nick Well-Known Member

    Okay, that was a screamer! I've just updated the Up Down Voting plugin with a fix.

    The default theme has "Best from: " before those filters so it makes sense that they are sorted by most votes.

    It wouldn't make sense to anyone using the "Best from" text in the default theme. ;)

    Take a look at the sb_sort_filter.php template in SB Base. You can comment out the 24 hour filter and un-comment the 48 hour filter if you prefer.

    Try changing the first function to this:
    PHP:
        /**
         * Override the default sort filters for the front page
         */
        
    public function sb_base_functions_preparelist($h)
        {
            if (
    $h->cage->get->keyExists('sort')) { 
                
    $sort $h->cage->get->testAlnumLines('sort');
                if (
    $sort) {
                    
    $h->vars['orderby'] = 'post_pub_date DESC';
                    return 
    true;
                }
            }
            
            if (
    $h->pageName == 'index') { 
                
    $h->vars['orderby'] = 'post_pub_date DESC';
                return 
    true;
            }
        }
    Afterthought: If the filters for 24 hour, etc are all sorted by published date, wouldn't they all show the same results at the top?
     
  5. Gunaxin

    Gunaxin Well-Known Member

    Thanks again. I guess I may have used the wrong wording. The sorting by votes is fine, its more the query for 24 hours that doesn't make sense to me. It is doing that query on the submission date, instead of the popular date. To me, if you are using this plugin, then you probably expect things to function similar to Digg, so you'd expect Best from 24 Hours to be items that have gone popular in the past 24 hours, not items that have been submitted in the past 24 hours. Does that make sense? It would definitely still be sorted by number of votes though.
     
  6. Nick

    Nick Well-Known Member

    Okay, I understand.

    Replace the first function with this. It's hard for me to test, but if it works for you, I'll update the plugin with these changes:

    PHP:
        /**
         * Override the default sort filters for the front page
         */
        
    public function sb_base_functions_preparelist($h)
        {
            if (
    $h->cage->get->keyExists('sort')) { 
                
    $sort $h->cage->get->testAlnumLines('sort');
                if (
    $sort) {
                    switch (
    $sort
                    {
                        case 
    'top-24-hours':
                            
    $start date('YmdHis'strtotime("now"));
                            
    $end date('YmdHis'strtotime("-1 day"));
                            break;
                        case 
    'top-48-hours':
                            
    $start date('YmdHis'strtotime("now"));
                            
    $end date('YmdHis'strtotime("-2 days"));
                            break;
                        case 
    'top-7-days':
                            
    $start date('YmdHis'strtotime("now"));
                            
    $end date('YmdHis'strtotime("-7 days"));
                            break;
                        case 
    'top-30-days':
                            
    $start date('YmdHis'strtotime("now"));
                            
    $end date('YmdHis'strtotime("-30 days"));
                            break;
                        case 
    'top-365-days':
                            
    $start date('YmdHis'strtotime("now"));
                            
    $end date('YmdHis'strtotime("-365 days"));
                            break;
                        default:
                            
    // no default
                    
    }
                    
                    
    // filter to posts made popular by published date
                    
    if (isset($end) && isset($start) && ($sort != 'top-all-time')) {
                        unset (
    $h->vars['filter']['(post_date >= %s AND post_date <= %s)']);
                        
    $h->vars['filter']['(post_pub_date >= %s AND post_pub_date <= %s)'] = array($end$start);
                    }
                    
                    
    // order by pub date
                    
    $h->vars['orderby'] = "post_votes_up DESC, post_pub_date DESC";
                }

                return 
    true;
            }
            
            if (
    $h->pageName == 'index') { 
                
    $h->vars['orderby'] = 'post_pub_date DESC';
                return 
    true;
            }
        }
    P.S. Thank you for the coffee! :D
     
    Gunaxin likes this.
  7. Gunaxin

    Gunaxin Well-Known Member

    Just made those changes, and it doesn't seem to work. Not that I really know what most of that code does, but this part seemed odd to me :

    (post_pub_date >= %s AND post_pub_date <= %s)
     
  8. Nick

    Nick Well-Known Member

    The %s stuff is normal. It's the Wordpress way for running database queries (which we borrowed) :D

    I've updated the code in post #6 with a few fixes that seems to get it working for me.
     
  9. Gunaxin

    Gunaxin Well-Known Member

    Looks like that did it. Thanks!
     
  10. Nick

    Nick Well-Known Member

    Updated: v.0.2 2010/4/05 - Nick - "Best from" pages use post_pub_date instead of post_date.
     
  11. Nick

    Nick Well-Known Member

    UPdated: v.0.3 2010/5/07 - Nick - Fixes for better caching in Hotaru 1.2
     
  12. Nick

    Nick Well-Known Member

    Updated v.0.5 2010/08/07 - Nick - Sets the publish date if a post is manually set to "top", regardless of votes.
     

Share This Page