Skip to content

Instantly share code, notes, and snippets.

@salehahmadbabu
Created February 7, 2018 15:55
Show Gist options
  • Save salehahmadbabu/bfb543a255e9495550283c3ffd3251e6 to your computer and use it in GitHub Desktop.
Save salehahmadbabu/bfb543a255e9495550283c3ffd3251e6 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Stock Toolkit
*/
add_action( 'init', 'stock_theme_custom_post' );
function stock_theme_custom_post() {
register_post_type( 'testimonial',
array(
'labels' => array(
'name' => __( 'Testimonials' ),
'singular_name' => __( 'Testimonial' )
),
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'public' => false,
'show_ui' => true,
)
);
}
function post_list_shortcode($atts){
extract( shortcode_atts( array(
'count' => -1,
'type' => 'post',
), $atts) );
$q = new WP_Query(
array('posts_per_page' => $count, 'post_type' => $type)
);
$list = '<div>';
while($q->have_posts()) : $q->the_post();
$idd = get_the_ID();
$post_content = get_the_content();
$thumbnail = get_the_post_thumbnail_url( $post->ID, 'thumbnail' );
$list .= '
<div>
<ul>
<li><img src="'.$thumbnail.'"></li>
<li><a href="'.get_permalink().'">'.get_the_title().'</li>
<li>'.$post_content.'</li>
</ul></div>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('post_list', 'post_list_shortcode');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment