WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: mikejd on October 18, 2011, 11:46:47 AM

Title: Blog menu snippet
Post by: mikejd on October 18, 2011, 11:46:47 AM
Has anyone used this with the current News v3.5 module?

I have tried to find info from the AMASP link to the forum but it is now very old - no posts since Feb 2010. It is a bit confusing about replacing the view.php file. Should the News v3.5 view.php file still be replaced by the one from the downloaded snippet? I have tried to compare the two files and there are a lot of differences.

Also if I replace the view.php file will this affect any other instances of the News module? I have it already on another page.

Any assistance welcome.

regards,
Mike
Title: Re: Blog menu snippet (SORTED)
Post by: mikejd on October 19, 2011, 01:34:48 PM
I think I have sorted this.

I have implemented the blog menu on a test page but did not change the view.php file. At first I made no changes to the News v3.5 view.php file and it worked but there was a slight problem - clicking a month showed all posts instead of for just the month. So I amended the view.php file with changes suggested by 'skywriter' here
https://forum.WebsiteBaker.org/index.php/topic,6563.75.html (https://forum.WebsiteBaker.org/index.php/topic,6563.75.html) (second post from the end of the thread.
and it now works correctly. It shows the correct number of posts for each category and month and, when you click on the month or category, displays the posts for that month or category.

However, there is a slight anomaly, which on consideration is probably correct, where posts that have an end date do not display, i.e. there might be 3 posts in a month but 1 is past it's end date so only 2 are displayed. At first this threw me slightly but now seems reasonable on reflection.

Hope this helps someone.

Mike
Title: Re: Blog menu snippet
Post by: sky writer on October 19, 2011, 06:15:36 PM
I addressed this "anomaly" here: https://forum.WebsiteBaker.org/index.php/topic,21071.new.html#new

Still waiting for an explanation.
Title: Re: Blog menu snippet
Post by: sky writer on October 19, 2011, 07:02:10 PM
I am still curious about the News Module functionality, but I have fixed my issue specific to the Blog Menu.

To properly display the number of visible posts in the Blog Menu...

In the Blog Menu module, open include.php

change:
Code: [Select]
// make database query and obtain active groups and amount of posts per group
$result = $database->query($query);
if($result->numRows() > 0){
if ($group_header != "") {
echo $group_header;
}
while($group = $result->fetchRow()){
                $id = $group['group_id'];
$query_detail = "SELECT * FROM " .TABLE_PREFIX ."mod_news_posts WHERE page_id=$page_id AND active=true AND group_id=$id;";
$detail_result = $database->query($query_detail);
$num = $detail_result->numRows();
$output .= "<li><a href=\"" .WB_URL.PAGES_DIRECTORY .$page_link .PAGE_EXTENSION ."?g=".$group['group_id']."\">" .$group['title'] ."</a> (".$num.")</li>\n";
    }
}
$output = "<ul>".$output."</ul>";
        echo $output;
}
if($display_option==0 or $display_option==1){ //show history

To:
Code: [Select]
// make database query and obtain active groups and amount of posts per group
$t = time();
$result = $database->query($query);
if($result->numRows() > 0){
if ($group_header != "") {
echo $group_header;
}
while($group = $result->fetchRow()){
                $id = $group['group_id'];
$query_detail = "SELECT * FROM " .TABLE_PREFIX ."mod_news_posts WHERE page_id=$page_id AND active=true
AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t) AND group_id=$id;";
$detail_result = $database->query($query_detail);
$num = $detail_result->numRows();
$output .= "<li><a href=\"" .WB_URL.PAGES_DIRECTORY .$page_link .PAGE_EXTENSION ."?g=".$group['group_id']."\">" .$group['title'] ."</a> (".$num.")</li>\n";
    }
}
$output = "<ul>".$output."</ul>";
        echo $output;
}
if($display_option==0 or $display_option==1){ //show history

To fix the post count in the monthly Blog Menu listing:

Change:
Code: [Select]
$query = "SELECT MONTHNAME(FROM_UNIXTIME(".$date.")) as mo,MONTH(FROM_UNIXTIME(".$date.")) as m,FROM_UNIXTIME(".$date.",'%Y') as y,COUNT(*) as total FROM " .TABLE_PREFIX ."mod_news_posts WHERE page_id=$page_id AND active=true GROUP BY y,m ORDER BY y DESC,m DESC;";
To:
Code: [Select]
$query = "SELECT MONTHNAME(FROM_UNIXTIME(".$date.")) as mo,MONTH(FROM_UNIXTIME(".$date.")) as m,FROM_UNIXTIME(".$date.",'%Y') as y,COUNT(*) as total FROM " .TABLE_PREFIX ."mod_news_posts WHERE page_id=$page_id AND active=true AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t) GROUP BY y,m ORDER BY y DESC,m DESC;";
Hope this helps.