S
S
Sergey Defactov2018-08-09 14:14:45
WordPress
Sergey Defactov, 2018-08-09 14:14:45

Set entry class with id?

There are received id records in the form 22 , 37 ,12 all separated by commas,
how can I set the class with this id ? or through style
I try like this

<?php $custom_values = get_post_meta($post->ID, 'продукт_в_отраслях'); ?>

<li id="post-<?php the_ID(); ?>" <?php post_class( $custom_values ,$custom_values ); ?>>

and through style
I specify post-<?php the_field('my field') ?> {there is style }
but since id's are separated by commas, it doesn't work
any ideas?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan Hasanli, 2018-08-09
@azerphoenix

Hello!
If I understand your example correctly, then you are using the ACF plugin.
A simple example of how you can set a class, provided that the article being viewed matches the post id.

<?php if(is_single(array(22,37,12))) { ?>
<!-- ваш код здесь -->
<?php } ?>

using this code, for example, you can add opening and closing tags... example:
<?php if(is_single(array(22,37,12))) { ?>
<div class="content"> <!-- открыв тег -->
<?php } ?>
<!-- bla bla content -->
<?php if(is_single(array(22,37,12))) { ?>
</div> <!-- закрыв. тег -->
<?php } ?>

I
Igor Vorotnev, 2018-08-10
@HeadOnFire

but since id's are separated by commas it doesn't work

Read about:
- explode
- foreach
These are the basics of PHP, the very basics.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question