2014-09-24 1 views
0

동적 요소를 위해 HTML에서 PHP로 몇 개의 사이트를 변환 중이며 (include()를 사용하여) 머리말과 꼬리말로 그렇게 할 수 있습니다. 그러나, 나는 머리 부분을하는 방법에 혼란스러워.PHP로 헤드 섹션 작성하기

<head> 
    <!--[if lt IE 9]> 
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"> 
    </script> 
    <![endif]--> 
    <meta charset="UTF-8" /> 
    <meta name="description" content="Liberty Resource Directory. The ultimate curated directory to find what you need."/> 
    <meta name="keywords" content="ethan glover, lrd, liberty resource directory"/> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
    <link href="stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen"> 
    <title>Liberty Resource Directory</title> 
</head> 

내가 쉽게 HTML5Shim 스크립트, 메타 캐릭터 세트, 뷰포트 (그래 난 그 최대 스케일을 제거), 그리고 스타일 시트 링크를 추가 할 수 있습니다 : 이것은 내가 일반 HTML과 함께하는 것입니다.

어떻게 내가 그에게 개별 페이지 설명, 키워드와 제목을 전달할 수있는 방법으로 .PHP 파일을 작성할 수 있습니다 : 여기

문제인가? (그런 식으로 위의 코드를 PHP 파일에 넣고 모든 페이지에 포함시킬 수 있습니다.)

또는 설명, 키워드 및 제목을 제외하고 매번 이러한 부분을 다시 작성하기 만하면됩니까? (알레한드로 아르 비사 씨)

head.php

<head> 
    <!--[if lt IE 9]> 
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"> 
    </script> 
    <![endif]--> 
    <meta charset="UTF-8" /> 
    <meta name="description" content="<?php echo $description;?>"/> 
    <meta name="keywords" content="<?php echo $keywords;?>"/> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="../stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen"> 
    <title><?php echo $title;?></title> 
</head> 

index.html을 (위에 포함하는 코드)

<?php 
    $description="Liberty Resource Directory. The ultimate curated directory to find what you need."; 
    $keywords="ethan glover, lrd, liberty resource directory"; 
    $title="Liberty Resource Directory"; 
    include 'scripts/head.php'; 
?> 

최종 결과 : 여기

해답이다 :

http://libertyresourcedirectory.com/

+0

내부에 ''- 개별 페이지 설명 등은 좀 더 코딩이 필요합니다. * 나는 두려워합니다 *. 대신 프레임 워크를 사용하십시오. 쉬울거야. –

+0

PHP 코드를 게시하십시오. 어떤 프레임 워크 나 베어 본 PHP를 사용하고 있습니까? –

답변

1

설명과 키워드에 변수를 사용할 수 있습니다. 그런 다음 페이지를 만들 때가되면 해당 값으로 변수를 설정하기 만하면됩니다.

<?php 
// page1.php 
$description = "This is page one"; 
$keywords = "page one"; 
include 'header.php'; 
?> 

<!-- Page content --> 

<?php include 'footer.php'; ?> 

물론

<?php 
// page2.php 
$description = "This is page two"; 
$keywords = "page two"; 
include 'header.php'; 
?> 

<!-- Page content --> 

<?php include 'footer.php'; ?> 

, 내가 여기에 가정입니다 전체 HTML 헤더 내부입니다 :

<head> 
    <!--[if lt IE 9]> 
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"> 
    </script> 
    <![endif]--> 
    <meta charset="UTF-8" /> 
    <meta name="description" content="<?php echo $description; ?>"/> 
    <meta name="keywords" content="<?php echo $keywords; ?>"/> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
    <link href="stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen"> 
    <title>Liberty Resource Directory</title> 
</head> 

그래서, 당신은 page1.php와 page2.php가 있다고 할 수 있습니다 header.php 파일, 즉 <html>, <head><body>을 포함합니다.

+1

굉장! 물론 태그와 동일한 방식으로 페이지 콘텐츠 내부에서도 PHP를 사용할 수 있습니다. –