An easy mod to create custom break titles for your sNews articles
This is a simple little sNews hack to change the default "read more" link to be whatever text you'd like for the [break] tag. The only real change is we will add a title="" tag within the bracket, and the text inside the title tag will be the text for the "Read more" link.
For example, if you put your break tag in as [break title="Continue reading if you love spinach!"], then the link text will appear as "Continue reading if you love spinach. I prefer broccoli by the way. I've been using this little hack on my site for quite a while.
Step 1) OK, as usual, BACK-UP your snews.php file and work off of a copy. Now find the following line within the articles function;
$short_display = strpos($text, '[break]');
and then simply remove the closing bracket from break, so you end up with this;
$short_display = strpos($text, '[break');
Step 2) Now still within the articles function, find the following line;
file_include(str_replace('[break]', '',$text), $shorten);
Now change this to;
file_include(preg_replace('/\[break(.*)\]/', '',$text), $shorten);
Step 3) Now for the bit that actually outputs the read more text, find;
case ($tag == 'readmore' && strlen($r['text']) > $shorten):
echo $link.$uri.'/'.$r['asef'].'/">'.l('read_more').'</a> ';
break;
and change that block to;
case ($tag == 'readmore' && strlen($r['text']) > $shorten):
if (preg_match("/\[break title=\"(.*)\"\]/i",$r['text'],$matches)) {
$readmore = $matches[1];
} else {
$readmore = l('read_more');
}
echo $link.$uri.'/'.$r['asef'].'/">'.$readmore.'</a> ';
break;
Step 4) Now to fix RSS output, find the function strip, and make the following change;
$search = array('/\[include\](.*?)\[\/include\]/', '/\[func\](.*?)\[\/func\]/', '/\[break(.*?)\]/', '/</', '/>/');
That should be it, you should now have custom break titles like mine. In a later tutorial, I'll explain how to take these out of the infobar and display them inside the article itself.
Comments
RSS Comments Feed
slemborg
Thanks for sharing.
markuman
Matt
You think I should make .patches available with my mods/hacks? Most hosted folks don't seem to have CLI access, so I never really thought about it.
An Arch Linux fan huh? I used to use Arch for my desktop, very bleeding edge, always seemed to break every few weeks, lol, pacman was nifty though. I've been using Zenwalk for a few years now, it's a nice distro.
Sven - Philippe
this is another smart one I' gonna try yhis day.
Thanks a lot from your keyboard pal from Paris.
Have a nice day.
Sven - Philippe
Matt
Sven - Philippe
it's Gil Evgren : the best pin-up illustrator (see more there :
http://carnet.hiseo.fr/epoque/pin-ups-annees-50/gil-evgren-le-norman-rockwell-des-pinups/
Before I go, did you read my post on sNews forum ?
http://snewscms.com/forum/index.php?topic=8610.msg60960#new
What da ya think of it mate?
Matt
I did have a quick look at the post on the forum, I didn't spend a whole lot of time visiting that site though, is it an ajax type script, "click to show comments", etc?
Sven - Philippe
There's not so much to do I think.
On the website I found the script and on the forum I explain the little function needed to call the article comments and the comment box and display them on the home page.
Matt
Sven - Philippe
Related to the page?
Matt
Sven - Philippe
ARTICLE 1 Title
article#1
comment's link to display the existing commments (if there are) and the comment box.
User after having posted should see the message 'Comment has been sent) at this place
ARTICLE 2 Title
article#2
comment's link to display (...)
Different
Excellent!
I'll add my three cents for the correct output RSS.
Please find code in snews.php:
$search = array('/\[include\](.*?)\[\/include\]/', '/\[func\](.*?)\[\/func\]/', '/\[break\]/', '//');
and replace for
$search = array('/\[include\](.*?)\[\/include\]/', '/\[func\](.*?)\[\/func\]/', '/\[break(.*)\]/', '//');
Enjoy!
Matt
I'll update the tutorial.
Thanks!
Different
You can make a smart button "Intro Break".
You need only to replace the standard code (intro) in the file admin.js:
case 'intro':
moread = prompt("", '');
if (moread == null) {
start = '';
end = '';
}
else if (moread != '') {
start = '';
end = '[break title="'+moread+'"]';
} else {
start = '';
end = '[break]';
}
break;
Do not forget to add the variable 'moread':
// basic html textarea editor
function tag(tag) {
var src = document.getElementById('txt');
var start, end, moread, url, width, border, align, alt, title='';
And to add language variable $l['js_title'].
Enjoy!
Matt