Skip to content

Instantly share code, notes, and snippets.

@sobytes
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sobytes/bef0c4de602e703680f9 to your computer and use it in GitHub Desktop.
Save sobytes/bef0c4de602e703680f9 to your computer and use it in GitHub Desktop.
Home page slider custom post type
/**
* Home page slider function to create a main slider
*
* @return void
* @author Sam East
*/
function home_slider_post_type() {
$labels = array(
'name' => _x( 'Home Slider', 'post type general name' ),
'singular_name' => _x( 'Home Slider', 'post type singular name' ),
'add_new' => _x( 'Add New', 'Slider' ),
'add_new_item' => __( 'Add New Slide' ),
'edit_item' => __( 'Edit Slide' ),
'new_item' => __( 'New Slide' ),
'all_items' => __( 'All Slide' ),
'view_item' => __( 'View Slide' ),
'search_items' => __( 'Search Slide' ),
'not_found' => __( 'No Slide found' ),
'not_found_in_trash' => __( 'No Slide found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Home Slider'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our Slides for home slider',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
);
register_post_type( 'HomeSlider', $args );
}
add_action( 'init', 'home_slider_post_type' );
<?php $loop = new WP_Query( array( 'post_type' => 'HomeSlider', '4' => -1 ) );
while ( $loop->have_posts() ) : $loop->the_post();
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<header class="clearfix headerwrap_inner" style="background-image: url('<?php echo $feat_image; ?>');"><h1><span class="icon icon-shield"></span></h1><p><?php the_title(); ?></p><p><?php the_content(); ?></p></header>
<?php endwhile; wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment