Page 1 of 2

BETA Custom News Block

Posted: 1. November 2008 15:16
by hooplah
I have been working on a custom news block that displays a compact recent news item of any singular forums. I have it so far that it takes you to the forum of a last post but not to the last post in that forum. So the link generated would be something like; http://web site/viewtopic.php?f2&t=26

EDIT: Code working fine after changing as was advised :D

here is the code if it needs improving let me know ;)

latest_posts.php

Code: Select all

<?php

/**
*
* @package - Board3portal
* @version $Id: latest_members.php 325 2008-08-17 18:59:40Z kevin74 $
* @copyright (c) kevin / saint ( www.board3.de/ ), (c) Ice, (c) nickvergessen ( www.flying-bits.org/ ), (c) redbull254 ( www.digitalfotografie-foren.de ), (c) Christian_N ( www.phpbb-projekt.de )
* @based on: phpBB3 Portal by Sevdin Filiz, www.phpbb3portal.com
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

$offsets = 10;
$forumnumber = 2;

$sqls  = "SELECT * FROM phpbb_posts WHERE forum_id = '$forumnumber' ORDER BY Post_id DESC LIMIT $offsets";

$results = $db->sql_query($sqls);

// print the results in a table

while($list = $db->sql_fetchrow($results))
  {

    $template->assign_block_vars('reviews_rows', array(
    
'U_NEWNEWSLINK'   => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $list['forum_id'] . '&t=' . $list['topic_id'] . '&p=' . $list['post_id'] . '#p' . $list['post_id']), 
'R_RELEASETITLE'          => $list['post_subject']

        )
    );
  }


$template->assign_vars(array(
    'S_DISPLAY_LATEST_POSTS' => true,
));

?>
latest_posts.html

Code: Select all

<table class="tablebg" cellspacing="1" width="100%">
    <tr>
        <th class="cat"><span style="float: left"><img src="{T_THEME_PATH}/images/portal/portal_members.png" width="16px" height="16px" alt="" />&nbsp;Latest Additions</span></th>
    </tr>
    <tr class="row1">
        <td>
            <span style="float:left;"><strong>{Title}</strong></span>
            
            <!-- BEGIN reviews_rows -->

            <a href="{reviews_rows.U_NEWNEWSLINK}" >{reviews_rows.R_RELEASETITLE}</a>
         
            <br style="clear:both" />
            
            <!-- END reviews_rows -->
        </td>
    </tr>
</table>
<br /> 
If anyone wants to try this create and put the latest_posts.php in the root\portal\blocks folder, then create latest_posts.html in root\styles\your style\templates\portal\blocks folder.
edit root\portal.php find

Code: Select all

    if ($portal_config['portal_welcome'])
    {
        include($phpbb_root_path . 'portal/block/welcome.'.$phpEx);
    } 
add after

Code: Select all

        include($phpbb_root_path . 'portal/block/latest_posts.'.$phpEx);     
edit root\styles\your style\template\portal\portal_body.php and add the following line where you want the block to appear

Code: Select all

            <!-- INCLUDE portal/block/latest_posts.html --> 
to set the forum you want to display change the value in latest_posts.php for $forumnumber

Re: BETA Custom News Block

Posted: 1. November 2008 16:21
by hooplah
Ok I know i need to use append_sid() function in includes\functions to set sid.

should it be something like

'U_NEWNEWSLINK' => append_sid("{$phpbb_root_path}viewtopic.$phpEx"),

or should i use something like this in the page?

append_sid("{$phpbb_root_path}viewtopic.$phpEx?t=1&f=2");


Any help would be greatly appreciated. Thanks ;)

Re: BETA Custom News Block

Posted: 1. November 2008 17:10
by Kevin
Hi,

i would suggest to do it this way:

replace:

Code: Select all

      'R_ID'                      => $list['post_id'],
      'R_TOPICID'                  => $list['topic_id'],
      'R_FORUMID'                  => $list['forum_id'], 
with:

Code: Select all

'U_NEWNEWSLINK'   => append_sid("$phpbb_root_path}viewtopic.$phpEx", 'f=' . $list['forum_id'] . '&t=' . $list['topic_id'] . '&p=' . $list['post_id'] . '#p' . $list['post_id']), 
and in your template instead of:

Code: Select all

<a href="./viewtopic.php?f{reviews_rows.R_FORUMID}&t={reviews_rows.R_TOPICID}" >{reviews_rows.R_RELEASETITLE}</a> 
just:

Code: Select all

<a href="{reviews_rows.U_NEWNEWSLINK}" >{reviews_rows.R_RELEASETITLE}</a> 
Thank you for sharing! :D

Re: BETA Custom News Block

Posted: 1. November 2008 18:19
by hooplah
Thanks for the help Kevin got it working a treat.

had to change

Code: Select all

'U_NEWNEWSLINK'   => append_sid("$phpbb_root_path}viewtopic.$phpEx", 'f=' . $list['forum_id'] . '&t=' . $list['topic_id'] . '&p=' . $list['post_id'] . '#p' . $list['post_id']), 
to this

Code: Select all

'U_NEWNEWSLINK'   => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $list['forum_id'] . '&t=' . $list['topic_id'] . '&p=' . $list['post_id'] . '#p' . $list['post_id']), 
Updated the code in my orriginal files so anyone who would like this block can have it working fine.

:D

Re: BETA Custom News Block

Posted: 23. December 2008 15:06
by Superman
I've tried adding this block twice and I keep getting errors and lines of code saying it can't modify the header. It also breaks the CSS and the text on the page looks huge.

Re: BETA Custom News Block

Posted: 24. December 2008 15:01
by hooplah
can you post a board link m8 so i can see?

Re: BETA Custom News Block

Posted: 28. December 2008 06:58
by the.ronin
Great mod! Thanks for sharing.

Any suggestions on how to exclude stickied posts or announcements? Also to limit the number of characters in the title?

[edit] I also notice it is posting responses. Any way to get rid of that too?

Re: BETA Custom News Block

Posted: 29. December 2008 13:28
by freedose
Hi,
this is great mod... but i got eror:

Code: Select all

[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3548: Cannot modify header information - headers already sent by (output started at /portal/block/latest_posts.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3550: Cannot modify header information - headers already sent by (output started at /portal/block/latest_posts.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3551: Cannot modify header information - headers already sent by (output started at /portal/block/latest_posts.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3552: Cannot modify header information - headers already sent by (output started at /portal/block/latest_posts.php:1)
what im wrong? Im follow what exactly your code.

Re: BETA Custom News Block

Posted: 30. December 2008 13:05
by hooplah
freedose wrote:Hi,
this is great mod... but i got eror:

Code: Select all

[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3548: Cannot modify header information - headers already sent by (output started at /portal/block/latest_posts.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3550: Cannot modify header information - headers already sent by (output started at /portal/block/latest_posts.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3551: Cannot modify header information - headers already sent by (output started at /portal/block/latest_posts.php:1)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3552: Cannot modify header information - headers already sent by (output started at /portal/block/latest_posts.php:1)
what im wrong? Im follow what exactly your code.
make sure there is no spaces before the <?php line on line 1

Re: BETA Custom News Block

Posted: 30. December 2008 14:05
by freedose
thanks bro!
it work now....

it show like this.
Image


if you could tell me, if able to make table like image below:
Image

Re: BETA Custom News Block

Posted: 31. December 2008 20:22
by hooplah
No Problems, keep an eye on this post over the next couple of weeks i'll make some variations ;)

Re: BETA Custom News Block

Posted: 31. December 2008 21:04
by freedose
of coz bro!
always in my notify topic....

Re: BETA Custom News Block

Posted: 7. February 2009 07:16
by Matt
First, I love this mod. Thank you very much for making it available. I have a quick question about adapting it. Is there a way to make just this block display only the newest topic, without showing replies and without having newly replied to topics show back up?

Thank you very much for your time,
Matt

CHANGE NEEDED

Posted: 6. March 2009 01:59
by can99
TO make this mod work with the latest version of the Database I had to change this line in latest_post.php



$sqls = "SELECT * FROM phpbb_posts WHERE forum_id = '$forumnumber' ORDER BY Post_id DESC LIMIT $offsets";

to


$sqls = "SELECT * FROM posts WHERE forum_id = '$forumnumber' ORDER BY Post_id DESC LIMIT $offsets";

How would you add 2 of these blocks to portal.php?

Posted: 6. March 2009 02:23
by can99
Does anyone have any idea how you could add 2 of these mods to the portal page WITHOUT is screwing up the posts, see I added 2 versions of the mod, one called latest_posts.html and .php and another called latest_newpost.html and .php, and added the code to the portal.php and portal_body.html

It works BUT it just simply duplicates the forum posts in each block ... ie:

Local Business
Concession Trailer For Your Next Event
artist needs condo>guest house

New Poster Lounge
Concession Trailer For Your Next Event
artist needs condo>guest house

Now I am missing something really really simple, does anyone know what it is?