php - 将 CSS 样式添加到文章页面上的 Wordpress 侧边栏

标签 php css wordpress sidebar custom-wordpress-pages

我需要为网站上的文章和单页边栏添加独特的 CSS 样式,以区别于主页。侧边栏已经有一个名为“.sidebar”的样式,当我更改它时它可以工作,但它会影响所有站点侧边栏。

我一直在查看 sidebars.php 文件,看到主页或单页有“if”行,但不知道要更改什么。请记住,我不是程序员。

我认为应该修改的代码是(sidebar.php):

<aside class="sidebar">
<?php
    wp_reset_query();
    if ( is_home() ){

        $sidebar_home = tie_get_option( 'sidebar_home' );
        if( $sidebar_home )
            dynamic_sidebar ( sanitize_title( $sidebar_home ) ); 

        else dynamic_sidebar( 'primary-widget-area' );  

    }elseif( is_page() ){
        global $get_meta;
        $tie_sidebar_pos = $get_meta["tie_sidebar_pos"][0];

        if( $tie_sidebar_pos != 'full' ){
            $tie_sidebar_post = sanitize_title($get_meta["tie_sidebar_post"][0]);
            $sidebar_page = tie_get_option( 'sidebar_page' );
            if( $tie_sidebar_post )
                dynamic_sidebar($tie_sidebar_post);

            elseif( $sidebar_page )
                dynamic_sidebar ( sanitize_title( $sidebar_page ) ); 

            else dynamic_sidebar( 'primary-widget-area' );
        }

    }elseif ( is_single() ){
        global $get_meta;
        $tie_sidebar_pos = $get_meta["tie_sidebar_pos"][0];

        if( $tie_sidebar_pos != 'full' ){
            $tie_sidebar_post = sanitize_title($get_meta["tie_sidebar_post"][0]);
            $sidebar_post = tie_get_option( 'sidebar_post' );
            if( $tie_sidebar_post )
                dynamic_sidebar($tie_sidebar_post);

            elseif( $sidebar_post )
                dynamic_sidebar ( sanitize_title( $sidebar_post ) ); 

            else dynamic_sidebar( 'primary-widget-area' );
        }

    }elseif ( is_category() ){

        $category_id = get_query_var('cat') ;
        $cat_sidebar = tie_get_option( 'sidebar_cat_'.$category_id ) ;
        $sidebar_archive = tie_get_option( 'sidebar_archive' );

        if( $cat_sidebar )
            dynamic_sidebar ( sanitize_title( $cat_sidebar ) ); 

        elseif( $sidebar_archive )
            dynamic_sidebar ( sanitize_title( $sidebar_archive ) );

        else dynamic_sidebar( 'primary-widget-area' );

    }else{
        $sidebar_archive = tie_get_option( 'sidebar_archive' );
        if( $sidebar_archive ){
            dynamic_sidebar ( sanitize_title( $sidebar_archive ) );
        }
        else dynamic_sidebar( 'primary-widget-area' );
    }
?>
</aside>

在此先感谢您提供解决此问题的任何帮助。

最佳答案

您的文章应该有一个唯一的页面或帖子 ID,查看页面/帖子源代码以获取 ID。你的 css 看起来像 #post_455 .sidebar { /* 你独特的文章风格 */ }

ps - 你不需要玩弄 sidebar.php

关于php - 将 CSS 样式添加到文章页面上的 Wordpress 侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38233123/

相关文章:

CSS 显示 : none; not working in Firefox. 我该如何解决这个问题?

php - 在新订单 Hook 中获取订单数据

php - 无法将数据从表单传递到模型 zend 2.3

php - 将 JS 函数转换为 PHP

jquery - Bootstrap 响应式网格不起作用

css - 使输入字段透明

javascript - 滚动时触发动画

mysql - 缓慢的 MySQL 查询 (Wordpress)

php - MySQL将玩家信息与时间连接起来

php - 如何在 <div> 中按两个分组显示数组元素