Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Put the 3 files in a folder on your (local) host and run the index.php - is that what you're looking for?</p> <p><code>/wwwroot/post.tpl</code></p> <pre><code>&lt;article id="{$postId}" class="{$postType}"&gt; &lt;div class="content" style="width:450px;float:left;margin-right:20px;"&gt; &lt;h3&gt;&lt;a href="single-post.php?id={$postId}"&gt;{$postTitle}&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;{$postContent}&lt;/p&gt; &lt;/div&gt; &lt;a href="single-post.php?id={$postId}"&gt;&lt;img style="height:150px;" src="{$postPreviewImage}"&gt;&lt;/a&gt; &lt;/article&gt;&lt;br clear="all"/&gt; </code></pre> <p><code>/wwwroot/main.tpl</code></p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="UTF-8"/&gt; &lt;title&gt;{$pageTitle}&lt;/title&gt; &lt;script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;{$pageH1}&lt;/h1&gt; &lt;hr&gt; Filter posts: &lt;select id="filter"&gt; &lt;option id="all"&gt;Show all posts&lt;/option&gt; {$filterOptions} &lt;/select&gt; &lt;hr&gt; {$posts} &lt;script&gt; $().ready(function() { $("#filter").change(function() { for(var b = $(this).find(":selected").attr("id"), d = document.getElementsByTagName("article"), c = 0;c &lt; d.length;c++) { var a = d[c]; "all" === b || b === a.className ? $(a).fadeIn() : b !== a.className &amp;&amp; $(a).fadeOut() } }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><code>/wwwroot/index.php</code></p> <pre><code>&lt;?php // get categories from DB $postCategoriesFromDb = array( array( 'slug' =&gt; 'games', 'name' =&gt; 'Games' ), array( 'slug' =&gt; 'dev', 'name' =&gt; 'Development' ) ); // get posts from DB $postsFromDb = array( array( 'id' =&gt; 1, 'type' =&gt; 'games', 'image' =&gt; 'http://openmatt.org/wp-content/uploads/2012/12/Game-On-banner.png', 'title' =&gt; 'A post about games', 'content' =&gt; 'This is the content of my game post.. lorem ipsum..' ), array( 'id' =&gt; 2, 'type' =&gt; 'dev', 'image' =&gt; 'http://gregrickaby.com/wp-content/uploads/2012/03/github-logo.png', 'title' =&gt; 'A post about development', 'content' =&gt; 'This is the content of my dev post.. lorem ipsum..' ) ); // function to populate single post template with post data function getPostHtml($postData) { $html = file_get_contents(__DIR__ . '/post.tpl'); $vars = array( '{$postId}' =&gt; $postData['id'], '{$postType}' =&gt; $postData['type'], '{$postPreviewImage}' =&gt; $postData['image'], '{$postTitle}' =&gt; $postData['title'], '{$postContent}' =&gt; $postData['content'] ); return strtr($html, $vars); } // create HTML for each post $posts = ''; foreach ($postsFromDb as $post) { $posts .= getPostHtml($post); } // create HTML for category filter $options = ''; foreach ($postCategoriesFromDb as $cat) { $options .= sprintf('&lt;option id="%s"&gt;%s&lt;/option&gt;', $cat['slug'], $cat['name']); } // get main page template $html = file_get_contents(__DIR__ . '/main.tpl'); // template vars $vars = array( '{$pageTitle}' =&gt; 'Page title', '{$pageH1}' =&gt; 'Hello World!', '{$filterOptions}' =&gt; $options, '{$posts}' =&gt; $posts ); // output to client echo strtr($html, $vars); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload