Page 1 of 1
Title of the most recent entry in <title> Tag
Posted: Wed Apr 04, 2007 12:07 pm
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
Posted: Wed Apr 04, 2007 4:28 pm
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.
Posted: Wed Apr 04, 2007 4:59 pm
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
Posted: Wed Apr 04, 2007 5:07 pm
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
Posted: Wed Apr 04, 2007 5:13 pm
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/
Posted: Thu Apr 05, 2007 3:42 pm
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!
Posted: Thu Apr 05, 2007 10:24 pm
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