Entrie Order

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
hawaigaign
Regular
Posts: 37
Joined: Thu Sep 14, 2006 11:43 am

Entrie Order

Post by hawaigaign »

Hi

Can I change the entry order of my blog? i'd like to have the oldest entries first, and the latest last.

Thanks for help

hawa
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Entrie Order

Post by garvinhicking »

Hi!

You can edit the file include/functions_entries.inc.php and replace

Code: Select all

function &serendipity_fetchEntries($range = null, $full = true, $limit = '', $fetchDrafts = false, $modified_since = false, $orderby = 'timestamp DESC', $filter_sql = '', $noCache = false, $noSticky = false, $select_key = null, $group_by = null, $returncode = 'array') {
with this:

Code: Select all

function &serendipity_fetchEntries($range = null, $full = true, $limit = '', $fetchDrafts = false, $modified_since = false, $orderby = 'timestamp ASC', $filter_sql = '', $noCache = false, $noSticky = false, $select_key = null, $group_by = null, $returncode = 'array') {
Note the changed "DESC" to "ASC".

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
hawaigaign
Regular
Posts: 37
Joined: Thu Sep 14, 2006 11:43 am

Post by hawaigaign »

thanks! works
One Eye Pied
Regular
Posts: 30
Joined: Wed Jan 18, 2006 6:35 pm
Contact:

Post by One Eye Pied »

Is there a way to change entry order only for a specific category ?
I try several plugins, and they don't do exactly what I want :
- filter entries : show the draft entries and is not automatic.
- category template : do not have the option.

I need this fonctionnality because I manage a blog with comics inside, and some stories are separated in several entries in the same category. So with the actual configuration visitor can not read the comics in the right order...

One Eye Pied
PS : sorry if some words aren't really english :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi Pied!

Entries are always sorted by either their "sticky posting" attribute [can be applied using the extended options when having the Extended Properties event plugin active] or by their timestamp.

Thus, if you change the time of your postings, you can arrange them in a specific order?

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
One Eye Pied
Regular
Posts: 30
Joined: Wed Jan 18, 2006 6:35 pm
Contact:

Post by One Eye Pied »

Thanks for this fast answer Garvin !

The probleme is I don't want to change the time of my posting because I want to keep in mind when the drawing was sent online.

My idea is :
- On the main page entries are ordered anti-chronologically.
- On a category page entries are ordered chronologically.

And if it's possible to change this order only for specified categories, it'll be the best way for me.

Is this possible ?

One Eye Pied
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

With the "templates for categories" plugin (whose name I'm just too busy to remember right now, sorry), you could specify different templates for different categories. Then, if your templates sort the entries oppositely, you get what you're asking for.

For instance, I'd have my usual template -- call it "comics", for demonstration purposes -- and I'd make a copy called "comics_antichron" or similar. Copy the style.css and entries.tpl from comics into comics_antichron.

Now the hard part: edit the comics_antichron/entries.tpl. See the first foreach? It should look like:

Code: Select all

{foreach from=$entries itemj="dategroup"}
That iterates over all the entires, in order. Since Serendipity can't be configured to return the entries in backwards order, we're going to iterate over them in backwards order.

Just change that line to:

Code: Select all

{section name="antichron" loop=$entries step="-1"}
{assign var="dategroup" value=`$entries[antichron]`}
Then change the /foreach to a /section.

Finally, assign the categories where you want reverse-chronological entries to the comics_antichron template in the plugin.

I believe this will do what you wanted, but I'm still a pretty novice Smarty programmer. Let me know if there are any problems.
Judebert
---
Website | Wishlist | PayPal
One Eye Pied
Regular
Posts: 30
Joined: Wed Jan 18, 2006 6:35 pm
Contact:

Post by One Eye Pied »

Ok, I try your tips but It do not works :(
It display an error, that I can pass by commenting the following lines (the /foreach also close the foreachelse):

Code: Select all

{foreachelse}
{if not $plugin_clean_page}
{$CONST.NO_ENTRIES_TO_PRINT}
{/if}
Then, it only display the today date...
One good thing : I've got the good number of pages and entries for the category.

Aaargh, it look like a godd answer at first sight !! :)

One Eye Pied

PS : my template is very simple : it's the default template, but with a very simple css and template tunning. I had to copy the entries.tpl from the default template to try your tips.
One Eye Pied
Regular
Posts: 30
Joined: Wed Jan 18, 2006 6:35 pm
Contact:

Post by One Eye Pied »

After a lot of search I found an answer.
The only problem, is that the ordering change is enable for all categories.
I edit genpage_inc.php and change the line 45 from :

Code: Select all

serendipity_printEntries(serendipity_fetchEntries($serendipity['range'], true, $serendipity['fetchLimit']));
to

Code: Select all

serendipity_printEntries(serendipity_fetchEntries($serendipity['range'], true, $serendipity['fetchLimit'], false, false, 'timestamp ASC'));
Thanx for helping !

One Eye Pied
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

If you're still interested in the ordering per-category, just change the foreachelse to a sectionelse.
Judebert
---
Website | Wishlist | PayPal
One Eye Pied
Regular
Posts: 30
Joined: Wed Jan 18, 2006 6:35 pm
Contact:

Post by One Eye Pied »

It doesn't work. It only display the today date, and the link for next entry... which only display the today date.

Thanks

One Eye Pied
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

This is my fault, I'm afraid, as a Smarty newbie. I just registered on their forums and discovered that {section} is only useful for numerical, 0-based, sequential arrays.

If you still want per-category sorting, we'll have to go a little deeper. You've already demonstrated that you know enough PHP to make the necessary modifications, so I'll describe them now. Feel free to ignore this if you like.

First, we'll need a reversing modifier for Smarty. Luckily, Serendipity is set up to do this kind of thing. Even luckier: since we're writing PHP, we can keep the sticky entries on the top!

In your template, make a config.inc.php and add this code:

Code: Select all

function reverse_entries($entries) {
  $reversed_entries = array();
  $sticky_entries = array();
  $unsticky_entries = array();
  // Separate the entries into sticky and non-sticky
  foreach ($entries as $date => $entry {
    if ($entry['is_sticky']) {
      $sticky_entries[$date] = $entry;
    } else {
      $unsticky_entries[$date] = $entry;
    }
  }
  // Reverse the unsticky entries only, keeping keys
  $unsticky_entries = array_reverse($unsticky_entries, true);
  // Put stickies on top, reversed unstickies on bottom
  $reversed_entries = $sticky_entries + $unsticky_entries;
  return $reversed_entries;
}

// Register the reversing function for Smarty
$serendipity['smarty']->register_modifier('reverse_entries','reverse_entries');
Now, in your templates, you have a new weapon. Revert to the original entries.tpl, and change the foreach line to:

Code: Select all

{foreach from=$entries|@reverse_entries item="dategroup"}
All we did was add our modifier, called on the entire array. Using the existing template-categories plugin, you can use this reversed template only for the categories you want reversed. Sticky entries will still be on the top, which I think is a bonus.

I haven't tested this, because I just don't have the time. I fully understand if you don't want to test it yourself. I just wanted to provide a better solution than hacking the core code.
Judebert
---
Website | Wishlist | PayPal
One Eye Pied
Regular
Posts: 30
Joined: Wed Jan 18, 2006 6:35 pm
Contact:

Post by One Eye Pied »

I try your code and...

Code: Select all

function reverse_entries($entries) { $reversed_entries = array(); $sticky_entries = array(); $unsticky_entries = array(); // Separate the entries into sticky and non-sticky foreach ($entries as $date => $entry { if ($entry['is_sticky']) { $sticky_entries[$date] = $entry; } else { $unsticky_entries[$date] = $entry; } } // Reverse the unsticky entries only, keeping keys $unsticky_entries = array_reverse($unsticky_entries, true); // Put stickies on top, reversed unstickies on bottom $reversed_entries = $sticky_entries + $unsticky_entries; return $reversed_entries; } // Register the reversing function for Smarty $serendipity['smarty']->register_modifier('reverse_entries','reverse_entries');
Fatal error: Smarty error: [in file:/mnt/105/sdc/f/c/yannor/serendipity/templates/yannor_dk/entries.tpl line 4]: [plugin] (secure mode) modifier 'reverse_entries' is not allowed (core.load_plugins.php, line 118) in /mnt/105/sdc/f/c/yannor/serendipity/bundled-libs/Smarty/libs/Smarty.class.php on line 1088
Ouch, great error ;) I do not analyse the error, I'm too tired for doing this.
And, again, thank for searching an answer to this problem.

One Eye Pied
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Weird. I'm sorry to have put you through all this. If I find a solution that works on one of my test blogs, I'll post again; until then, I won't bother you any more.

Garvin, why can't I register this modifier? It's not a standard PHP call, so I figured it would bypass security.
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

the code above looks to me as if he added the PHP code to a smarty template instead of into config.inc.php?!

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply