An easy mod to create custom break titles for your sNews articles

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.

Tags

 

You might like

Comments


This is actually a pretty usefull "hack" the more you can customize, the better in my opinion.

Thanks for sharing.


Thx a lot :)


Nifty markuman, I linkified your patch :)

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.


Hi Matt,
this is another smart one I' gonna try yhis day.
Thanks a lot from your keyboard pal from Paris.
Have a nice day.


Has voted: I prefer broccoli too. :-d


lol... damn Sven, I love the vote box styling (the background image is great) you've done with the polls on your site, that looks awesome, outstanding work.


Oh, I know it wasn't your illustration, I just think it's a very good use of it!

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?


Yeap, that's it. a kinda of Ajax. This Ahah script is light and its purpose is to call the comments and the comment box to the home page.
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.


Ahhh, I think I see, but it wouldn't be easier to simply hide a div containing the comments/comment form? To call the entire page again via ajax and extract the comments/comment form would be quite a bit of overhead.


"Ahhh, I think I see, but it wouldn't be easier to simply hide a div containing the comments/comment form?"
Related to the page?


Hmmm, do you mean bring the comments/form to the home/category view?


Yeap that's it:
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 (...)


Hi Matt,

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!


Ahhh, yes Different, I forgot that part. That is needed in function strip for cleaning up the text for RSS.

I'll update the tutorial.

Thanks!


Hi, Matt!
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!


Nice work Different!

Comments are closed. No new comments allowed.

Copyleft 2002 - 2017 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top