2011-02-14 36 views
1

我正在使用多個樣式表,並且需要頁面根據類別而有所不同。如何根據WordPress的類別顯示多個單頁模板?

我在header.php中添加了以下內容,但顯示了基本主題的單個條目模板。有任何想法嗎?

<?php if (is_category('20')) { ?> 
     <link rel="stylesheet" type="text/css" href="wp-content/themes/tanzaku/style.css" /> 
    <?php } else {?> 
     <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/style.css" /> 
    <?php } ?> 

我使用的是與這些網站相同的主題,但我在這些網站上使用了兩個主題。

  1. http://marioortega.net/
  2. http://atelier6.co.uk/

當你點擊一個縮略圖,單端起來的頂部和底部的縮略圖。

+0

什麼不起作用?怎麼了? – 2011-02-14 11:09:26

+0

我認爲HTML不在PHP的控制範圍之內。 – Hellonearthis 2011-02-14 11:57:57

回答

0

所有:

謝謝你看這個。爲了讓我得到這個工作,問題實際上是多個single.php文件。這可以通過讓你的single.php看起來像這樣,

<?php 
    $post = $wp_query->post; 

    if (in_category('20')) { 
    include(TEMPLATEPATH . '/single1.php'); 

    } else { 
    include(TEMPLATEPATH . '/single2.php'); 

    } 
?> 

我也編輯了其他人尋找這個答案的問題。

0

您不應該使用echo語句將鏈接放入您的頁面。

<?php 
    if (is_category('20')) { 
    echo '&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;wp-content/themes/tanzaku/style.css&quot; /&gt;'; 
    } 
else { 
    echo '&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;'.bloginfo('template_url').'/style.css&quot; /&gt;'; 
} 
?> 
相關問題