Forum Moderators: coopster

Message Too Old, No Replies

Can I get an SHTML page to parse php code

found a lot on getting php to parse shtml but...

         

fabulousyarn

5:59 pm on Jul 2, 2010 (gmt 0)

10+ Year Member



I have a rather large shtml site, and a blog that is about the site - I'd like to include some stuff from the blog inside the shtml pages - any way to do that. I've found a lot of stuff going the other way, and maybe I'm not seeing it, but I can't seem to find code that allows me to pull, say, comments from the blog or latest from the blog into a sidebar on the main site. Thanks.

rocknbil

8:08 pm on Jul 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Should be able to with no special stuff, I thought you needed exec, but do not.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test PHP in SSI</title>
</head>
<body>
<h1>PHP include Test</h1>
<p>You should see &quot;test PHP in SSI&quot; below.</p>
<!--#include virtual="/includes/test-include.php" -->
</body>
</html>

File needs to be named with .shtml extension: include.shtml

<?php
header("content-type:text/html");
echo "<p>test PHP in SSI</p>";
?>

For specific chunks, you would probably have to do something custom in the included PHP for, or maybe there's an existing chunk you can get by just copying the url:

blog.php?id=1234&amp;snippet=true

fabulousyarn

2:25 pm on Jul 12, 2010 (gmt 0)

10+ Year Member



Hi -thanks, I've tested php in shtml, and it def works, using the include situation - I guess my real problem is figuring out how to get 'pieces' of a blog on the site.Ie, your chunks. I was thinking that I would have to include specific files - like the includes in the blog files - does that make sense?

rocknbil

4:33 pm on Jul 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It kind of does, but without seeing how it's doing it, impossible to say. Let's say one part of your blog has an area that displays snippets.

<?php
echo '<div id="snippet-sidebar">';
include('/path/to/snippet/include.php');
echo '</div>';
?>

So you could take that piece and put it in a file, call it main-page-snippets.php, and use it in your .shtml. Of course, if there are dependent includes, you'd need to include them as well . . . or it may be just a URL you need, as in the first reply, don't know. There's always a way.

fabulousyarn

7:58 pm on Jul 12, 2010 (gmt 0)

10+ Year Member



hi rocknbil thanks can I bend your 'ear' some more - ok, so lets say I want to include recent posts from the blog on a page of the site...do you have any idea how I met get there from here, or do I need to go down the wordpress loop road and break down wordpress, which I havent done in an eon, and try to figure out what actual reference I need to reference...I think i know your answer but I thought I'd put it out there in the hopes that someone has done this. The folks at bigmedium seem to have built a whole shtml publishing system that does this, but of course, I don't use that so....

rocknbil

1:17 am on Jul 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, me, I'd just grow my own. Figure out the database structure, then

select * from posts order by date desc limit 5;

gives you the last 5 posts. Figure out what the links are to them, let's say it's /blog (or something) and (if!) WP identifies the record by id from a query string, you'd do

while ($row = mysql_fetch_array) {
$link = "/blog?id=" . $row['id'];
$title = $row['title'];
echo "<li><a href=\"$link\">$title</a></li>";
}

All you need to do is figure out how the database is structured, and you can build it yourself. I imagine the WordPress forums have some stuff for you, might even tell you how to do this, but I don't muck about with open source code much . . . not if I can avoid it anyway. :-)