Class 8

[php]

<?php

//registering post type
function seo_testimonial_custompost(){
register_post_type(‘testimonial’, array(
‘labels’ => array(
‘name’ => ‘Testimonial’,
‘add_new’ => ‘Add new Testimonial’
),
‘public’ => true,
‘supports’ => array(‘title’, ‘thumbnail’)
));
}
add_action(‘init’, ‘seo_testimonial_custompost’);

//shortcode
function seo_testimonial_shortcode($atts, $content = null){
extract(shortcode_atts(
array(
‘type’ => ‘post’,
‘item’ => 5,
‘order’ => ‘ASC’
), $atts
));

$q = new WP_Query(array(
‘post_type’ => $type,
‘posts_per_page’ => $item,
‘order’ => $order
));

$list = ‘<ul>’;
while($q->have_posts()) : $q->the_post();
$list .= ‘<li><a href="’.get_permalink().’">’.get_the_title().'</a></li>’;
endwhile;
$list .= ‘</ul>’;

return $list;
}
add_shortcode(‘post_list’, ‘seo_testimonial_shortcode’);

?>

[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *