Просто выполните следующие шаги
Шаг 1: за кодом в файле function.php
function create_posttype() {
register_post_type( 'Events',
// CPT Options
array(
'labels' => array(
'name' => __( 'CTA' ),
'singular_name' => __( 'CTA' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'CTA'),
'taxonomies' => array( 'category' ),
'supports' => array( 'title', 'editor','thumbnail' ),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
это создасттип записи " CTA ".
Шаг 2: Получить блог определенной категории в типе записи.
function blogcts() {
$args=array(
'posts_per_page' => 100,
'post_type' => 'CTA', // posttype name
'order' => 'ASC',
'cat'=> 5 //category id
);
$wp_query = new WP_Query( $args );
$pp .='';
while ($wp_query->have_posts()) : $wp_query->the_post();
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($productPost->ID)); //feature
$contents = get_the_content(); //Fetch
$contents_new = substr($contents, 0, 50);
$excerpt = get_the_excerpt();
$pp .=' <div class="">
<div class="">
<img src="'.$feat_image .'" class="" alt="">
</div>
<p>'. get_the_title() .'</p>
<hr>
<p>'.$contents_new.'</p>
<p class=""><a href="'. get_the_permalink() .'"> More</a></p>
</div>';
endwhile;
$pp .='</div>';
return '' .$pp.'';
}
add_shortcode('srtcode_blogcts', 'blogcts');
Шаг 3: Вставьте шорткод на страницу.
[srtcode_blogcts]
или файл шаблона
<?php echo do_shortcode('[srtcode_blogcts]'); ?>