如何根据WordPress的类别显示多个单页模板?

问题描述:

我正在使用多个样式表,并且需要页面根据类别而有所不同。如何根据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

所有:

谢谢你看这个。为了让我得到这个工作,问题实际上是多个single.php文件。这可以通过让你的single.php看起来像这样,

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

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

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

    } 
?> 

我也编辑了其他人寻找这个答案的问题。

您不应该使用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;'; 
} 
?>