2017-06-08 10 views
-2

私のメインページのタイトルは取得していますが、内部ページ(可変ポスト)を取得する場合は機能しません。PHPでページタイトルを動的に取得する方法

$path=$_SERVER['PHP_SELF']; 
$page_title=basename($path); 
switch($page_title){ 
    case 'index.php': 
     $title="Welcome to the the website"; 
     $description="description goes here"; 
     break; 
    case 'about.php': 
     $title="Welcome to the the website"; 
     $description="somehtinfd"; 
     break; 
    case 'career.php': 
     $title="Welcome to the the website"; 
     $description="ome textr"; 
     break; 
    /*IT's NOT WORKING HERE*/ 
    case 'post.php?post_id=1':$title="graphics design services"; 
     $description= "about "; 
     break; 
} 
+0

$ _SERVER ['PHP_SELF']は、URLのクエリ文字列を返しません。 post.php – manian

+0

'' post.php?post_id = 1''というファイル名でしか試してはいけません - それを比較しようとしている '$ page_title'の値を見ましたか? – Quentin

+0

こんにちは兄どのように私はこのタイプの値を得ることができます –

答えて

0

私はあなたが()getを使用することができると思います。

case 'post.php': 
    If($_GET["post_id"]== "1"){ 
     $title="graphics design services"; 
     $description= "about "; 
    }elseif($_GET["post_id"]== "2"){ 

    } 
    break; 

ページの投稿を取得するために使用するためには、IDを取得するために使用します。

+0

Uは私の右のbroを得ました。たくさんありがとう –

0
<title> <?php echo $title; ?> </title> 
<meta type="description" content="<?php echo $description ?."</meta> 
+0

それはあなたが同じタイトルを持っている間、 –

+0

どうすればこの値を得ることができますか? case 'post.php?post_id = 1':$ title = "graphics design services"; $ description = "about"; 休憩。 –

関連する問題