A
A
Alexey2020-04-11 10:50:05
css
Alexey, 2020-04-11 10:50:05

A couple of questions: background for wordpress category posts, header?

Help me solve a couple of questions:
1. I made a certain background (background) on the home page, for each of the headings there is a different background:
body.home {
background: url('....')
...
}
body.category-1 {
background -image: url("X") ;
.....
}
and so on

for a single entry is clear:
.postid-1 {

background-image: url(".... ") ;
...
}
how to set a common background "X" for all entries in category 1?

Second question. Set the padding for the header
#header .hu-pad {
padding-top: 260px;
}

similar to the first question - how to implement indentation only on the home page (the home page is supposed to be temporary), in the categories (all category entries)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan Hasanli, 2020-04-11
@azerphoenix

for a single entry it is clear:

.postid-1 {

background-image: url(".... ") ;
...
}

In theory it's not exactly a single post, but a post with an ID of 1. postid-1
I think this is not the correct way to assign a style to a single post.
how to set a common background "X" for all entries in category 1?

Such logic should be decided at the PHP level.
Read about VI conditional tags.
https://wp-kama.ru/id_89/uslovnyie-tegi-v-wordpres...
Second question. I set the indentation for the header
similarly to the first question - how to implement the indentation only on the home page (on the home page is supposed to be temporary), in categories (all category entries)?

The answer to all your questions is Wordpress conditional tags.
For the homepage the logic is:
if( is_front_page() || is_home ) {
// вставляем стили для главной
}

For single entry tag
if( is_single()  ) {
// вставляем стили для одиночной записи
}

To check if a post is in a certain category (rubric)
if ( in_category( 10 ) ) {
// вставляем стили для записи, которая находится в рубрике с ID 10
}

A
Alexey, 2020-04-12
@ColorWave

In theory, this is not exactly a single record, but a record with an ID equal to 1 postid-1

Yes, you're right, that's what I mean.
Thank you, azerphoenix, for participating! with php, unfortunately, problems ...
with background-image came to this solution:
<?php if ( in_category()): ?>
  <div class=".." style="background-image: url('<?php $image=wp_get_attachment_image_src( $attachment_id, 'full'); echo $image[0]; ?>);">; 
<?php endif ?>

In the process of solving a new question was formed - how to make an image "clickable" so that the link leads to a specific post/page? in which direction to dig?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question