We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Reorder exp:weblog:entries based on interval

Development and Programming

Wouter Vervloet's avatar
Wouter Vervloet
758 posts
16 years ago
Wouter Vervloet's avatar Wouter Vervloet

The title might be a bit vague, but I’ll try to explain it as good as possible…

I’m busy with a site that has a portfolio. Instead of ordering the entries based on the entry_date, title, or whatever I want to sort them by entry_id, but put a different entry on top everyday.

I made a php-function that does just this, but I’m having troubles implementing it in EE.

Here’s the function:

function order_by_interval($array) {
  $returnArray = array();
  $length = count($array);
  $i = (time() / 60 / 60 / 24) % $length;
  for($j=0;$j < $length;$j++) {
    if($i > $length - 1) { $i = 0; }
    $returnArray[$j] = $array[$i];
    $i++;
  }
  return $returnArray;
}

$entries = array(23, 34, 54, 62, 71, 77);
$sorted = order_by_interval($entries);
$string = implode('|', $sorted);

I would then be able to use $string in the new fixed_order parameter for exp:weblog:entries.

The only problem I’ve run into is that I need the entry id’s before I parse the php and I need to use the outcome of that function to sort the entries accordingly. (See my dilemma?)

Hardcoding the fixed_order parameter isn’t really an option since the portfolio is updated regularly.

So I figured I need to whip up an extension that reorders the results before they get sent to the client, but I have no idea which hook I need to grab. I looked over the weblog_entries_tagdata-hook, but rewriting that much code and functionality isn’t my idea of a simple extension… is there another hook that let’s me manipulate the resultset before EE starts returning the data?

Greets, Wizz

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.