สงสัยว่าหน้า index เขามีวิธีเขียนแบบไหนครับ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สงสัยว่าหน้า index เขามีวิธีเขียนแบบไหนครับ
สงสัยว่าหน้า index เขามีวิธีเขียนแบบไหนครับ
Copy
หน้า index.php เขามีวิธีเขียนยังไงครับ เพราะเท่าที่ผมเคยเรียนมา หน้า index ก็จะมีดังโค้ดด้านล่างนี้ครับ
<html>
<head>
<title></title>
</head>
<body>
<header>
</header>
<nav>
</nav>
<section>
<aside></aside>
</section>
<footer>
</footer>
</body>
</html>
ประมาณนี้ครับ และที่เข้าใจอีกวิธีหนึ่งคือ ในไฟล์ index.php ก็อป แบ่งเอา ส่วนหัว ส่วนเนื้อหา ส่วนล่าง แยกกันเป็นคนละไฟล์
แล้วใช้ PHP include เข้ามาที่หน้า index.php เอา
เช่น
include('header.html');
include('content.php');
include('footer.html');
ประมาณนี้ครับ
แต่พอผมลองไปเปิดไฟล์ตัวอย่างเว็บอื่นๆ ดู มันไม่เป็นแบบนั้นครับ ผมนี่งงเลย
ส่วนมากจะเป็นแบบ มีแค่โค้ด สั้นๆ และจะมีแค่โค้ด PHP ซะส่วนมาก เช่น พวกคำสั่ง DEFINE() SEVER() หรือ get_header อะไรอย่างงี้ครับ
หรืออีกตัวอย่างจาก template wordpress ครับ งงมากครับ
ตองศึกหาเรื่องอะไรบ้าง แนะนำทีครับ
คำถามสุดถ้ายครับ ในไฟล์ index.php ที่มีโค้ด ภาษา php สามารถทำให้เป็น index.html ได้ไหมครับ
ขอบคุณมากครับ
<html>
<head>
<title></title>
</head>
<body>
<header>
</header>
<nav>
</nav>
<section>
<aside></aside>
</section>
<footer>
</footer>
</body>
</html>
ประมาณนี้ครับ และที่เข้าใจอีกวิธีหนึ่งคือ ในไฟล์ index.php ก็อป แบ่งเอา ส่วนหัว ส่วนเนื้อหา ส่วนล่าง แยกกันเป็นคนละไฟล์
แล้วใช้ PHP include เข้ามาที่หน้า index.php เอา
เช่น
include('header.html');
include('content.php');
include('footer.html');
ประมาณนี้ครับ
แต่พอผมลองไปเปิดไฟล์ตัวอย่างเว็บอื่นๆ ดู มันไม่เป็นแบบนั้นครับ ผมนี่งงเลย
ส่วนมากจะเป็นแบบ มีแค่โค้ด สั้นๆ และจะมีแค่โค้ด PHP ซะส่วนมาก เช่น พวกคำสั่ง DEFINE() SEVER() หรือ get_header อะไรอย่างงี้ครับ
<?php //index.php?>
<?php session_start();?>
<?php require 'makepage.php'; $MasterPage = 'master.php';?>
<?php if (0):?>
<?php endif;?>
<?php sb('title'); echo "หน้าแรก"; eb();//end title?>
<?php sb('head');?>
<?php eb();//endhead?>
<?php sb('content');
if(isset($_SESSION['user_class'])){
echo"<script>window.location='main.php';</script>";
}
?>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
showkey('username');
//showkey('password2');
function showkey(id){
// Load the Google Onscreen Keyboard API
google.load("elements", "1", {
packages: "keyboard"
});
function onLoad() {
var kbd = new google.elements.keyboard.Keyboard(
[google.elements.keyboard.LayoutCode.ENGLISH],
[id]);
}
google.setOnLoadCallback(onLoad);
}
</script>
<style>
.line{
border:none;
}
</style>
<div align="center">
<div class="login">
<form action="login.php" method="post" autocomplete="off">
<div align="left"><label for="username" align="left">ชื่อผู้ใช้</label></div>
<input type="text" id="username" onclick="showkey('username')" name="username" class="form-control" placeholder="กรอกชื่อผู้ใช้">
<div align="left"><label for="username" align="left">รหัสผ่าน</label></div>
<input type="password" onclick="showkey('password2')" id="password2" name="password" class="form-control">
<div align="center" style="margin-top:10px;">
<button type="submit" class="btn btn-info">เข้าสู่ระบบ</button>
<button type="reset" class="btn btn-default">ยกเลิก</button>
</div>
</form>
</div>
</div>
<?php eb();// end content?>
<?php render();?>
แบบนี้ในส่วนหัว คือ เขามีวิธีแยกไฟล์ยังไง ครับเขียนยังไงผมงงมากหรืออีกตัวอย่างจาก template wordpress ครับ งงมากครับ
<?php /** * The main template file * * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists. * * @link http://codex.wordpress.org/Template_Hierarchy * * @package WordPress * @subpackage Twenty_Sixteen * @since Twenty Sixteen 1.0 */ get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php if ( have_posts() ) : ?> <?php if ( is_home() && ! is_front_page() ) : ?> <header> <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1> </header> <?php endif; ?> <?php // Start the loop. while ( have_posts() ) : the_post(); /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'template-parts/content', get_post_format() ); // End the loop. endwhile; // Previous/next page navigation. the_posts_pagination( array( 'prev_text' => __( 'Previous page', 'twentysixteen' ), 'next_text' => __( 'Next page', 'twentysixteen' ), 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>', ) ); // If no content, include the "No posts found" template. else : get_template_part( 'template-parts/content', 'none' ); endif; ?> </main><!-- .site-main --> </div><!-- .content-area --> <?php get_sidebar(); ?> <?php get_footer(); ?>คือวิธีเขียนแบบไหนครับ
ตองศึกหาเรื่องอะไรบ้าง แนะนำทีครับ
คำถามสุดถ้ายครับ ในไฟล์ index.php ที่มีโค้ด ภาษา php สามารถทำให้เป็น index.html ได้ไหมครับ
ขอบคุณมากครับ
คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ