Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Register Custom Post Type
- function themename_custom_post_type() {
- $labels = array(
- 'name' => _x( 'Portfolios', 'Post Type General Name', 'text_domain' ),
- 'singular_name' => _x( 'Portfolio', 'Post Type Singular Name', 'text_domain' ),
- 'menu_name' => __( 'Portfolios', 'text_domain' ),
- 'parent_item_colon' => __( 'Parent Portfolio Item:', 'text_domain' ),
- 'all_items' => __( 'All Portfolio Items', 'text_domain' ),
- 'view_item' => __( 'View Portfolio Item', 'text_domain' ),
- 'add_new_item' => __( 'Add New Portfolio Item', 'text_domain' ),
- 'add_new' => __( 'Add New', 'text_domain' ),
- 'edit_item' => __( 'Edit Portfolio Item', 'text_domain' ),
- 'update_item' => __( 'Update Portfolio Item', 'text_domain' ),
- 'search_items' => __( 'Search Portfolio Item', 'text_domain' ),
- 'not_found' => __( 'Not found', 'text_domain' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
- );
- $rewrite = array(
- 'slug' => 'portfolio',
- 'with_front' => true,
- 'pages' => true,
- 'feeds' => true,
- );
- $args = array(
- 'label' => __( 'portfolio', 'text_domain' ),
- 'description' => __( 'Post Type Description', 'text_domain' ),
- 'labels' => $labels,
- 'supports' => array( 'title', 'editor', 'thumbnail', ),
- 'hierarchical' => false,
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'show_in_nav_menus' => true,
- 'show_in_admin_bar' => true,
- 'menu_position' => 5,
- 'menu_icon' => 'dashicons-slides',
- 'can_export' => true,
- 'has_archive' => true,
- 'exclude_from_search' => false,
- 'publicly_queryable' => true,
- 'rewrite' => $rewrite,
- 'capability_type' => 'page',
- );
- register_post_type( 'portfolio', $args );
- }
- // Hook into the 'init' action
- add_action( 'init', 'themename_custom_post_type', 0 );
- /***********************************************************************
- To display posts from a specific post type.
- ***********************************************************************/
- $args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 );
- $loop = new WP_Query( $args );
- while ( $loop->have_posts() ) : $loop->the_post();
- //Your content go here
- the_title();
- echo '<div class="entry-content">';
- the_content();
- echo '</div>';
- //End of your content
- endwhile;
- /***********************************************************************
- Another way to display posts from a specific post type.
- ***********************************************************************/
- <?php
- global $post;
- $args = array( 'posts_per_page' => -1, 'post_type'=> 'portfolio');
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- <?php $slider_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'slider-thumb' ); ?>
- <li data-thumb="<?php echo $slider_image[0]; ?>">
- <?php the_post_thumbnail('slider-larger'); ?>
- <?php the_content(); ?>
- </li>
- <?php endforeach; ?>
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement