Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions helper.php

This file was deleted.

40 changes: 4 additions & 36 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
include("helper.php");
include("postHelper.php");
include("menuHelper.php");
?>
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -63,16 +64,7 @@
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto nav-pills">
<?php
$menus = menus();
foreach($menus as $menu) {
echo "<li class='nav-item'>";
echo "<a class='nav-link' href='" . $menu['url'] . "'>";
echo $menu['title'];
echo "</a>";
echo "</li>";
}
?>
<?php echo menus(); ?>
</ul>
</div>
</div>
Expand All @@ -83,31 +75,7 @@
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<?php
$posts = posts();
foreach($posts as $post) {
?>
<div class="post-preview">
<a href="./post.php">
<h2>
<?php
echo $post['title'];
?>
</h2>
</a>
<div class="intro">
<div class="clearfix">
<p>
<?php
echo $post['intro'];
?>
</p>
</div>
</div>
</div>
<?php
}
?>
<?php echo posts()?>
<hr>

<div class="clearfix"></div>
Expand Down
27 changes: 27 additions & 0 deletions menuHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
include("data.php");

/**
* Get all menus
*/
function menus() {
global $menus;

$allMenus = null;
if (isset($menus) && count($menus) > 0) {
foreach ($menus as $menu) {
$allMenus .= createEachMenuItem($menu);
}
}
return $allMenus;
}

function createEachMenuItem($menu){
$menuBody = "<li class='nav-item'>\n";
$menuBody .= "<a class='nav-link' href='" . $menu['url'] . "'>\n";
$menuBody .= $menu['title'];
$menuBody .= "</a>\n";
$menuBody .= "</li>\n";
return $menuBody;

}
34 changes: 34 additions & 0 deletions postHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
include("data.php");

/**
* Get All Posts
*/
function posts()
{
global $posts;

$allPosts = null;
if (isset($posts) && count($posts) > 0) {
foreach ($posts as $post) {
$allPosts .= createEachPost($post);
}
}
return $allPosts;
}


function createEachPost($post){

$postBody = '<div class="post-preview">';
$postBody .= '<a href="./post.php">';
$postBody .= '<h2>'.$post['title'].'</h2>';
$postBody .= '</a>';
$postBody .= '<div class="intro">';
$postBody .= '<div class="clearfix">';
$postBody .= '<p>'.$post['intro'].'</p>';
$postBody .= '</div>';
$postBody .= '</div>';
$postBody .= '</div>';
return $postBody;
}