3. Readmore Menu Content and Readmore Category Article

1.crud.php

<?php

class Crud {

    public $conn;

    public function __construct() {
        $this->conn = mysqli_connect("localhost", "root", "", "fresh");
        if (mysqli_connect()) {
            //echo "Connect Successfully";
        } else {
            die("connection error");
        }
    }

    /* This is for readmore menu content */
    public function readMenuContent($table, $id) {
        $query = mysqli_query($this->conn, "SELECT * FROM $table WHERE menu_id=$id AND status= 1");
        if (mysqli_num_rows($query) > 0) {
            return mysqli_fetch_assoc($query);
        } else {
            return false;
        }
    }
    
    /* This is for readmore Article */
    public function readArticle($table, $id) {
        $query = mysqli_query($this->conn, "SELECT * FROM $table WHERE art_id=$id AND status = 1");
        if (mysqli_num_rows($query)) {
            return mysqli_fetch_assoc($query);
        } else {
            return false;
        }
    }

}

$obj = new Crud();

2.content.php

<div class="content1">
    <div class="content1_box1 flt_lt">

        <?php
        /* This is for menu content */
        if (isset($_REQUEST['menu_id'])) {
            $content = $obj->MenuContent("menus", $_REQUEST['menu_id']);
            //echo $content["menu_content"];

            /* Start from this here for Readmore content */
            extract($content);
            $convert_array = explode(' ', $menu_content);
            //print_r($convert_array);
            if (count($convert_array) <= 210) {
                echo "<p>$menu_content</p>";
            } else {
                $slice = array_slice($convert_array, 0, 209);
                echo "<p>" . implode(' ', $slice) . "<a style=text-decoration:none;color:red; href=index.php?id=$menu_id>&nbsp;&nbsp;Read More</a> </p>";
            }
        } elseif (isset($_REQUEST['id'])) {
            $readmore = $obj->readMenuContent("menus", $_REQUEST['id']);
            //print_r($readmore);
            echo $readmore['menu_content'];
        } /* finish line Readmore content */



        /* This is for category articles */
        if (isset($_REQUEST['cat_id']) ? $_GET['cat_id'] : null) {
            $articles = $obj->CatArticle("articles", $_REQUEST['cat_id']);
            //echo "<pre>";
            //print_r($articles);
            foreach ($articles as $article) {
                extract($article);
                echo "<h2>" . $article["art_title"] . "</h2>";
                //echo "<p>" . $article["art_content"] . "</p>";

                /* Start from this here for Readmore Article */
                $art_convert_array = explode(' ', $art_content);
                //print_r($art_convert_array);
                if (count($art_convert_array) <= 160) {
                    echo "<p>" . $art_convert_array["art_content"] . "</p>";
                    //echo "<p>$art_content</p>";
                } else {
                    $art_slice = array_slice($art_convert_array, 0, 159);
                    echo "<p>" . implode(' ', $art_slice) . "<a style=text-decoration:none;color:red; href=index.php?art_id=$art_id>&nbsp;&nbsp;Read More</a> </p>";
                }
            }
        } elseif (isset($_REQUEST['art_id'])) {
            $artReadmore = $obj->readArticle("articles", $_REQUEST['art_id']);
            echo "<h2>" . $artReadmore['art_title'] . "</h2>";
            echo "<p>" . $artReadmore['art_content'] . "</p>";
        } /* finish line Readmore Article */
        ?>

        <br/>
    </div>

Output:
readmore

Advertisements

2. Dynamic Category and Category Articles show

1.Create Database Table articles

article

2.Crud.php file

<?php

class Crud {

    public $conn;

    public function __construct() {
        $this->conn = mysqli_connect("localhost", "root", "", "fresh");
        if (mysqli_connect()) {
            //echo "Connect Successfully";
        } else {
            die ("connection error");
            
        }
    }
   
    /* This is for category show */
    public function categories($table){
        $query = mysqli_query($this->conn, " SELECT * FROM $table");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_all($query, MYSQL_ASSOC);
        } else{
            return false;
        }
    }
    
    /* This is for Category Article show*/
    public function CatArticle($table,$id){
        $query = mysqli_query($this->conn, "SELECT * FROM $table WHERE cat_id=$id");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_all($query,MYSQL_ASSOC);
        } else{
            return false;
        }
    }

}

$obj = new Crud();

3.sidebar.php

<div class="content1_box2 flt_lt">
    <h2>Latest work</h2>
    <div class="content1_box2_img"><a href="#"><img src="images/img.jpg" width="300" height="135" alt="img" /></a></div>
    <p>Pellentesque diam ligula, egestas eget rhoncus vel, hendrerit in sem. Viva mus laoreet erat sit amet ante ullamcorper vestibulum. <a href="#">Read More</a></p>
    <h2>Categories</h2>
    <ul>
        <?php
        $categories = $obj->categories("categories");
        foreach ($categories as $category) {
            extract($category);
            ?> <li><a href="index.php?cat_id=<?php echo $cat_id; ?>"><?php echo $cat_name; ?></a></li>
            <?php
        }
        ?>
    </ul>
    <div class="clear"></div>
</div>

4.content.php

<div class="content1">
    <div class="content1_box1 flt_lt">

        <?php
        /* This is for category articles */
        if (isset($_REQUEST['cat_id'])) {
            $articles = $obj->CatArticle("articles", $_REQUEST['cat_id']);
            //echo "<pre>";
            //print_r($articles);
            foreach ($articles as $article) {
                echo "<h2>" . $article["art_title"] . "</h2>";
                echo "<p>" . $article["art_content"] . "</p>";
            }
        }
        ?>

        <br/>
    </div>

Output like following screenshot
category

1. Dynamic menu and menu content show

1.At first you have to do separate the whole template.section header, content, banner, sidebar, footer.
2.Look like following index.php file

<?php
include_once('header.php');
include_once('banner.php');
include_once('content.php');
include_once('sidebar.php');
include_once('footer.php');
?>

3.create database table

db-looking

4.create crud.php

<?php class Crud { public $conn; public function __construct() { $this->conn = mysqli_connect("localhost", "root", "", "fresh");
        if (mysqli_connect()) {
            //echo "Connect Successfully";
        } else {
            die ("connection error");
            
        }
    }
    /* This is for menu showing */
    public function Menu($table){
        $query = mysqli_query($this->conn, "SELECT * FROM  $table WHERE STATUS=1");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_all($query,MYSQLI_ASSOC);
        } else {
            echo "Menu not showing";
        }
        
    }
    
    /* This is for menu content */
    public function MenuContent($table,$id){
        $query = mysqli_query($this->conn, "SELECT * FROM  $table WHERE menu_id=$id");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_assoc($query);
        } else{
            return false;
        }
    }

}

$obj = new Crud();

5.header.php

<?php
include_once('crud.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Demo site</title>
        <!-- SET: FAVICON -->
        <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
        <!-- END: FAVICON -->
        <!-- SET: STYLESHEET -->
        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
        <!-- END: STYLESHEET -->
    </head>
    <body>
        <!-- wrapper starts -->
        <div class="wrapper">
            <!-- main Starts -->
            <div class="main">
                <!-- Header Starts -->
                <div class="header">
                    <div class="logo flt_lt">
                        <h1><a href="#">Logo</a></h1>
                        <p>Your slogan goes here</p>
                    </div>
                    <div class="header_right flt_rt">
                        <ul>
                            <li><a href="#"><img src="images/twitter-logo.png" width="16" height="16" alt="twitter" class="img" /><span>twitter</span></a></li>
                            <li><a href="#"><img src="images/fb-logo.png" width="16" height="16" alt="facebook" class="img"  /><span>facebook</span></a></li>
                        </ul>
                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                    <div id="nav">
                        <ul>
                            <li><a href="index.php">HOME </a></li>
                            <?php
                            $headmenus = $obj->Menu("menus");
                            foreach ($headmenus as $singlemenu) {
                                extract($singlemenu);
                                //print_r($singlemenu);
                                ?>
                                <li><a href="index.php?menu_id=<?php echo $menu_id;?>"><?php echo $menu_name; ?></a></li>
                                <?php
                            }
                            ?>
                        </ul>
                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
                <!-- Header ends -->
                <!-- content Starts -->
                <div class="content">

6.content.php

<div class="content1">
    <div class="content1_box1 flt_lt">
        <!-- This code is for Menu content showing -->
        <?php
           if(isset($_REQUEST['menu_id'])){
               $menucontent = $obj->MenuContent("menus", $_REQUEST['menu_id']);
               //print_r($menucontent);
               echo $menucontent['menu_content'];
           }
        ?>
        
        <br/>
    </div>

Final showing like following screenshot
template-menu