Title of the most recent entry in <title> Tag

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
aschlemmer
Regular
Posts: 70
Joined: Fri Feb 23, 2007 6:13 pm
Location: Freiburg/Germany
Contact:

Title of the most recent entry in <title> Tag

Post by aschlemmer »

Dear all,

Users don't like page that all have the same page title: This is bad for the session history and bad for bookmarking.

I searched the forum a lot but found only one unanswered question regarding my topic:
How do I display the (most recent) entry title in the page title?

If I write

Code: Select all

{$head_title|@default:$blogTitle}: {$entry.title}
it works on single entry pages. On the main page, it displays the title of the oldest entry instead of the latest.

I did try with the recententries_plugin and a number of entries set to "1" which works in the sidebar -- how to activate this for the <title> tag?

This is a very important feature and any help is very appreciated!

Thanks,
achim
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

It sounds like you're trying to modify the title of the page (as opposed to the banner title). If I'm right, you're modifying the index.tpl. In that case, {$entry} is the most recently modified entry: the last one.

Unfortunately, the complete entries array is sorted by dategroup, with sticky entries on top. So the easy way -- pulling the first dategroup out of the entries and using its title -- will get you the sticky entry instead of the newest entry. This will only happen on pages like the front page, where multiple entries are displayed.

Then again, on those pages, you probably don't want an entry title anyway.

So here are a few solutions for you.

If you'd like to use only the blog title on the front page, try this:

Code: Select all

{if $frontpage}
{$head_title|@default: $blogTitle}
{else}
{$head_title|@default: $blogTitle}: {$entry.title}
{/if}
To use the blog title on any page with multiple entries, check $is_single_entry instead. In fact, this would work:

Code: Select all

{$head_title|@default: $blogTitle}{$if $is_single_entry}: {$entry.title}{/if}
Actually obtaining the most recent entry is more difficult. If these other solution won't work for you, we'll take a shot at that.
Judebert
---
Website | Wishlist | PayPal
aschlemmer
Regular
Posts: 70
Joined: Fri Feb 23, 2007 6:13 pm
Location: Freiburg/Germany
Contact:

Post by aschlemmer »

Judebert,

yes, I'm modifying the index.tpl.

I have no sticky entries yet. Could your first idea help me?
pulling the first dategroup out of the entries and using its title -- will get you the sticky entry instead of the newest entry. This will only happen on pages like the front page, where multiple entries are displayed.
Your other two solutions don't fit exactly what I want: On any page with multiple entries (front page, categories) I need the most recent entry title followed by the blog title. If you have another idea on how to obatin such a very useful behaviour, it would be very great for me.

Just a note -- This:

Code: Select all

{$head_title|@default: $blogTitle}{$if $is_single_entry}: {$entry.title}{/if} 
results in a smarty error. Until we have the perfrect way it could have helped a bit -- but to be frank: the most recent entry title is excatly what I'm looking for ...

Thanks for your patience ...
Achim
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

I suppose you'll need to edit the entries.tpl template file and within the second {foreach} loop add:

Code: Select all

{if !$first_entry}
{assign var="first_entry" value=$entry}
{/if}
Then you can change your index.tpl to use {$first_entry.title}, I think.

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/
aschlemmer
Regular
Posts: 70
Joined: Fri Feb 23, 2007 6:13 pm
Location: Freiburg/Germany
Contact:

Post by aschlemmer »

Garvin, you're my wizard!!!

Thanks very much (I'm too weak in PHP and such :-)) -- that's exactly what I needed.

Great!!

See for yourself:
http://www.ms-reporter.de/
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Neat! So the entries.tpl must get handled before the index.tpl. I had been considering that as a possible solution, but I wasn't certain of the order.

The Smarty is invalid because I used {$if}. It should've been just {if}. Sorry; I didn't have access to Smarty at the time to check it out.

Good job, Garvin!
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 judebert!

In fact the nice thing is that all .tpl files get compiled and later used at one place. So no matter in which .tpl file you set a PHP variable, they all get available in index.tpl because that's the last file being included and it cann access all PHP/Smarty variables that were created since. I just recently found that out myself :)

Best regards,
Grvin
# 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