2017-04-07 8 views
1

新しい投稿が作成されるたびに変更されるヘッダーを作成しようとしています。最新の投稿のおすすめ画像は、その投稿を見るためのボタン付きのホームページヘッダにもなります。複数のheader.phpファイルを持つのがベストプラクティスですか、それとも条件文を持つべきですか?ダイナミックヘッダーを作成するには、複数のheader.phpファイルを作成する必要がありますか?

+1

一つへのリンクである、または多分宇宙のパダワンと_one – RiggsFolly

+0

が、一つだけを作り、あなたがしたい最新post.Ifから絵が迷惑を取得取得する関数を作成learner_ AJAXで画像を変更します(ページをリロードせずに)。あなたが100%HTMLサイトのように機能を決めるなら、PHPを使うのは意味がありません:)。 –

+0

@MarinNedeaだから私はあなたが言ったことをしましたが、私の問題は私がすべてのヘッダーを変更していることです。私は私のif文を設定するためにhtmlでis_home()を使用するのに苦労していると思います。 – rabowlen

答えて

1

マルチプルの動的ヘッダーは必要ありません。投稿には1つの見出しが必要です。あなたは「header.phpの」が含まれるようなものが必要な場合がありますpost.phpファイルに

post.php

を持っている、のは、例えばとしましょう。インクルードするには次のように試してください

//put this portion of the code in between the head tag somewhere 

<!--Little CSS fade in --> 
<style> 
.fade-in{ 
    -webkit-animation: fade-in 2s ease; 
    -moz-animation: fade-in ease-in-out 2s both; 
    -ms-animation: fade-in ease-in-out 2s both; 
    -o-animation: fade-in ease-in-out 2s both; 
    animation: fade-in 2s ease; 
    visibility: visible; 
    -webkit-backface-visibility: hidden; 
} 

@-webkit-keyframes fade-in{0%{opacity:0;} 100%{opacity:1;}} 
@-moz-keyframes fade-in{0%{opacity:0} 100%{opacity:1}} 
@-o-keyframes fade-in{0%{opacity:0} 100%{opacity:1}} 
@keyframes fade-in{0%{opacity:0} 100%{opacity:1}} 

</style> 
</head> 
<body> 

<!--We appendin' on this div - ps: ids make sense here... punk--> 
<div id="banner-load"></div> 

<!--Don't forget Jquery--> 
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js'></script> 

<!--New images on load --> 
<script> 
//Add your images, we'll set the path in the next step 
    var images = ['banner-1.jpg', 'banner-2.jpg', 'banner-3.jpg', 'banner-4.jpg]; 

//Build the img, then do a bit of maths to randomize load and append to a div. Add a touch off css to fade them badboys in all sexy like. 
    $('<img class="fade-in" src="images/' + images[Math.floor(Math.random() * images.length)] + '">').appendTo('#banner-load'); 
</script> 

</body> 
?> 

インクルードには、ファイルを含めるときにheadタグとbodyタグの場所を覚えておいてください。ここで

はgithubの条件とhttps://gist.github.com/stephenscaff/8266351

関連する問題