functions.php
add_theme_support( 'post-thumbnails', array( 'post', 'slider') );
add_image_size( 'slider-image', 920, 347, true );
function create_post_type() {
register_post_type( 'slider',
array(
'labels' => array(
'name' => __( 'Slides' ),
'singular_name' => __( 'Slide' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Slide' ),
'edit_item' => __( 'Edit Slide' ),
'new_item' => __( 'New Slide' ),
'view_item' => __( 'View Slide' ),
'not_found' => __( 'Sorry, we couldn't find the Slide you are looking for.' )
),
'public' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
// 'show_in_menu' => false,
'menu_position' => 14,
'has_archive' => false,
'hierarchical' => false,
'capability_type' => 'page',
'rewrite' => array( 'slug' => 'slide' ),
'supports' => array( 'title','editor','custom-fields', 'thumbnail' )
)
);
/*
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'SlPortfoliode' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Slide' ),
'edit_item' => __( 'Edit Portfolio' ),
'new_item' => __( 'New Portfolio' ),
'view_item' => __( 'View Portfolio' ),
'not_found' => __( 'Sorry, we couldn't find the Portfolio you are looking for.' )
),
'public' => true,
'publicly_queryable' =>true,
'exclude_from_search' => true,
// 'show_in_menu' => false,
'menu_position' => 14,
'has_archive' => false,
'hierarchical' => false,
'capability_type' => 'page',
'rewrite' => array( 'slug' => 'portfolio' ),
'supports' => array( 'title', 'thumbnail' )
)
);
*/
}
add_action( 'init', 'create_post_type' );
Uses:
<?php the_post_thumbnail('slider-image', array('class' => 'customimage'));
?>
Note: If you need to link with the slider image use custom field with it.
add_theme_support( 'post-thumbnails', array( 'post', 'slider') );
add_image_size( 'slider-image', 920, 347, true );
function create_post_type() {
register_post_type( 'slider',
array(
'labels' => array(
'name' => __( 'Slides' ),
'singular_name' => __( 'Slide' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Slide' ),
'edit_item' => __( 'Edit Slide' ),
'new_item' => __( 'New Slide' ),
'view_item' => __( 'View Slide' ),
'not_found' => __( 'Sorry, we couldn't find the Slide you are looking for.' )
),
'public' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
// 'show_in_menu' => false,
'menu_position' => 14,
'has_archive' => false,
'hierarchical' => false,
'capability_type' => 'page',
'rewrite' => array( 'slug' => 'slide' ),
'supports' => array( 'title','editor','custom-fields', 'thumbnail' )
)
);
/*
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'SlPortfoliode' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Slide' ),
'edit_item' => __( 'Edit Portfolio' ),
'new_item' => __( 'New Portfolio' ),
'view_item' => __( 'View Portfolio' ),
'not_found' => __( 'Sorry, we couldn't find the Portfolio you are looking for.' )
),
'public' => true,
'publicly_queryable' =>true,
'exclude_from_search' => true,
// 'show_in_menu' => false,
'menu_position' => 14,
'has_archive' => false,
'hierarchical' => false,
'capability_type' => 'page',
'rewrite' => array( 'slug' => 'portfolio' ),
'supports' => array( 'title', 'thumbnail' )
)
);
*/
}
add_action( 'init', 'create_post_type' );
Uses:
<?php the_post_thumbnail('slider-image', array('class' => 'customimage'));
?>
------------OR--------------
<img src="<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'slider-image'); echo $image[0]; ?> atl=""> Note: If you need to link with the slider image use custom field with it.
Example
Uses: Look the source<ul> Put the code </ul>
----------------------------------------------------------------------------
<div class="slider">
<ul class="items">
<?php if(!is_paged()) { ?>
<?php
$args = array( 'post_type' => 'slider', 'posts_per_page' => 5 );
$loop = new WP_Query( $args );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php } ?>
</ul>
</div>
----------------------------------------------------------------------------
<div class="slider">
<ul class="items">
<?php if(!is_paged()) { ?>
<?php
$args = array( 'post_type' => 'slider', 'posts_per_page' => 5 );
$loop = new WP_Query( $args );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li>
<?php the_post_thumbnail('slider-image', array('class' => 'customimage')); ?>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php } ?>
</ul>
</div>