Latest Posts on site home page

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Anti-Spam Guide
Pond Life
Registered User
Posts: 388
Joined: Sat Jan 20, 2007 1:55 am

Re: Latest Posts on site home page

Post by Pond Life » Mon Aug 18, 2008 11:14 pm

This part of the code needs to be at the very top of your page, before <!DOCTYPE...

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = 'Forums/'; // Path to phpbb folder
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
// Grab user preferences
$user->setup();
?>
You can either put the chunk of code there or put it in a separate file and use an include.
Never argue with idiots, they will drag you down to their level and beat you with experience.

juxair
Registered User
Posts: 6
Joined: Thu Aug 07, 2008 7:16 pm
Contact:

Re: Latest Posts on site home page

Post by juxair » Mon Aug 18, 2008 11:30 pm

@ pond Life

ty for your fast reply if this was ment to me but it s only the code on the page

regards
juxair

Pond Life
Registered User
Posts: 388
Joined: Sat Jan 20, 2007 1:55 am

Re: Latest Posts on site home page

Post by Pond Life » Mon Aug 18, 2008 11:42 pm

Then I have no idea, sorry. It worked for me. :?
Never argue with idiots, they will drag you down to their level and beat you with experience.

Bob_La_Londe
Registered User
Posts: 94
Joined: Sun Aug 17, 2008 5:08 pm

Re: Latest Posts on site home page

Post by Bob_La_Londe » Tue Aug 19, 2008 3:55 pm

I am using the original code posted and it works fine since I allow guest viewing.

(I did modify it to show 20 instead of 10 recent topics)

Now, there are two things I would also like to be able to do.

Use it to display recents posts from a particular forum, and to display based on announcement vs not an announcement.

P.S. Excellent piece of original code by the way.

P.P.S. It worked great as a seperate PHP file, and then I just included it using SSI in a "static" shtml page. That allowed me to easily plug it into a pre-existing format. Basically it works perfectly as an external utility.

Pond Life
Registered User
Posts: 388
Joined: Sat Jan 20, 2007 1:55 am

Re: Latest Posts on site home page

Post by Pond Life » Tue Aug 19, 2008 5:45 pm

Bob_La_Londe wrote:Use it to display recents posts from a particular forum
I can help with this bit, I got it to work on mine.

In this bit

Code: Select all

    // Get active topics.
    $sql="SELECT *
    FROM " . TOPICS_TABLE . "
    WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
    ORDER BY topic_last_post_time DESC";
    $result = $db->sql_query_limit($sql,TOPICS_LIMIT);
    while ($r = $db->sql_fetchrow($result))
    {
Change

Code: Select all

    WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
to something like this (4 being the forum id of your choice)

Code: Select all

    WHERE topic_approved = '1' AND forum_id = '4'
and if you want to display topics from more than one selected forums:

Code: Select all

    WHERE topic_approved = '1' AND (forum_id = '6' OR forum_id = '36' OR forum_id = '48')
Sorry, I don't know about the announcement part.
Never argue with idiots, they will drag you down to their level and beat you with experience.

Bob_La_Londe
Registered User
Posts: 94
Joined: Sun Aug 17, 2008 5:08 pm

Re: Latest Posts on site home page

Post by Bob_La_Londe » Tue Aug 19, 2008 5:54 pm

I could back door that to work. I'ld just setup a seperate forum for that announcement, and lock posting to it to all, but the guy who needs to make that announcement. Then I could do an include anywhere I needed to that copy of the script.

I'm also playing with Announcement Centre. Lefty says I can tie an announcement center item to a particular announcement by topic_id in the centre. I could only display it on the forum pages, but it would cover one end of it, and the Announcement Centre is a good looking tool.

I may do both for different things...

cold-machine
Registered User
Posts: 27
Joined: Tue Apr 15, 2008 7:36 pm

Re: Latest Posts on site home page

Post by cold-machine » Wed Aug 20, 2008 1:15 am

i dunno what im doin wrong.. but i still cant get this to wokr..

jo_bb
Registered User
Posts: 18
Joined: Sun Feb 17, 2008 8:42 am

Re: Latest Posts on site home page

Post by jo_bb » Sun Aug 24, 2008 9:14 pm

Re: Latest Posts on site home page
by mitchristina on Sun Aug 10, 2008 6:48 pm

When I use the below code is get a Call to undefined function: request_var()

Anyone know why it is complaining about the request_var function???
I was getting the same error and resolved it by (1) moving my newposts.php file from the root directory to the to the forums directory and (2) editing the "$phpbb_root_path" line in the code.

Initally, even after I customized the line below, the code didn't work...

Code: Select all

$phpbb_root_path = './forum/'; // Path to phpbb folder
...then I noticed all other .php files for my PHPBB3 used the following line instead...

Code: Select all

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
...after I made these changes it worked wonderfully.

Thank you everyone for your input and direction.

k77
Registered User
Posts: 9
Joined: Sun Nov 13, 2005 8:47 pm

Re: Latest Posts on site home page

Post by k77 » Tue Aug 26, 2008 1:09 pm

can i put my last 10 posts on html home page

Bluesplayer
Registered User
Posts: 8
Joined: Sun Nov 18, 2007 12:02 pm

Re: Latest Posts on site home page

Post by Bluesplayer » Wed Aug 27, 2008 12:47 pm

Might be of interest to some but I have used this code to create a drop down menu for my video forums. I used the code found on page 1 and altered it to this:

Code: Select all

<?
    define('IN_PHPBB', true);
    $phpbb_root_path = ''; // Path to phpbb folder
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
    include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);

    // Grab user preferences
    $user->setup();
    
    /*** phpBB3 - Last Active Topics System ***/
    //Show last x topics
    define('TOPICS_LIMIT',1000);

    // Create arrays
    $topics = array();
    
    // Get forums that current user has read rights to.
    $forums = array_unique(array_keys($auth->acl_getf('f_read', true)));
    
    // Get active topics.
    $sql="SELECT *
    FROM " . TOPICS_TABLE . "
       WHERE topic_approved = '1' AND (forum_id = '281' OR forum_id = '282') 
     ORDER BY topic_title ASC";
    $result = $db->sql_query_limit($sql,TOPICS_LIMIT);
    while ($r = $db->sql_fetchrow($result))
    {
        $topics[] = $r;
    }
   $db->sql_freeresult($result);
?>
<div>
<form name="gameslist" action="">
<select style="width: 100%; border:1px solid gray; background: black; color: #FFFFFF; font-family: Arial; font-size: 10px" onChange="document.location.href=this[selectedIndex].value" size="1" name="1">
<OPTION VALUE="___" selected>DAoC Gaming Video Jump List - Click To View</OPTION>
<?
        
    foreach($topics as $t)
    {
        // Get folder img, topic status/type related information
        $topic_tracking_info = get_complete_topic_tracking($t['forum_id'], $t['topic_id']);
        $unread_topic = (isset($topic_tracking_info[$t['topic_id']]) && $t['topic_last_post_time'] > $topic_tracking_info[$t['topic_id']]) ? true : false;
        $folder_img = $folder_alt = $topic_type = '';
        topic_status($t, $t['topic_replies'], $unread_topic, $folder_img, $folder_alt, $topic_type);
        
        // output the link
        ?><option value="<?=$phpbb_root_path . 'viewtopic.php?f=' . $t['forum_id'] . '&t=' . $t['topic_id'] . '&p=' . $t['topic_last_post_id'] . '#p' . $t['topic_last_post_id'];?>"><?=html_entity_decode($t['topic_title']);?></option>
    <?
    }
    ?>
</select><noscript><br /><input type="submit" value="GO"></noscript></form>
</div>
The above code was saved as daoclisting.php and uploaded to the root of my forum.

I copied my existing template by downloading it and renaming it in these files: style.cfg, template.cfg, theme.cfg and then re-uploading it to install it as any other style. This is an identical theme to my default theme. I altered the overall_header.html file to show another black bar with curved corners. Each template is different so you will have to work this out yourself. It isn't hard though. In my case I have also added a search box that was missing from the original template and then added my drop down box to the left of it. To do this I added a table. The complete additional overall_header.html code was this:

Code: Select all

	<div id="page-header" style="margin-top: 5px;">
		<div class="headerbar">
			<div class="inner" align="right"><span class="corners-top"><span></span></span>
<table border="0" width="100%"><tr><td align="center" width="50%">
<script type="text/javascript"><!--
ajaxinclude("/mainforum/daoclisting.php")
// --></script>

</td><td width=50%" align="center">
		<!-- IF S_DISPLAY_SEARCH and not S_IN_SEARCH -->
			<div id="search-box" style="margin-top:0px;">
				<form action="./search.php?st=0&sk=t&sd=d&sr=topics&keywords=" method="post" id="search">
				<fieldset>
					<input name="keywords" id="keywords" type="text" maxlength="128" title="{L_SEARCH_KEYWORDS}" class="inputbox search" value="<!-- IF SEARCH_WORDS-->{SEARCH_WORDS}<!-- ELSE -->{L_SEARCH_MINI}<!-- ENDIF -->" onclick="if(this.value=='{LA_SEARCH_MINI}')this.value='';" onblur="if(this.value=='')this.value='{LA_SEARCH_MINI}';" /> 
					<input class="button2" value="{L_SEARCH}" type="submit" />
					<a href="{U_SEARCH}" title="{L_SEARCH_ADV_EXPLAIN}">{L_SEARCH_ADV}</a> {S_SEARCH_HIDDEN_FIELDS}
				</fieldset>
				</form>
			</div>
		<!-- ENDIF -->
</td></tr></table>
			<span class="corners-bottom"><span></span></span>
</div></div></div>
I used ajaxinclude to incorporate the new code into the template though I will try and bypass this if I can and make it work like an integral part of the phpBB3 forum - if I can work it out! I tend to use ajax include a lot as it nearly always works in whatever script I am working on. You can get hold of the code here:

Ajaxinclude code

No doubt other methods can be used to include the code into the template (and get it to work).

The result of the above code is that on my custom video templates I can easily add a drop down menu that will update itself as I add videos. Also when a user uses the menu the video will show at the right height from the top of the screen which is perfect. This drop down menu can be used for anything and not just videos but in my case it saves a great deal of work as I was adding the videos to this menu manually at one time. As I have a few hundred videos to add from my other scripts this would have been exhausting.

You can view this menu in action here: http://bluesplayer.co.uk/mainforum/viewforum.php?f=276. You will not be able to load a video though unless you register as all the videos are for members only.

Is this a mod? Should I move it elsewhere?

Bob_La_Londe
Registered User
Posts: 94
Joined: Sun Aug 17, 2008 5:08 pm

Re: Latest Posts on site home page

Post by Bob_La_Londe » Sun Aug 31, 2008 6:50 am

Pond Life wrote:
Bob_La_Londe wrote:Use it to display recents posts from a particular forum
I can help with this bit, I got it to work on mine.

In this bit

Code: Select all

    // Get active topics.
    $sql="SELECT *
    FROM " . TOPICS_TABLE . "
    WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
    ORDER BY topic_last_post_time DESC";
    $result = $db->sql_query_limit($sql,TOPICS_LIMIT);
    while ($r = $db->sql_fetchrow($result))
    {
Change

Code: Select all

    WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
to something like this (4 being the forum id of your choice)

Code: Select all

    WHERE topic_approved = '1' AND forum_id = '4'
and if you want to display topics from more than one selected forums:

Code: Select all

    WHERE topic_approved = '1' AND (forum_id = '6' OR forum_id = '36' OR forum_id = '48')
Sorry, I don't know about the announcement part.

Ok. I got a it modified to work:

Example:
http://www.yumabassman.com/1recent.php

Example in Context (Shtml)
http://www.yumabassman.com/#FreeLures

Now I am trying to figure out how to make it work in the overall_header file of the forum. So I can add something that looks like this to the top of the forums.

http://www.yumabassman.com/winner.shtml

I've tried all kinds of strange things.

Bob_La_Londe
Registered User
Posts: 94
Joined: Sun Aug 17, 2008 5:08 pm

Re: Latest Posts on site home page

Post by Bob_La_Londe » Sun Aug 31, 2008 7:59 pm

Still mostly using the original script I just discovered... it does not pick up Global Announcments.

Vinyard_X43q
Registered User
Posts: 19
Joined: Wed Jun 06, 2007 8:14 am

Re: Latest Posts on site home page

Post by Vinyard_X43q » Wed Sep 03, 2008 8:47 am

Just took a look at it. Global Announcements are assigned to forum id 0. To make them show in the list we have to add forum id 0 to the array of forums.

quick fix- add this code:

Code: Select all

    // Add forum id 0 to the list of readable forums so we can view global announcements.
    array_push($forums,0);
after this:

Code: Select all

    // Get forums that current user has read rights to.
    $forums = array_unique(array_keys($auth->acl_getf('f_read', true)));
With that change it should display your global announcements as well.

wireaudio
Registered User
Posts: 26
Joined: Fri Oct 19, 2007 8:14 am

Re: Latest Posts on site home page

Post by wireaudio » Wed Sep 03, 2008 8:57 am

Here's what i use and it works perfectly fine:

Note that this can be done w/o any session integration w/ phpbb3.
This code allows you to pull from ONE forum, or MULTIPLE forums, or ALL forums or exclude SOME forums.
If you want to parse HTML and/or Smilies paths simply change
echo (
with
echo str_ireplace("{smilies_path}","$urlPath/images/smilies/",htmlspecialchars_decode(
(and dont forget to close the ")" at the end either :P)

This way, you can even parse smilies AND HTML if you decide to do so.

Also, this gives you the flexibility to have a hidden forum where you can quickly add/remove posts (for let's say a "news" section or a "downloads" section,) and link those entries to your main web site.

I dont have recent posts on my site right now, but you can check it out.
For a demo, you can look at the News and Announcements on the main page, and at the "Files" section. All those pages have data pulled from a hidden section in the forums. It's like having a CMS in the forum!

And if you need some help to even pull the download link to there, for the posts that have attachments, i can help with that too :P (see the files section of my site).

http://www.frozenphoenix.org


Code: Select all

      <!-- START - Latest topic repeat -->
      <?php
    // Number of latest topics you want shown.
    $topicnumber = 10;
    // Change this to your phpBB path relative to your document. 
    $urlPath = "/forum";
 
    // Database Configuration (Where your phpBB config.php file is located)
    include 'forum/config.php';
   
   // begin variable statements.
    $table_topics = $table_prefix. "topics";
    $table_forums = $table_prefix. "forums";
    $table_posts = $table_prefix. "posts";
    $table_users = $table_prefix. "users";
    $link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect");
    mysql_select_db("$dbname") or die("Could not select database");

   // in my case, forum number 2 5 9 10 11 17 21 22 23 24 25 26 27 28 29 are public forums where the data i pull can be seen by anyone. Read below if you want to know how to EXCLUDE a forum instead of reading from all public forums.

    $query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username
    FROM $table_topics t, $table_forums f, $table_posts p, $table_users u
    WHERE t.topic_id = p.topic_id AND
    f.forum_id = t.forum_id AND
    (t.forum_id = 2 || t.forum_id = 5 || t.forum_id = 9 || t.forum_id = 10 || t.forum_id = 11 || t.forum_id = 17 || t.forum_id = 21 || t.forum_id = 22 || t.forum_id = 23 || t.forum_id = 23 || t.forum_id = 25 || t.forum_id = 26 || t.forum_id = 27 || t.forum_id = 28 || t.forum_id = 29) AND
    t.topic_status <> 2 AND
    p.post_id = t.topic_last_post_id AND
    p.poster_id = u.user_id
    ORDER BY p.post_id DESC LIMIT $topicnumber";
    $result = mysql_query($query) or die("Query failed");				

   //note here that (t.forum_id = 2 || t.forum_id = 5 || t.forum_id = 9 || t.forum_id = 10 || t.forum_id = 11 || t.forum_id = 17 || t.forum_id = 21 || t.forum_id = 22 || t.forum_id = 23 || t.forum_id = 23 || t.forum_id = 25 || t.forum_id = 26 || t.forum_id = 27 || t.forum_id = 28 || t.forum_id = 29) 
  //are the forums that have public access to them. I ONLY want the data pulled from these forums.
  //Also, this can be done if you want to use ALL forums except one lets say, like this:
  //t.forum_id != 2 (this means it will NOT pull from forum 2)
  //begin display

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo  htmlspecialchars_decode("<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td colspan='2' align='left'><span class='style2'><a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\">" .
    $row["topic_title"] . 
    "</a></span></td></tr><tr><td align='left'><div align='left' class='style5'>By <a href=\"$urlPath/memberlist.php?mode=viewprofile&u=$row[user_id]\">" .
    $row["username"] . "</a></div></td><td align='right'><div align='right' class='style5'>" . date('m.d.y', $row["post_time"]) . "</div></td></tr></table><hr>");
    }
    mysql_free_result($result);
    mysql_close($link);
    ?>
   <!-- End Latest topic repeat -->
I'm planning on adding a "previous/next" button in the near future for the news/files/links section. (i.e. if theres over $topicnumber number of news, display the next $topicnumber posts from that section.)

Don't forget to change the echo string accordingly. Feel free to PM me if you got any questions.

Hope this helps a few people.

mykee
Registered User
Posts: 271
Joined: Thu Jun 07, 2007 9:46 pm

Re: Latest Posts on site home page

Post by mykee » Thu Sep 04, 2008 12:26 pm

I think made a plus page to my forum, where user can see all forums, but latest posts/topics top 10 per forums.
Like here:
http://www.nlcafe.hu/forum
I don't want colours, but I need for every forums a latest posts/topics top 5/top 10 on a page. How can I make this page with yours code?
Thanks!

Locked

Return to “[3.0.x] MOD Requests”