2012-01-02, 22:29:01
Hi Ian,
The functions of which I speak is from the file inc/site.php and inc/functions.php of News Manager Plugin.
To not change the plugin directly, I chose the option to duplicate in my theme functions.php, all the functions I needed to customize.
In my case, I wanted to display in a sidebar on my homepage a sample of the latest news with a picture.
I've used nm_show_page, nm_show_post (from inc/site.php) and nm_create_excerpt (from inc/functions.php)
I've copied and renamed its in nm_show_sidepage, nm_show_sidepost and nm_create_sideexcerpt in the functions.php of my theme.
You can take a look of my finally code (i've made some just little modification.)
In my homepage.php I've add this :
And that's all
I'm not a programmer to…
and my english is not my cup of tea ;-)
Hoping to have helped
benoît
The functions of which I speak is from the file inc/site.php and inc/functions.php of News Manager Plugin.
To not change the plugin directly, I chose the option to duplicate in my theme functions.php, all the functions I needed to customize.
In my case, I wanted to display in a sidebar on my homepage a sample of the latest news with a picture.
I've used nm_show_page, nm_show_post (from inc/site.php) and nm_create_excerpt (from inc/functions.php)
I've copied and renamed its in nm_show_sidepage, nm_show_sidepost and nm_create_sideexcerpt in the functions.php of my theme.
You can take a look of my finally code (i've made some just little modification.)
Code:
/*******************************************************
*@function for show news on home side bar
*/
/*******************************************************
* @function nm_show_sidepage
* param $index - page index (pagination)
* @action show posts on news sidepage
*/
function nm_show_sidepage($index=0) {
global $NMPOSTSPERPAGE, $NMSHOWEXCERPT;
$posts = nm_get_posts();
$pages = array_chunk($posts, intval($NMPOSTSPERPAGE), true);
if (is_numeric($index) && $index >= 0 && $index < sizeof($pages))
$posts = $pages[$index];
else
$posts = array();
if (!empty($posts)) {
foreach ($posts as $post)
nm_show_sidepost($post->slug, $NMSHOWEXCERPT == 'Y');
if (sizeof($pages) > 1)
nm_show_navigation($index, sizeof($pages));
} else {
echo '<p>' . i18n_r('news_manager/NO_POSTS') . '</p>';
}
}
/*******************************************************
* @function nm_show_sidepost
* param $slug post slug
* param $excerpt - if TRUE, print only a short summary
* @action show the requested post on front-end news sidepage
*/
function nm_show_sidepost($slug, $excerpt=false) {
$excerpt = true;
$file = NMPOSTPATH . "$slug.xml";
$post = @getXML($file);
if (!empty($post) && $post->private != 'Y') {
$url = nm_get_url('post') . $slug;
$title = strip_tags(strip_decode($post->title));
$date = nm_get_sidedate(i18n_r('news_manager/DATE_FORMAT'), strtotime($post->date));
$content = strip_decode($post->content);
if ($excerpt) $content = nm_create_sideexcerpt($content);
# print post data ?>
<section class="nm_post">
<h3 class="nm_post_title">
<a href="<?php echo $url; ?>"><?php echo $title; ?></a>
</h3>
<p class="nm_post_date"><?php echo i18n_r('news_manager/PUBLISHED') . " $date"; ?></p>
<div class="nm_post_content">
<?php echo $content; ?>
<a href="<?php echo $url; ?>">[...]</a>
</div>
<?php
# print tags, if any
if (!empty($post->tags)) {
echo '<p class="nm_post_meta"><b>' . i18n_r('news_manager/TAGS') . ':</b>';
$tags = explode(',', $post->tags);
foreach ($tags as $tag) {
$url = nm_get_url('tag') . $tag;
echo " <a href=\"$url\">$tag</a>";
}
echo '</p>';
}
# show "go back" link, if required
if (strstr($_SERVER['QUERY_STRING'], "post=$slug")) {
echo '<p class="nm_post_back"><a href="javascript:history.back()"><< ';
i18n('news_manager/GO_BACK');
echo '</a></p>';
}
?>
</section>
<?php
} else {
echo '<p>' . i18n_r('news_manager/NOT_EXIST') . '</p>';
}
}
/*******************************************************
* @function nm_create_sideexcerpt
* @param $content the post content
* @return a truncated version of the post content
*/
function nm_create_sideexcerpt($content) {
global $NMEXCERPTLENGTH;
$len = intval($NMEXCERPTLENGTH);
$content = $content;
if (strlen($content) > $len) {
if (function_exists('mb_substr'))
$content = mb_substr($content, 0, $len);
else
$content = substr($content, 0, $len);
}
return "<p>$content</p>";
}
In my homepage.php I've add this :
Code:
<aside id="sidebar">
<article id="news">
<h1>En ce moment…</h1>
<?php nm_show_sidepage(); ?>
</article>
</aside>
And that's all
I'm not a programmer to…
and my english is not my cup of tea ;-)
Hoping to have helped
benoît