Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 10:36:38 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155556 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Blog menu snippet  (Read 433 times)
mikejd

Offline Offline

Posts: 160


« on: October 18, 2011, 10: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
Logged
mikejd

Offline Offline

Posts: 160


« Reply #1 on: October 19, 2011, 12: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
http://www.websitebaker2.org/forum/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
Logged
sky writer

Offline Offline

Posts: 285



« Reply #2 on: October 19, 2011, 05:15:36 PM »

I addressed this "anomaly" here: http://www.websitebaker2.org/forum/index.php/topic,21071.new.html#new

Still waiting for an explanation.
Logged
sky writer

Offline Offline

Posts: 285



« Reply #3 on: October 19, 2011, 06: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:
// 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:
// 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:
$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:
$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.
« Last Edit: October 19, 2011, 06:12:46 PM by sky writer » Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!