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)
Scam Warning
kazooki
Registered User
Posts: 3
Joined: Tue Jul 17, 2012 12:50 pm

Re: Latest Posts on site home page

Post by kazooki »

Scrap that I figured it.

I simply replaced

Code: Select all

$url = generate_board_url() . "/viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}";
with ..

Code: Select all

$url = "http://www.domainname.co.uk/forum/viewtopic.{$phpEx}?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}";
All works great now :)
alexintour
Registered User
Posts: 4
Joined: Tue Jan 04, 2011 12:59 pm

Re: Latest Posts on site home page - time setting is wrong

Post by alexintour »

Perhaps it's going to be useful to someone.

I have a phpbb forum and an external site where I'm including a lasttopics.php page, which shows up the latest posts or topics.

The main problem is that both phpbb and the site have GMT/UTC time settings, and while the posts are taken from the forum and displayed to the site, every date misses two hours (I'm UTC -2 and think that both phpbb and the site are taking their -2 hours from the posts).

As a result, I was missing 2 hours on the site (but only for the lastposts, because every other date is OK).

Yes, I said WAS missing, because here there is a very simple solution:

Just add this line:

Code: Select all

date_default_timezone_set('Europe/Rome'); 
before:

Code: Select all

$table_topics = $table_prefix. "topics";
    $table_forums = $table_prefix. "forums";
and everything should be great.

Of course put your location instead of Rome! :)
Hope this helps.


On the other hand, I still have something else that troubles me.
Both forum and site has UTF-8, but the topics are loosing the encoding.
I mean, in the forum everything is great, like the éàù letters, but on the site this letters are changed, like that the double encoding isn't good for them (like it was for the post time).

Has someone a solution for this?
Thanks.

NEVERMIND, I seem to have found the solution also for this one. It seems the collation of my database is different from utf-8 or something like this.
To avoid strange characters in topic names, you should put

Code: Select all

@mysql_query('SET CHARACTER SET UTF8');
before

Code: Select all

$query = "SELECT t.topic_id, t.topic_title, t.to.....
payam30
Registered User
Posts: 9
Joined: Fri Dec 28, 2012 9:03 am

Re: Latest Posts on site home page

Post by payam30 »

Hi,
I use this code you guy wrote in the first page and it works like a charm. I have one more question..
How do I do so when user hover over the link with the mouse it apears a little of the last post? like 10 words and it disapears when the mouse is gone..
I don't know so much PHP . Hope you guys can help
techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: Latest Posts on site home page

Post by techman41973 »

Great MOD idea! This thread goes back many years. Can anyone post their updated working code.
Also, please share your demo sites. You can PM me if you prefer.
Thanks
5hocK
Registered User
Posts: 3147
Joined: Wed Nov 23, 2011 7:00 pm
Location: UK

Re: Latest Posts on site home page

Post by 5hocK »

You means something like this? https://www.phpbb.com/customise/db/mod/ ... nt_topics/
Can be modified to display on a custom page.
techman41973
Registered User
Posts: 410
Joined: Thu Mar 28, 2013 10:27 pm

Re: Latest Posts on site home page

Post by techman41973 »

5hock. That solution is similar but not the same.
I'm looking to replicated the Acitivity Feed of some of the new forums.
This mod is for recent topics, not posts.
I'd like to show recent posts and few lines of each post.
I've posted on Recent Topics requesting if there is an easy way to modify that mod for my needs.
But still, it would be great to see a demo of this abandoned mod and the latest code for it.
Thank you!
5hocK
Registered User
Posts: 3147
Joined: Wed Nov 23, 2011 7:00 pm
Location: UK

Re: Latest Posts on site home page

Post by 5hocK »

techman41973 wrote:5hock. That solution is similar but not the same.
I'm looking to replicated the Acitivity Feed of some of the new forums.
This mod is for recent topics, not posts.
I'd like to show recent posts and few lines of each post.
I've posted on Recent Topics requesting if there is an easy way to modify that mod for my needs.
But still, it would be great to see a demo of this abandoned mod and the latest code for it.
Thank you!
It's in the MODs database, not abandoned ;)
but yeah it's topics.


Edit: Misread your post, sorry.
Flippi
Registered User
Posts: 4
Joined: Tue Oct 08, 2013 9:17 am

Re: Latest Posts on site home page

Post by Flippi »

I don't know, I'm not all a professional, but the following code does the job for me (displaying the 10 latest topic-posts):

Code: Select all

<?php

$connect = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error());
mysql_select_db('databasename') or die(mysql_error());

$query  = "SELECT forum_id, topic_id, post_id, post_subject FROM phpbb_posts WHERE post_approved='1' ORDER BY post_time DESC limit 10";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    echo "<a href=\"/forum/viewtopic.php?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}\">".$row['post_subject']."</a><br />";

}

mysql_close($connect);

?>
Just replace 'mysql_user', 'mysql_password', 'databasename' and 'localhost' if necessary.
Please correct me when the code above is wrong.

I've seen a lot of code in this topic with a lot of problems too. Please tell me why I shouldn't use this small piece of code above instead.

Flippi
Flippi
Registered User
Posts: 4
Joined: Tue Oct 08, 2013 9:17 am

Re: Latest Posts on site home page

Post by Flippi »

Hi,

I've slightly changed the code of the script in my previous post.
That script displayed the 10 latest posts of a phpbb forum on your index page or whatever page of your site you want. So when you have a very popular topic with lots of posts, all links will go to the same topic.
It's much better to have 10 links to 10 different topics and that's what the script below does.

The script below displays the subject of the 10 latest active topics and links to the last post in each of these 10 topics:

Code: Select all

<?php

$connect = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error());
mysql_select_db('databasename') or die(mysql_error());

$query ="SELECT forum_id, topic_id, topic_last_post_id, topic_title FROM phpbb_topics WHERE topic_approved='1' ORDER BY topic_last_post_time DESC limit 10";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    echo "<a href=\"/forum/viewtopic.php?f={$row['forum_id']}&t={$row['topic_id']}&p={$row['topic_last_post_id']}#p{$row['topic_last_post_id']}\">".$row['topic_title']."</a><br />";

    }

mysql_close($connect);

?>
Just include this code on whatever php-page you want to display the subjects (with links) to your most active topics (change 'mysql_user', 'mysql_password', 'databasename' and 'localhost' if necessary)

Bye,

Flippi
User avatar
c64persian
Registered User
Posts: 87
Joined: Tue Sep 18, 2012 11:58 pm
Location: instagram:c64persian

Re: Latest Posts on site home page

Post by c64persian »

how to add persian last post time in this scroll code?

Code: Select all

<?php

    // How Many Topics you want to display?
    $topicnumber = 10;
    // Scrolling towards up or down?
    $scroll = "up";
    // Change this to your phpBB path
    $urlPath = "/forum";

    // Database Configuration (Where your phpBB config.php file is located)
    include 'config.php';

    $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");

    $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 != 4 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");                           

    print "<marquee id=\"recent_topics\" behavior=\"scroll\" direction=\"$scroll\" height=\"170\" scrolldelay=\"100\" scrollamount=\"2\" onMouseOver=\"document.all.recent_topics.stop()\" onMouseOut=\"document.all.recent_topics.start()\">
    <table cellpadding='3' cellSpacing='2' width='100%'>";
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    echo  "<tr valign='top'><td><font face=\"Tahoma\" size=\"1\"><font color=\"#FFCC00\"><b><a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\" TARGET=\"_blank\">" .
    $row["topic_title"] .
    "</a></td></font></b><td><font face=\"Tahoma\" size=\"1\"><font color=\"#C0C0C0\"> by: <a href=\"$urlPath/memberlist.php?mode=viewprofile&u=$row[user_id]\" TARGET=\"_blank\">" .
    $row["username"] .
    "</td><td><font face=\"tahoma\" size=\"1\"><font color=\"#C0C0C0\">" .
    date('F j, Y, g:i a', $row["post_time"]) .
    "</td></tr></font>";
    }
    print "</table></marquee>";
    mysql_free_result($result);
    mysql_close($link);
    ?>
Last edited by c64persian on Wed Aug 12, 2015 8:21 am, edited 1 time in total.
mrb1129
Registered User
Posts: 10
Joined: Tue Nov 18, 2014 3:56 am

Re: Latest Posts on site home page

Post by mrb1129 »

Where to put the first part of the code? I mean it is said to put it on the top of my page but where?. Should I put it in index.php or somewhere else.
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Latest Posts on site home page

Post by andrewilley »

mrb1129 wrote:Where to put the first part of the code? I mean it is said to put it on the top of my page but where?. Should I put it in index.php or somewhere else.
It means insert it at the top of every webpage that you wish to use content on - i.e. it must be the very first thing in the PHP document, before even the initial <!DOCTYPE ... > tag. Do not place any characters at all before the commencing <?php ... ?> code - not even spaces, comments or carriage returns.

Andre
--- Admin of www.portorleans.org
mrb1129
Registered User
Posts: 10
Joined: Tue Nov 18, 2014 3:56 am

Re: Latest Posts on site home page

Post by mrb1129 »

Its not working
andrewilley
Registered User
Posts: 114
Joined: Fri Sep 12, 2008 7:28 pm
Location: Birmingham UK

Re: Latest Posts on site home page

Post by andrewilley »

mrb1129 wrote:Its not working
As error reports for diagnostic purposes go, that is one of the more informative ones.

Andre
--- Admin of www.portorleans.org
User avatar
RMcGirr83
Former Team Member
Posts: 22068
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Latest Posts on site home page

Post by RMcGirr83 »

:lol:
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then you can support me by buying a beer 🍺

Return to “[3.0.x] MOD Requests”