Show latest posts on home page.

Avatar

By Wulfrey 11 May 2015 02:50

Member · 5 comments

I want to be able to show the latest posts of a specific thread on the home page of my website with the newest one on top -- blog style. The the website is modified quite a bit so here is a link to it:

http://www.anvil-mc.net/

I hope that my explanation wasn't too confusing, let me know if it was.

Last edited by Wulfrey (11 May 2015 03:15)

Avatar

By Yannick 11 May 2015 05:08

Administrator · 1,453 comments

So you basically want to show a topic in reverse on your home page?


You can do anything

Avatar

By Wulfrey 11 May 2015 11:00

Member · 5 comments

Yes. That is a much better way to word it and exactly what I wanted.

Last edited by Wulfrey (13 May 2015 02:48)

Avatar

By Wulfrey 13 May 2015 02:48

Member · 5 comments
Yannick wrote

So you basically want to show a topic in reverse on your home page?

Do you have any ideas?

Avatar

By Yannick 13 May 2015 14:54

Administrator · 1,453 comments
<?
// Display Recent Topics

// Using SimpleXML: http://php.net/manual/en/book.simplexml.php
$xml = file_get_contents('http://forum.getluna.org/extern.php?action=feed&type=xml&show=3'); // Change url and final number to your likings
$posts = new SimpleXMLElement($xml);

foreach($posts->topic as $topic) {
    // Show topic title
    echo '<a href="'.$topic->link.'"><b>'.$topic->title.'</b></a><br />';

    // Next, a teaser of the latest post
    $post = strip_tags($topic->content); //Dont want partial html tags
    if(strlen($post) > 50) // Change "50" to whatever characters you want on this and the next line
        echo substr($post, 0, 50).'...<br />';
    else
        echo $post.'<br />';

    // Finally, the username
    echo '--<a href="'.$topic->author->uri.'">'.$topic->author->name.'</a><br /><br />';
}

This should get you started. This works with the extern.php file which is capable of pushing out xml. Have fun. 😉


You can do anything

Avatar

By Wulfrey 13 May 2015 23:41

Member · 5 comments

I am not sure why, but when I use the code with your url it works fine, but my url won't work on it. Here is the entire index file I am using. Thanks very much for writing this though!

<?php

/**
 * Copyright (C) 2013-2014 ModernBB Group
 * Based on code by FluxBB copyright (C) 2008-2012 FluxBB
 * Based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
 * Licensed under GPLv3 (http://modernbb.be/license.php)
 */

define('FORUM_ROOT', dirname(__FILE__).'/');
require FORUM_ROOT.'include/common.php';

if ($luna_user['g_read_board'] == '0')
	message($lang['No view'], false, '403 Forbidden');

$page_title = array(luna_htmlspecialchars($luna_config['o_board_title']));
define('FORUM_ACTIVE_PAGE', 'help');
require FORUM_ROOT.'header.php';

?>

<!-- Left Sidebar -->

<div class = "col-xs-3">

	<center>

		<div class="panel-body">

			<p>
			This is text that should appear in the left sidebar. I believe that the twitter feed has a weird rescale factor and that is what is causing the overlap. I also hope that this does not look weird with no border around it. I will probably add one once I upload this and look at it for myself and see how ugly it is.
			</p>
			
		</div>

	</center>

</div>

<!-- Main Content -->

	<div class = "col-xs-6">
		<div class = "panel-body panel-trans">
			<center>
					 <h2><strong>Welcome to ANVIL!</strong></h2>
					 <p><i>(A Network of Vanilla Inventions and Logic)</i></p>

					 <hr>
					 <p><strong>Please enjoy your stay both on our server, and on our forum.</strong></p>
					 <hr>

					<?php
					
					$xml = file_get_contents('http://www.anvil-mc.net/extern.php?action=feed&type=xml&show=5&fid=4');
					$posts = new SimpleXMLElement($xml);

					foreach($posts->topic as $topic) {
					    echo '<div class = "panel-body"><a href="'.$topic->link.'"><strong>'.$topic->title.'</strong></a><br />';
					    $post = strip_tags($topic->content);
					    if(strlen($post) > 999)
					        echo substr($post, 0, 999).'...<br />';
					    else
					        echo $post.'<br />';
					    echo '--<a href="'.$topic->author->uri.'">'.$topic->author->name.'</a><br /></div><br />';
					}

					?>

			</center>
		</div>
 	</div>

<!-- Right Sidebar Begin -->

<div class = "col-xs-3">

	<center>

		<div class="panel-body">

			<p>
			This is text that should appear in the right sidebar. I believe that the twitter feed has a weird rescale factor and that is what is causing the overlap. I also hope that this does not look weird with no border around it. I will probably add one once I upload this and look at it for myself and see how ugly it is.
			</p>
			
		</div>

	</center>

</div>

<?php

require FORUM_ROOT.'footer.php';

Last edited by Wulfrey (14 May 2015 00:45)

Avatar

By Yannick 14 May 2015 08:28

Administrator · 1,453 comments

Well, it appears that extern.php is damaged on your site, can that be possible? If you visit that URL, you should get a list of topics, but with your site that page is empty. Try to replace the file with a fresh downloaded version from our website.


You can do anything

Avatar

By Wulfrey 14 May 2015 17:32

Member · 5 comments

.

Last edited by Wulfrey (14 May 2015 19:21)

Avatar

By ninjagolloyd 15 May 2015 09:40

Member · 62 comments
Wulfrey wrote

.

To make an empty new post, try bump. It is easier to understand.

Back on topic. I agree with Yannick. That happened to Techie Heaven just last week (I tried an MBB extension). Go on github and download extern.php and put it on your website. It helps.