N
N
Nikita Ivanov2013-12-14 09:18:15
css
Nikita Ivanov, 2013-12-14 09:18:15

How to make a different style for different categories and pages in Wordpress?

There are two css files, one should load on certain pages and categories, the other on all others.
The title snippet is:

<?php if( is_category(array( 16, 7, 5, 11, 12,6,8,22)) || in_category(16) || is_page( array(30, 28, 22, 34, 547, 553, 311, 529, 36, 40, 42, 38, 307)) && !is_home()  && !is_category(4)) {  ?>

<link rel="stylesheet" id="style-css" href="1.css" type="text/css" media="all" />
<?php } 

else {  ?>

<link rel="stylesheet" id="style-css" href="2.css" type="text/css" media="all" />

<?php  }  ?>

It turns out that if style 1 is assigned to a child category, then it is also issued to the parent category.
And the second style is displayed on the main page.
How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
avalak, 2013-12-14
@avalak

It is correct to use the wp_enqueue_scripts hook .

N
Nikolai Antal, 2013-12-14
@hermit931

As far as I understand from the description of the functions is_category and in_category , these are several different functions - the first one relates to category templates (category.php), the second to posts (post.php).
And @avalak 's advice is good too

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question