Answer the question
In order to leave comments, you need to log in
How to make a category shortcode for Wordpress?
In the admin panel in WYSYWING, when editing the page, make it possible to display all posts of the category as a shortcode, the shortcode should look like [category = "category slug"]. Tell me how to do this?
Answer the question
In order to leave comments, you need to log in
[category slug="category slug" ]
<?php
function my_shortcode( $atts ) {
extract( shortcode_atts(
array(
'slug' => '',
), $atts )
);
$out ='';
$query = new WP_Query('category_name=' . $slug);
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$out .= '<div><h3 >' . get_the_title() . '</h3>' . get_the_content() . '</div>';
}
} else {
$out .= 'Записей для вывода шорткодом нет';
}
wp_reset_query();
return $out;
}
add_shortcode( 'category ', 'my_shortcode' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question