【问题标题】:How to display multiple single page templates based on categories for WordPress?WordPress 如何根据类别显示多个单页模板?
【发布时间】:2011-02-14 11:08:16
【问题描述】:

我正在使用多个样式表,并且需要根据类别来区分页面。

我在 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/

当您单击其中一个缩略图时,单个缩略图位于顶部,而缩略图位于底部。

【问题讨论】:

  • 什么不起作用?会发生什么?
  • 我认为 HTML 超出了 PHP 的控制范围。

标签: php wordpress stylesheet categories


【解决方案1】:

全部:

感谢您对此进行调查。为了让我让它工作,问题实际上是多个 single.php 文件。这可以通过让你的 single.php 看起来像这样来解决,

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

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

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

  }
?>

我还为寻找此答案的其他人编辑了问题。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-09
      相关资源
      最近更新 更多