สงสัยว่าหน้า index เขามีวิธีเขียนแบบไหนครับ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สงสัยว่าหน้า index เขามีวิธีเขียนแบบไหนครับ

สงสัยว่าหน้า index เขามีวิธีเขียนแบบไหนครับ
หน้า 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 อะไรอย่างงี้ครับ

<?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 ได้ไหมครับ

ขอบคุณมากครับ


Boomzaclub 223.205.245.xxx 28-08-2016 22:56:05

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
สงสัยอีกเรื่องครับ 

ใน 1 เว็บ จะมีไฟล์และโฟลเดอร์อะไรบ้างครับ ผมไม่เข้าใจว่าเขานิยมทำยังไงกันครับ

คือผมจะรับจ้างเขียนโปรเจคให้น้องอะครับ จะต้องมีไฟล์อะไรส่งให้เขาบ้าง ครับ เช่น พวก index.php header.php conten.php footer
php connect.php style.css แล้วจะมีอะไรบ้างอีกไหมครับ

ถ้าเป็นไปได้ คุณ nik พอจะมีตัวอย่างให้ดูไหมครับ 

ขอบคุณมากครับ



Boomzaclub 223.205.245.xxx 28-08-2016 23:17
 ความคิดเห็นที่ 2
- การสร้างไฟล์ index ทำได้หลายวิธี include ก็เป็นวิธีที่นิยมใช้
หรือจะเป็นสร้างฟังก์ชั่นไว้ในไฟล์ include แรกแล้วเรียกใช้ฟังก์ชัน get_sidebar(); get_footer(); ... แทน
ปัจจุบันก็มีเปลี่ยนมาใช้การเขียนแบบ OOP โดยเฉพาะใน php framework ต่างๆ
- ศึกษา php เยอะๆ 
- ไฟล์ index.php เปลี่ยนเป้น index.html ด้วย mode_rewrite
- ไฟล์ โฟลเดอร์ ไม่มีรูปแบบตายตัว หาข้อมูล ศึกษาเพิ่มติม


ninenik 180.183.50.xxx 29-08-2016
 ความคิดเห็นที่ 3
ขอบคุณมาก ครับ 


Boomzaclub 223.205.243.xxx 29-08-2016 11:13
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ