P
P
Pchelkin2015-10-31 12:06:07
Taxonomy
Pchelkin, 2015-10-31 12:06:07

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

2 answer(s)
W
WP Panda, 2015-10-31
@wppanda5

[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' );

P
Pchelkin, 2015-11-03
@webdjuice

Thanks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question