2017-04-11 2 views
0

저는 Wordpress 및 CSS에 다소 익숙합니다. 사람들이 나를 도울 수 있기를 바랍니다. 특정 카테고리의 모든 게시물 중 sitelogo .site-branding의 위치를 ​​변경하고 싶습니다.Wordpress에서 카테고리의 게시물 CSS를 변경하십시오.

내 style.css에서 site-branding을 좋아할만한 것으로 바꿀 수 있지만 모든 페이지, 게시물 및 카테고리를 포함한 전체 사이트에 영향을줍니다.

.site-branding { 
    left: 50%; 
    position: absolute; 
    top: 40%; 
    -webkit-transform: translate(-50%, -50%); 
    -ms-transform: translate(-50%, -50%); 
    transform: translate(-50%, -50%); 

여러분이 도와 주길 바랍니다.

미리 감사드립니다.

+0

A의 소스에서 링크 또는 무언가 (HTML/코드)를 게시하시기 바랍니다 :이 작업이 일단

, 당신은이 같은 뉴스 카테고리에서 하나의 게시물에 .site-branding을 대상으로 그 몸 클래스를 사용할 수 있습니다 깡깡이. – dutchsociety

+0

본문에있는 클래스별로 특정 카테고리 페이지를 타겟팅 할 수 있어야합니다. 귀하의 테마에서 body_class()를 사용한다고 가정하십시오. –

답변

0

아마도 Javascript와 Jquery가 필요합니다.

그래서

이 당신의 URL 구조 인 경우 www.mysite.com/home/category/,

(function($){ 
var $pathArray = window.location.pathname.split('/'); 
var $location = pathArray[2] 
var $branding = $(".site-branding") 
if ($location == 'cat1' || $location == 'cat2') { 
    $branding.css({ 
     'left' : '50%', 
     'position' : 'absolute', 
     'top' : '40%', 
     '-webkit-transform' : 'translate(-50%, -50%)', 
     '-ms-transform' : 'translate(-50%, -50%)', 
     'transform' : 'translate(-50%, -50%)' 
    }); 
} 
}); 

당신이 (당신의 워드 프레스 인스턴스에서 자식 테마를 실행하는 가정하는 당신이 아니라 당신이 확실히있는 경우 should) header.php 파일 맨 아래에이 스크립트를 추가 할 수 있습니다.

0

저는 현재 게시물이 특정 카테고리에 있는지 확인하는 PHP 조건부를 header.php에 추가 한 다음 위치를 변경하는 로고 태그에 다른 클래스를 추가해야한다고 생각합니다.

<h1 class="site-branding <?php in_array(YOUR_CATEGORY_ID, get_the_category((get_the_ID())) ? ' new-posision' : '' ; ?>"></h1> 
0

워드 프레스는 body 태그에 클래스로 카테고리를 추가 할 수 있습니다 :

은 다음과 같이 될 것이다. 카테고리에 맞는 CSS 규칙을 추가하는 것보다 테마에 맞는 경우.

.category .site-branding { 
    /* your css rules here */ 
} 
1

워드 프레스는 당신에게 당신의 스타일 시트 (보통 "카테고리-X를")의 이름을 추가하여 범주를 대상으로 할 수있는 기능을 제공하고 당신은 고유의 CSS에있는 모든 카테고리를 타겟팅 할 수 있습니다.

Here's a great step by step article for targeting this class in your css.

예는 다음과 같을 수 있습니다

카테고리 - 농업
<body class="archive category category-agriculture category-40"> 

당신과 같이 대상으로 지정할 클래스 인 : 노력에 대한

body.category-agriculture .site-branding {color: red;} 
1

감사합니다,하지만 난 약간의 도움을했고 한 문제가 해결되었습니다.

나는 필터가 하나의 게시물에 body에 클래스로 카테고리 이름을 추가 할 것입니다 내 functions.php

function pn_body_class_add_categories($classes) { 

// Only proceed if we're on a single post page 
if (!is_single()) 
    return $classes; 

// Get the categories that are assigned to this post 
$post_categories = get_the_category(); 

// Loop over each category in the $categories array 
foreach($post_categories as $current_category) { 

    // Add the current category's slug to the $body_classes array 
    $classes[] = 'category-' . $current_category->slug; 

} 

// Finally, return the $body_classes array 
return $classes; 
} 
add_filter('body_class', 'pn_body_class_add_categories'); 

에이 필터를 추가했다.

예를 들어, 해당 범주의 뉴스가 호출되면 category-news이 단일 게시물의 클래스로 본문에 추가됩니다.

.single.category-news .site-branding { 
left: 20%; 
} 
관련 문제