Как добавить CSS стиль wp

ER
На сайте с 25.05.2009
Offline
66
609

извините за ламерский вопрос. добавил такой код в functions php для вывода случайных записей:

function wpb_rand_posts() {
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 7,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$string .= '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$string .= '<li><a href="'. get_permalink() .'">'. get_the_post_thumbnail() .get_the_title() .'</a></li>';
}
$string .= '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
$string .= 'no posts found';
}
return $string;
}
add_shortcode('wpb-random-posts','wpb_rand_posts');
add_filter('widget_text', 'do_shortcode');

все работает, но надо стили прикрутить, не пойму куда в этот код добавить стиль random-posts чтобы потом его можно было редактировать через style css, если просто весь код взять в <div id="random-posts"></div> то весь functions перестает работать :)

melkozaur
На сайте с 06.04.2010
Offline
505
#1

Попробуйте вот так:

function wpb_rand_posts() {
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 7,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$string .= '<div id="random-posts"><ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$string .= '<li><a href="'. get_permalink() .'">'. get_the_post_thumbnail() .get_the_title() .'</a></li>';
}
$string .= '</ul></div>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
$string .= 'no posts found';
}
return $string;
}
add_shortcode('wpb-random-posts','wpb_rand_posts');
add_filter('widget_text', 'do_shortcode');
Серверы в NL/US со скидкой 30% нашим читателям: E5-2650v4/10GB DDR4/240GB SSD/1 Gbps - от $20: https://ua-hosting.company/vps/nl SEO без компромиссов: https://seoleaks.net SEOLEAKS - продвижение сайтов: https://www.instagram.com/seoleaks
ER
На сайте с 25.05.2009
Offline
66
#2

надо было так:

function wpb_rand_posts() {
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 7,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$string .= '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$string .= '<li class="right_col_element"><a href="'. get_permalink() .'">'. get_the_post_thumbnail() .get_the_title() .'</a></li>';
}
$string .= '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
$string .= 'no posts found';
}
return $string;
}

add_shortcode('wpb-random-posts','wpb_rand_posts');
add_filter('widget_text', 'do_shortcode');

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий