Seite 1 von 22

Einfache Anzeige der letzten Themen in Div-Box

Verfasst: 06.04.2008 14:17
von sascha123
Hallo,

ich suche nach einer einfachen Variante die neuesten X-Beiträge im Forum auf meiner Hompage (Startseite) einzublenden. Gibt es das schon für phpBB3?[/b]

Das könnte wie folgt aussehen:

Dies ist ein neuer Beitrag... (als Direktlink)
verfasst von UserX

Die Anzeige sollte später in einer schmalen Div-Box am Seitenrand sein und nach einer bestimmten länge abgeschnitten werden.

Gibt es hierfür eine einfache PHP-Lösung? Die Formatierung würde ich mit CSS realisieren.

Ich wäre für einen Tipp wirklich dankbar, da ich mich nur ungern wochenlang mit der Forenstruktur ausereinandersetzen möchte.

Verfasst: 06.04.2008 15:00
von 4seven

Verfasst: 06.04.2008 15:21
von sascha123
Hallo 4seven,

vielen Dank für die Info.

Das geht absolut in die richtige Richtung !!! :grin:

Allerdings brauche ich aus Platzgründen nur das Thema und den Verfasser. Eine Angabe von Forenart & Datum ist für mich unwichtig.
Das sollte man aber im Quelltext (hoffentlich) problemlos modifizieren können.

Wäre super, wenn du hier den Code posten könntest. Ich vermute mal, dass der einfach per include eingebunden werden kann.

Verfasst: 06.04.2008 17:24
von 4seven
Hallo sascha123,

das Script lässt sich sehr gut anpassen und per include in html einbinden.

have fun...

Code: Alles auswählen

<?php
// ############         Edit below         ########################################
$topic_length = '20';   // length of topic title
$topic_limit = '12';   // limit of displayed topics
$special_forums = '0';   // specify forums ('0' = no; '1' = yes)
$forum_ids = '3,5,6,7';      // IDs of forums; separate them with a comma

$config_path = '/';   // path to config.php
$root_path = 'http://www.deinforum.de/phpbb/';      // link path
// ############         Edit above         #######################################

$path = dirname(__FILE__);
include_once($path.$config_path .'config.php');
mysql_connect($dbhost, $dbuser, $dbpasswd) OR die('Unable to select server.');
mysql_select_db($dbname) OR die('Unable to select database.');

// ############## output ##############
echo '<table border="0" cellpadding="0" cellspacing="0" style="width: 100%" id="Table_DSF-Top5">
<body text="#000000" link="#000000" vlink="#333333" alink="#333333">
         <tr>
           <td colspan="4"><span class="small"><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">
           Die '. $topic_limit .' letzten Themen im Forum</font></span></td><br>
         </tr>
         <tr>

            <td style="width: 20%"><span class="small">
            <strong>
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Foren</font></strong>
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:9px"></font
            </strong></span></td>
            <td style="width: 20%"><span class="small">
            <strong>
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">User</font>
            </strong>
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:9px"></font
            </strong></span></td>
            <td style="width: 20%"><span class="small">
            <strong>
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Datum</font>
            </strong></span></td>
            <td style="width: 20%"><span class="small"><strong>
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">Thema</font>
            </strong>
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:9px"></font
            </strong></span></td>

         </tr>';
// ############## output ##############

$where_forums = ( $special_forums == '0' ) ? '' : 't.forum_id NOT IN ('. $forum_ids .') AND ';
$sql = "SELECT t.*, f.forum_id, f.forum_name, u.username AS first_poster, u.user_id AS first_poster_id, u2.username AS last_poster, u2.user_id AS last_poster_id, p.post_username AS first_poster_name, p2.post_username AS last_poster_name, p2.post_time
   FROM ". $table_prefix ."topics t, ". $table_prefix ."forums f, ". $table_prefix ."users u, ". $table_prefix ."posts p, ". $table_prefix ."posts p2, ". $table_prefix ."users u2
   WHERE $where_forums t.topic_poster = u.user_id AND f.forum_id = t.forum_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id
   ORDER BY t.topic_last_post_id DESC LIMIT $topic_limit";
$result = mysql_query($sql);
if( !$result )
{
   die('SQL Statement Error: '. mysql_error());
   exit();
}

$line = array();
while( $row = mysql_fetch_array($result) )
{
   $line[] = $row;
}

for( $i = 0; $i < count($line); $i++ )
{
   $forum_id = $line[$i]['forum_id'];
   $forum_url = $root_path .'viewforum.php?f='. $forum_id;
   $topic_id = $line[$i]['topic_id'];
   $topic_url = $root_path .'viewtopic.php?t='. $topic_id;

   $topic_title = ( strlen($line[$i]['topic_title']) < $topic_length ) ? $line[$i]['topic_title'] : substr(stripslashes($line[$i]['topic_title']), 0, $topic_length) .'...';

   $topic_type =  ( $line[$i]['topic_type'] == '2' ) ? 'Announcement ': '';
   $topic_type .= ( $line[$i]['topic_type'] == '3' ) ? 'Global Announcement ': '';
   $topic_type .= ( $line[$i]['topic_type'] == '1' ) ? 'Sticky ': '';
   $topic_type .= ( $line[$i]['topic_vote'] ) ? 'Poll ': '';

   $views = $line[$i]['topic_views'];
   $replies = $line[$i]['topic_replies'];

   $first_time = date('d.m.Y', $line[$i]['topic_time']);
   $first_author = ( $line[$i]['first_poster_id'] != '-1' ) ? '<a href="'. $root_path .'profile.php?mode=viewprofile&u='. $line[$i]['first_poster_id'] .'" target="_blank">'. $line[$i]['first_poster'] .'</a>' : ( ($line[$i]['first_poster_name'] != '' ) ? $line[$i]['first_poster_name'] : 'guest' );
   $last_time = date('d.m.Y', $line[$i]['post_time']);
   $last_author = ( $line[$i]['last_poster_id'] != '-1' ) ? $line[$i]['last_poster'] : ( ($line[$i]['last_poster_name'] != '' ) ? $line[$i]['last_poster_name'] : 'guest' );
   $last_url = '<a href="'. $root_path .'viewtopic.php?p='. $line[$i]['topic_last_post_id'] .'#'. $line[$i]['topic_last_post_id'] .'" target="_blank">'. $last_author .'</a>';

   // ############## output ##############
   echo '<tr>

            <td style="width: 20%"><a href="'. $forum_url .'" target="_blank">
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $line[$i]['forum_name'] .'</font></a></td>
            <td style="width: 20%">
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_url .'</font></td>
            <td style="width: 20%">
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $last_time .'</font></td>
            <td style="width: 20%"><a href="'. $topic_url .'" target="_blank">
            <font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:11px">'. $topic_title .'</font></a></td>

        </tr>';

   // ############## output ##############
}

echo '</table>';
mysql_close();
?>

Verfasst: 06.04.2008 19:52
von sascha123
Vielen Dank für deine Hilfe !!!

Verfasst: 06.04.2008 19:59
von Pfotenwelt
Wow, genau sowas habe ich auch gesucht.

Was müsste ich da ändern, wenn ich jetzt zb. nur Postings aus einer Kategorie raus nehmen möchte? So könnte ich nämlich meine Forumsnews auch auf die Startseite binden.

Denke das müsste irgendwo über ID angepasst werden oder?

edit: ah habs glaubs raus gefunden. 8)

Verfasst: 06.04.2008 20:15
von Pfotenwelt
Hab jetzt aber doch noch ne frage. Wo muss ich das den hochladen? dass es angezeigt wird? :-?

Verfasst: 06.04.2008 20:26
von 4seven
Überallhin, wo du magst (dann halt Pfad anpassen). Am besten aber im Foren-Root.
Die *.php kann dann nach überallhin per include verlinkt werden (muss also nicht auf dem Foren-Space sein)

Tip zur Gestaltung:

Am besten im Root in eine *.html includen, die kann man chiquer gestalten :wink:

Code: Alles auswählen

<html>
<head>
<title>Last Topics</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include("last_topics.php");
?>
</body>
</html>
lg
4seven

Verfasst: 06.04.2008 20:28
von Pfotenwelt
ich habe ne index.php seite, die schon besteht im root, und eine html seite im
prosilver/template/home.html

wie krieg ich das dann zusammen?

Verfasst: 06.04.2008 20:29
von 4seven
Was genau ist die Zielsetzung?