2012-10-06, 21:37:57
I think News Manager is a great plug-in. It does everything I need for the minimal blog I run. I have added a couple of tweaks to my installation which I thought I'd share here - they might be useful to someone else.
1) When editing posts I found it irked me that there wasn't a "Save" button in the sidebar like there is when editing pages. I have added one by making a simple change to the file /plugins/news_manager/template/edit_post.php. At the very end of the file, before:
add the following:
2) I didn't like the fact that News Manager would truncate in the middle of a word when producing it's excerpts, so I fixed that with the following method:
Paste this code into /admin/inc/theme_functions.php
Then, in the file /plugins/news_manager/inc/site.php, find the function called "nm_show_post" and replace the following line:
with:
I hope these snippets of code are useful to someone.
1) When editing posts I found it irked me that there wasn't a "Save" button in the sidebar like there is when editing pages. I have added one by making a simple change to the file /plugins/news_manager/template/edit_post.php. At the very end of the file, before:
Code:
});
</script>
add the following:
Code:
// BOF: Let's have that extra submit button in the sidebar (same as with the page editor)
$('.submit').clone().appendTo('#sidebar');
$('#sidebar .submit').css({'margin-left': '14px'}).click(function() { $('form#edit.largeform input.submit').trigger('click'); });
// EOF: Let's have that extra submit button in the sidebar (same as with the page editor)
2) I didn't like the fact that News Manager would truncate in the middle of a word when producing it's excerpts, so I fixed that with the following method:
Code:
/**
* Takes a block of text/HTML and trims it's length to $NMEXCERPTLENGTH, but will
* only trim at a whitespace character.
* If a $url is supplied, then a "read more" link will be appended to the snippet.
*
* @param text/HTML $snippet The text/HTML to trim.
* @param text $url The "read more" URL.
* @return text The trimmed text, stripped of HTML.
*
*/
function trim_snippet($snippet, $url = false) {
global $NMEXCERPTLENGTH;
$cutOff = intval($NMEXCERPTLENGTH);
$snippet = strip_tags($snippet);
if (strlen($snippet) > $cutOff) {
$whole_words = explode(' ', $snippet);
$return_snippet = '';
$test_return_snippet = '';
foreach ($whole_words as $word) {
$test_return_snippet = $return_snippet . ' ' . $word . ' …' . ($url ? ' [<a href="' . $url .'">read more</a>]' : '');
if (strlen($test_return_snippet) <= $cutOff) {
$return_snippet = $return_snippet . ' ' . $word;
} else {
$return_snippet = $return_snippet . ' …' . ($url ? ' [<a href="' . $url .'">read more</a>]' : '');
break;
}
}
$snippet = $return_snippet;
}
return $snippet;
}
Paste this code into /admin/inc/theme_functions.php
Then, in the file /plugins/news_manager/inc/site.php, find the function called "nm_show_post" and replace the following line:
Code:
if ($excerpt) $content = nm_create_excerpt($content);
with:
Code:
if ($excerpt) $content = '<p>' . trim_snippet($content, $url) . '</p>';
I hope these snippets of code are useful to someone.