+91-943-185-6038 me@shashidharkumar.com

wordpressOpen “function.php” add the following code to add new custom post type :
<?php
add_action(‘init’, ‘featured_post_register’);

function featured_post_register() {
$labels = array(
‘name’ => _x(‘Featured Posts’, ‘post type general name’),
‘singular_name’ => _x(‘Featured Posts’, ‘post type singular name’),
‘add_new’ => _x(‘Add New’, ‘featured posts’),
‘add_new_item’ => __(‘Add New Featured Posts’),
‘edit_item’ => __(‘Edit Featured Posts’),
‘new_item’ => __(‘New Featured Posts’),
‘view_item’ => __(‘View Featured Posts’),
‘parent_item_colon’ => ”
);

$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’thumbnail’)
);

register_post_type( ‘featured-post’ , $args );
}
?>
Use the following code in template page to display custom post type :
<?php
$args = array( ‘post_type’ => ‘featured-post’, ‘posts_per_page’ => 1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
?>
<h3 class=”youtube-widget-title”>let the world hear you</h3>
<?php
echo ‘<div class=”entry-content”>’;
the_content();
echo ‘</div>’;
endwhile;
?>

See also  How to move Magento site from subdomain to main domain?