build a custom wordpress slider using a custom post type
/******** slider in dashboard ********/
/****** paste into functions.php ******/
function my_custom_sliders_posttype(){
$args = array(
'labels'=> array( 'name'=>'sliders',
'singular_name'=> 'slider',
'menu_name'=>'sliders',
'name_admin_bar'=> 'sliders',
'all_items' =>'View all sliders',
'add_new'=> 'Add New sliders' ),
'description' =>"This post type is for sliders",
'public' => true,
'exclude_from_search'=>false,
'publicly_queryable'=> true,
'show_ui' => true,
'show_in_menu'=> true,
'show_in_admin_bar'=> true,
'menu_position'=>6,
'capability_type'=> 'page',
'supports'=> array( 'title', 'editor', 'author', 'thumbnail', 'excerpt',
),
'query_var'=>true,
);
register_post_type( "sliders", $args );
}
add_action("init","my_custom_sliders_posttype");
/******./slider in dashboard***********/
<!--past into custome file-->
<div class="carousel-inner">
<?php
$class_active="active";
$args=array(
'post_type'=> 'sliders',
'post_status' => 'publish',
'posts_per_page' => 3,
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="item <?php echo $class_active ;?>">
<?php the_post_thumbnail('full'); ?>
<div class="container">
<div class="caro-caps">
<h2> <?php the_title(); ?> </h2>
<p> <?php the_content();?> </p>
<div class="lnk-btn more-btn"><a href="#">More Details</a></div>
</div>
</div>
</div>
<?php
$class_active="";
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
</div>
/****** paste into functions.php ******/
function my_custom_sliders_posttype(){
$args = array(
'labels'=> array( 'name'=>'sliders',
'singular_name'=> 'slider',
'menu_name'=>'sliders',
'name_admin_bar'=> 'sliders',
'all_items' =>'View all sliders',
'add_new'=> 'Add New sliders' ),
'description' =>"This post type is for sliders",
'public' => true,
'exclude_from_search'=>false,
'publicly_queryable'=> true,
'show_ui' => true,
'show_in_menu'=> true,
'show_in_admin_bar'=> true,
'menu_position'=>6,
'capability_type'=> 'page',
'supports'=> array( 'title', 'editor', 'author', 'thumbnail', 'excerpt',
),
'query_var'=>true,
);
register_post_type( "sliders", $args );
}
add_action("init","my_custom_sliders_posttype");
/******./slider in dashboard***********/
<!--past into custome file-->
<div class="carousel-inner">
<?php
$class_active="active";
$args=array(
'post_type'=> 'sliders',
'post_status' => 'publish',
'posts_per_page' => 3,
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="item <?php echo $class_active ;?>">
<?php the_post_thumbnail('full'); ?>
<div class="container">
<div class="caro-caps">
<h2> <?php the_title(); ?> </h2>
<p> <?php the_content();?> </p>
<div class="lnk-btn more-btn"><a href="#">More Details</a></div>
</div>
</div>
</div>
<?php
$class_active="";
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
</div>
Comments
Post a Comment