0
我正在構建一個WordPress主題&我試圖根據用戶所處的頁面來改變我的功能區域中的圖像。如何根據WordPress主題中的頁面ID更改圖像?
我有這樣一段代碼爲特徵的文字,其工作原理:
<?php
$pageID = get_the_ID();
if ($pageID == 17) // Overview
$text = "Greater numbers of young adults on the autism spectrum will gain access to higher
education. Educational opportunities for people with autism spectrum disorders will improve across
Europe.";
else if ($pageID == 39) //Publications
$text = "Our aim is to support the young students to learn the skills they need to negotiate student life and studies
successfully";
else if ($pageID == 44) //Events
$text = "xxxxx";
else if ($pageID == 37) //Blog
$text = "xxxxx";
else
$text = "We research, design, build and evaluate materials to help people with autism access and succeed within Higher Education.";
echo "<h1>" . $text . "</h1>";
?>
然後將此用於圖像:
<?php
$pageID = get_the_ID();
if ($pageID == 15) // Home Page
echo
'<img src="<?php echo get_template_directory_uri(); ?>/images/document.png" width="200" height="200" alt="doc">';
else if ($pageID == 17) // Overview
echo
'<img src="<?get_template_directory_uri(); ?>/images/paperclip.png" width="200" height="200" alt="paperclip">';
?>
其中,此刻,看起來要工作,但圖像'回形針'沒有正確地在根目錄中訪問。
任何人都可以拿起我要去哪裏錯了嗎?我是一個絕對的PHP初學者,所以請原諒,如果它真的很明顯!
謝謝!