How can I embed recent topics on my homepage?

Suggestions for improving the site.
Forum rules
Please make sure you've read the Board Policies forum, which spells out the rules and guidelines of this forum.

How can I embed recent topics on my homepage?

Postby mpg187 » Wed Jan 27, 2010 4:15 pm

I don't know where to put this, so I am asking here. (While I am in the suggestions section, I might as well suggest a forum for General Discussion).

My forum's URL is http://operation420.net/forum and my homepage is http://operation420.net/

I want a listing of the forums recent topics to appear on my homepage, would you know how to do this? I have asked on phpbb's forum and had no luck...
Proud HTC Touch Owner (Windows Mobile 6.1 Professional)
http://operation420.net
User avatar
mpg187
Admin Wannabe
 
Posts: 139
Joined: Wed Aug 12, 2009 7:30 pm
Location: By my PSP, and HTC Touch

Re: How can I embed recent topics on my homepage?

Postby SV Pocket PC » Thu Jan 28, 2010 7:31 am

mpg187 wrote:I don't know where to put this, so I am asking here. (While I am in the suggestions section, I might as well suggest a forum for General Discussion).

I don't really want general discussion here. Maybe I'll add a forum one day if I get more than two people who actually participate here, though.

mpg187 wrote:My forum's URL is http://operation420.net/forum and my homepage is http://operation420.net/

I want a listing of the forums recent topics to appear on my homepage, would you know how to do this? I have asked on phpbb's forum and had no luck...

Did you read their blog post How to display posts and topics on external pages? I think that explains it.

I'm not sure why nobody on phpbb.com could point you there.

Steve
Silicon Valley Pocket PC
http://www.svpocketpc.com
User avatar
SV Pocket PC
Site Admin
 
Posts: 204
Joined: Sun Sep 26, 2004 1:39 pm
Location: Hollister, CA

Re: How can I embed recent topics on my homepage?

Postby mpg187 » Fri Jan 29, 2010 1:47 pm

We should try to get more members here... I'll maybe try...

They pointed me there, but I don't understand it. I tried and it dind't work...
Proud HTC Touch Owner (Windows Mobile 6.1 Professional)
http://operation420.net
User avatar
mpg187
Admin Wannabe
 
Posts: 139
Joined: Wed Aug 12, 2009 7:30 pm
Location: By my PSP, and HTC Touch

Re: How can I embed recent topics on my homepage?

Postby SV Pocket PC » Mon Feb 01, 2010 2:56 am

mpg187 wrote:They pointed me there, but I don't understand it. I tried and it dind't work...

There was a problem with Example #1, but it was easily fixed. The code that the author linked to on his own blog seemed to work, though.

Here's what I got with minimal changes (and some template changes):

Last 5 Topics
Last 5 Posts

NOTE: When you link to those items, you'll be logged out. I think those break the user's session, but they're not meant to be used in the forum, of course.

Steve
Silicon Valley Pocket PC
http://www.svpocketpc.com
User avatar
SV Pocket PC
Site Admin
 
Posts: 204
Joined: Sun Sep 26, 2004 1:39 pm
Location: Hollister, CA

Re: How can I embed recent topics on my homepage?

Postby mpg187 » Mon Feb 01, 2010 4:47 pm

What is the php code for those pages?
Proud HTC Touch Owner (Windows Mobile 6.1 Professional)
http://operation420.net
User avatar
mpg187
Admin Wannabe
 
Posts: 139
Joined: Wed Aug 12, 2009 7:30 pm
Location: By my PSP, and HTC Touch

Re: How can I embed recent topics on my homepage?

Postby SV Pocket PC » Tue Feb 02, 2010 6:12 am

lastposts.php
Code: Select all
<?php
/*
* home.php
* Description: example file for displaying latest posts and topics
* by battye (for phpBB.com MOD Team)
* September 29, 2009
*/

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './discuss/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include(
$phpbb_root_path . 'common.' . $phpEx);
include(
$phpbb_root_path . 'includes/bbcode.' . $phpEx);
include(
$phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');
$search_limit = 5;

$posts_ary = array(
'SELECT' => 'p.*, t.*, u.username, u.user_colour',

'FROM' => array(
POSTS_TABLE => 'p',
),

'LEFT_JOIN' => array(
array(
'FROM' => array(USERS_TABLE => 'u'),
'ON' => 'u.user_id = p.poster_id'
),
array(
'FROM' => array(TOPICS_TABLE => 't'),
'ON' => 'p.topic_id = t.topic_id'
),
),

'WHERE' => $db->sql_in_set('t.forum_id', array_keys($auth->acl_getf('f_read', true))) . '
AND t.topic_status <> '
 . ITEM_MOVED . '
AND t.topic_approved = 1'
,

'ORDER_BY' => 'p.post_id DESC',
);

$posts = $db->sql_build_query('SELECT', $posts_ary);

$posts_result = $db->sql_query_limit($posts, $search_limit);

while(
 $posts_row = $db->sql_fetchrow($posts_result) )
{
$topic_title = $posts_row['topic_title'];
$post_author = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']);
$post_date = $user->format_date($posts_row['post_time']);
$post_link = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=" . $posts_row['post_id'] . "#p" . $posts_row['post_id']);
$post_subject = $posts_row['post_subject'];

$post_text = nl2br($posts_row['post_text']);

$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);

$post_text = smiley_text($post_text);

$template->assign_block_vars('announcements', array(
'TOPIC_TITLE' => censor_text($topic_title),
'POST_AUTHOR' => $post_author,
'POST_DATE' => $post_date,
'POST_LINK' => $post_link,
'POST_TEXT' => censor_text($post_text),
'POST_SUBJECT' => $post_subject,
));
}
page_header('Last Posts');

$template->set_filenames(array(
'body' => 'lastposts.html'
));

page_footer();
?>


lastposts.html
Code: Select all
<!-- BEGIN announcements -->
<h2>{announcements.TOPIC_TITLE}</h2>
Post author: {announcements.POST_AUTHOR}<br />
Post date: {announcements.POST_DATE}<br />
<blockquote>{announcements.POST_TEXT}</blockquote>
From: <a href="{announcements.POST_LINK}">{announcements.POST_SUBJECT}</a>
<!-- END announcements -->


lasttopics.php
Code: Select all
<?php
/*
* home.php
* Description: example file for displaying latest posts and topics
* by battye (for phpBB.com MOD Team)
* September 29, 2009
*/

/* create_where_clauses( int[] gen_id, String type )
* This function outputs an SQL WHERE statement for use when grabbing
* posts and topics */

function create_where_clauses($gen_id, $type)
{
global $db, $auth;

$size_gen_id = sizeof($gen_id);

switch(
$type)
{
case 'forum':
$type = 'forum_id';
break;
case 'topic':
$type = 'topic_id';
break;
default:
trigger_error('No type defined');
}

// Set $out_where to nothing, this will be used of the gen_id
// size is empty, in other words "grab from anywhere" with
// no restrictions
$out_where = '';

if ($size_gen_id > 0)
{
// Get a list of all forums the user has permissions to read
$auth_f_read = array_keys($auth->acl_getf('f_read', true));

if ($type == 'topic_id')
{
$sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
WHERE '
 . $db->sql_in_set('topic_id', $gen_id) . '
AND '
 . $db->sql_in_set('forum_id', $auth_f_read);

$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result))
{
// Create an array with all acceptable topic ids
$topic_id_list[] = $row['topic_id'];
}

unset(
$gen_id);

$gen_id = $topic_id_list;
$size_gen_id = sizeof($gen_id);
}

$j = 0;

for ($i = 0; $i < $size_gen_id; $i++)
 {
$id_check = (int) $gen_id[$i]; // If the type is topic, all checks have been made and the query can start to be built 
if( $type == 'topic_id' ) 
{ 
    $out_where 
.= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' '; 
} // If the type is forum, do the check to make sure the user has read permissions
else if( $type == 'forum_id' && $auth->acl_get('f_read', $id_check) )
{
$out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
}

$j++;
}
}

if ($out_where == '' && $size_gen_id > 0)
{
trigger_error('A list of topics/forums has not been created');
}
 else if ($out_where == '') {
    $out_where = 'WHERE 1';
}

return $out_where;
}
 // create_where_clauses

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './discuss/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include(
$phpbb_root_path . 'common.' . $phpEx);
include(
$phpbb_root_path . 'includes/bbcode.' . $phpEx);
include(
$phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');
$search_limit = 5;

$forum_id = array();
$forum_id_where = create_where_clauses($forum_id, 'forum');

$topic_id = array();
$topic_id_where = create_where_clauses($topic_id, 'topic');
    
$topics 
= 'SELECT * FROM ' . TOPICS_TABLE . '
'
 . $forum_id_where . '
AND topic_status <> '
 . ITEM_MOVED . '
AND topic_approved = 1
ORDER BY topic_last_post_id DESC'
;

$topics_result = $db->sql_query_limit($topics, $search_limit);

while ($topics_row = $db->sql_fetchrow($topics_result))
{
$topic_title = $topics_row['topic_title'];
$topic_author = get_username_string('full', $topics_row['topic_poster'], $topics_row['topic_first_poster_name'], $topics_row['topic_first_poster_colour']);
$topic_date = $user->format_date($topics_row['topic_time']);
$topic_last_post = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=" . $topics_row['topic_last_post_id'] . "#p" . $topics_row['topic_last_post_id']);
$topic_last_author = get_username_string('full', $topics_row['topic_last_poster_id'], $topics_row['topic_last_poster_name'], $topics_row['topic_last_poster_colour']);
$topic_link = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=" . $topics_row['topic_id']);
$topic_last_post_date = $user->format_date($topics_row['topic_last_post_time']);

$template->assign_block_vars('announcements', array(
'TOPIC_TITLE' => censor_text($topic_title),
'TOPIC_AUTHOR' => $topic_author,
'TOPIC_DATE' => $topic_date,
'TOPIC_LAST_POST' => $topic_last_post,
'TOPIC_LAST_AUTHOR' => $topic_last_author,
'TOPIC_LINK' => $topic_link,
'TOPIC_LAST_POST_DATE' => $topic_last_post_date,
));
}

page_header('Last Topics');

$template->set_filenames(array(
'body' => 'lasttopics.html'
));

page_footer();
?>


lasttopics.html
Code: Select all
<ol>
<!-- BEGIN announcements -->
<li>
<a href="{announcements.TOPIC_LINK}">{announcements.TOPIC_TITLE}</a><br />
Started by {announcements.TOPIC_AUTHOR} on {announcements.TOPIC_DATE}<br />
<a href="{announcements.TOPIC_LAST_POST}">Last post</a> by {announcements.TOPIC_LAST_AUTHOR} on {announcements.TOPIC_LAST_POST_DATE}<br />
</li>
<!-- END announcements -->
</ol>

I don't want this board turning into a phpBB programming tutorial, so let's not go any further than that.

Steve
Silicon Valley Pocket PC
http://www.svpocketpc.com
User avatar
SV Pocket PC
Site Admin
 
Posts: 204
Joined: Sun Sep 26, 2004 1:39 pm
Location: Hollister, CA

Re: How can I embed recent topics on my homepage?

Postby mpg187 » Tue Feb 02, 2010 8:15 pm

I don't want this board turning into a phpBB programming tutorial, so let's not go any further than that.
Why not?

Anyways, if you don't want it here, then can you answer me here?:
http://www.phpbb.com/community/viewtopi ... #p11943195
Proud HTC Touch Owner (Windows Mobile 6.1 Professional)
http://operation420.net
User avatar
mpg187
Admin Wannabe
 
Posts: 139
Joined: Wed Aug 12, 2009 7:30 pm
Location: By my PSP, and HTC Touch

Re: How can I embed recent topics on my homepage?

Postby SV Pocket PC » Wed Feb 03, 2010 7:15 am

mpg187 wrote:
I don't want this board turning into a phpBB programming tutorial, so let's not go any further than that.

Why not?

Most likely because this is a site discussing Windows Mobile, not phpBB. ;)

mpg187 wrote:Anyways, if you don't want it here, then can you answer me here?:
http://www.phpbb.com/community/viewtopi ... #p11943195

Yes. If you want my help on phpBB, start a thread at phpBB.com and PM me (at phpBB.com, not here) a link to that thread.

Steve
Silicon Valley Pocket PC
http://www.svpocketpc.com
User avatar
SV Pocket PC
Site Admin
 
Posts: 204
Joined: Sun Sep 26, 2004 1:39 pm
Location: Hollister, CA

Re: How can I embed recent topics on my homepage?

Postby mpg187 » Thu Feb 04, 2010 8:34 pm

SV Pocket PC wrote:
mpg187 wrote:
I don't want this board turning into a phpBB programming tutorial, so let's not go any further than that.

Why not?

Most likely because this is a site discussing Windows Mobile, not phpBB. ;)
Who says it can't be about phpbb? (Well I guess you because you are the admin) but most site's have a "General Discussion" for things that don't belong anywhere.
Proud HTC Touch Owner (Windows Mobile 6.1 Professional)
http://operation420.net
User avatar
mpg187
Admin Wannabe
 
Posts: 139
Joined: Wed Aug 12, 2009 7:30 pm
Location: By my PSP, and HTC Touch

Re: How can I embed recent topics on my homepage?

Postby SV Pocket PC » Sat Feb 06, 2010 8:11 am

mpg187 wrote:Who says it can't be about phpbb? (Well I guess you because you are the admin) but most site's have a "General Discussion" for things that don't belong anywhere.

Right, because I'm the admin. :D We covered the General Discussion part in the second post here.

Anyway, I've updated the code post to include the HTML templates as you had trouble with them. Just FYI, I have no real interest in this code; I'm not going to put it on my site or anything. I looked into it just as a favor to you.

Steve
Silicon Valley Pocket PC
http://www.svpocketpc.com
User avatar
SV Pocket PC
Site Admin
 
Posts: 204
Joined: Sun Sep 26, 2004 1:39 pm
Location: Hollister, CA

Next

Return to Suggestions

Who is online

Users browsing this forum: No registered users and 7 guests