Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Cheese Head on February 10, 2008, 07:45:03 AM

Title: Index/Default Dynamic Forum Content
Post by: Cheese Head on February 10, 2008, 07:45:03 AM
mornin y'all, small help question please. I have SMF installed and running, now I want to put some dynamic content on my index/default page.

What's that called and where on SMF website should I look for how-to?

Thx, John.
Title: Re: Index/Default Dynamic Forum Content
Post by: Dragooon on February 10, 2008, 08:13:41 AM
So you want a homepage type of thing?
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on February 10, 2008, 08:48:32 AM
Yes please, my Forum is actually just part of my website not the only thing, so yes how to insert dynamic recent Forum posts into my Homepage/Default/Index file.
Title: Re: Index/Default Dynamic Forum Content
Post by: karlbenson on February 10, 2008, 10:15:00 AM
Use SSI.
http://www.simplemachines.org/community/index.php?topic=14906.0
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on February 10, 2008, 04:31:52 PM
Thanks karlbenson, appreciate, wish me luck, John.
Title: Index/Default Dynamic Forum Content
Post by: Cheese Head on May 18, 2008, 09:27:32 AM
Edit: Oops, just realized this is in SMF1.0 Support board, I'm now using 2.0, moderator please move post if like . . . thanks

So I've just spent almost a day trying to figure out SSI so that I can make my homepage dynamic with recent posts and I'm still stuck. So far I've:
When I come to implement into my default.html homepage I realize that:

Appreciate any advice as I feel I've lost a day and am worse off when I started. All I want to do is show the 10 most recent posts on my index.html homepage.

Thanks, John.
Title: Re: Index/Default Dynamic Forum Content
Post by: Sarge on May 18, 2008, 10:31:32 AM
Hello John, simply put the PHP code inside <?php and ?> and the webserver will parse it with PHP.
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on May 24, 2008, 08:10:50 AM
Hi Sarge

OK, I've put the code inside <?php and ?>  into my default.htm homepage:
Quote
<p>Please have a look, enjoy, participate, and come back soon . . . John, Webmaster.</p>

<?php
require("/home/jlsr12/public_html/forum/SSI.php");

$array = ssi_recentTopics(10, null, 'array');
   foreach ($array as $recent)
   {
      echo '
      <a href="', $recent['href'], '" title="Board: ', $recent['board']['name'], ' - Poster: ', $recent['poster']['name'], '">
      ', $recent['subject'], '
      ', $recent['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $recent['topic'] . '.from' . $recent'newtime'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>', '
      ', $news['body'], '
      </a><br/>';
   }
?>

<!-- #EndEditable --></div>
</td>
I then FTP'd the file to my host but my online homepage still doesn't show any change. I don't think it is as easy as putting php code into an html type file.

Any advice appreciated, all I'm trying to do is make my homepage dynamic with 10 most recent posts to entice viewers to click into the forum.
Title: Re: Index/Default Dynamic Forum Content
Post by: Dragooon on May 24, 2008, 08:12:59 AM
It should be a .php File not .htm or .html
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on May 24, 2008, 08:19:31 AM
Fully agree it should be in a php file and that's where I've been experimenting with SSI as per the tutorials. But I want to include it into my default.htm homepage, how do I do that?
Title: Re: Index/Default Dynamic Forum Content
Post by: Dragooon on May 24, 2008, 08:29:37 AM
You can do it this way
<?php
echo 'YOUR HTML HERE';
?>

Make sure you escape quotes( ' ) with backslashes ( \ ).
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on May 24, 2008, 08:58:39 AM
Dragooon thanks for your help, sadly I don't fully understand.

I have a default.html that I want to put some SSI in. But I think you are saying the opposite, change my default.htm homepage to php language file and cut and paste the htm code into it?

I really don't want to go down that road as I have a Dynamic Web Template and CSS for my webpages so I'd have to junk all that and basically rebuild my website.

There must be a way to put SSI into an default.htm file or 95% of people build their websites in php?

Thanks again for your support . . .
Title: Re: Index/Default Dynamic Forum Content
Post by: Dragooon on May 24, 2008, 09:08:07 AM
You cannot use SSI in HTML(not directly atleast). You will be needing to either use SHTML or PHP(recommended).
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on May 24, 2008, 09:41:36 AM
Dragooon, so you are saying that to have SSI on my homepage I need to unlearn HTML, CSS, and DWT and best to learn PHP and rebuild my website in PHP? Ouch that means probably up to 1 month work plus probably buying new guide books and software as I bought MS Expression Web 1 (instead of Dreamweaver) which will code php files but is really built for html & CSS . . . MS Expression Web 2 is now out features page here (http://www.microsoft.com/expression/features/Default.aspx?key=web).

I just googled SHTML and it looks similar as it's a server side include version of HTML, wouldn't that be easier for me and if so what do I have to do?
Title: Re: Index/Default Dynamic Forum Content
Post by: Dragooon on May 24, 2008, 10:08:10 AM
PHP do uses a LOT of HTML(See SMF's files for example, HTML is the way to output the data, PHP collects the data).
And are you trying to enclose your whole site in SSI or just 1 page?

You can also ask at the Help Wanted board if you want someone to do it for you.
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on May 24, 2008, 10:54:07 AM
Thanks Dragooon, just one page, all I want to do is have my homepage show the latest posts as a way of enticing viewers to click through and look at posts in the forum.

But If I convert my default.htm into I assume default.php so that I can include SSI then I will not be able to use CSS or DWT for that page making it very awkward to have one page different from the rest. I guess I could just rewrite that page and menus but there must be an easier way via shtml . . . thanks anyway, I'm hoping someoone will reply with a html way to incude SSI . . .
Title: Re: Index/Default Dynamic Forum Content
Post by: Dragooon on May 24, 2008, 10:59:23 AM
You cannot use HTML and SSI together

BTW, You can use CSS and DWT just fine(you basically can use everything you use in HTML(see www.php.net (http://www.php.net))).

Something like
Code: [Select]
<?php
global $context;
require_once(
'SSI.php');
echo 
'
<html>
<head>
<link rel="stylesheet" src="blabla.com/style.css" type="text/css" />
</head>
<body>
Bla bla bla
</body>
</html>'
;
?>

Thats how SMF does it, SMF doesn't uses any static HTML files, all of the HTML/CSS/JScript are in PHP Files.
Title: Re: Index/Default Dynamic Forum Content
Post by: Sarge on May 25, 2008, 09:01:59 AM
Let me chime in before this topic gets out of hand...

On most servers, you can use PHP code inside an HTML page. What happens is (a bit simplified, but basically correct):

1. Someone wants to visit a page of your site, using a browser.
2. The browser sends the URL of the page to the server of the site.
3. Apache (or IIS, or Lighttpd, or whatever webserver is running on the server) reads the requested HTML page from the server's storage.
4. If Apache finds PHP code in the page, it sends everything between <?php and ?> to PHP.
5. PHP parses the code and returns the result as HTML to Apache.
6. Apache returns the result, along with the rest of the HTML code of your page, to the visitor's browser.

Let me repeat: PHP code should work inside an HTML page if the server is configured to do that, and most commercial servers are. If you're not sure about this, ask your host.

Dragooon, what you have said can be true, but not in all servers. So please test your statements before posting...

Now, John, your code had a few typos. Try this:

Code: [Select]
<p>Please have a look, enjoy, participate, and come back soon . . . John, Webmaster.</p>

<?php
require("/home/jlsr12/public_html/forum/SSI.php");

$array ssi_recentTopics(10null'array');
   foreach (
$array as $recent)
   {
      echo 
'
      <a href="'
$recent['href'], '" title="Board: '$recent['board']['name'], ' - Poster: '$recent['poster']['name'], '">
      '
$recent['subject'], '
      '
$recent['new'] ? '' '<a href="' $scripturl '?topic=' $recent['topic'] . '.msg' $recent['new_from'] . ';topicseen#new"><img src="' $settings['images_url'] . '/' $context['user']['language'] . '/new.gif" alt="' $txt[302] . '" border="0" /></a>''
      '
$recent['preview'], '
      </a><br/>'
;
   }
?>


</td>
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on May 26, 2008, 03:19:52 PM
Thanks Dragooon for all your patience and thanks Sarge on taking the extra effort to explain and to correct my code.

Sarge, I just updated my default.htm homepage with your code and FTP'd to my host called www.hostgator.com but sadly it doesn't display anything.

I haven't checked but I'm pretty sure they use Apache? They don't mention it on their features page http://www.hostgator.com/shared.shtml, but they show an Apache Handlers feature button on my cPanel and on their example cPanel at http://67.18.39.34:2082/frontend/x/index.html.

Sorry for asking for more support, appreciate if you have a couple minutes to advise . . . thanks John.
Title: Re: Index/Default Dynamic Forum Content
Post by: Sarge on May 30, 2008, 01:37:57 PM
Have you asked the HostGator support about whether PHP code inside an HTML file should work in your account?

Also, make sure that the path to SSI.php is correct.
Title: Re: Index/Default Dynamic Forum Content
Post by: Cheese Head on June 07, 2008, 11:24:17 AM
Thanks Sarge

Spent an hour on Chat service with HostGator.com, in summary to get to work I had to

Now I need to work on forrmatting . . .