I want to integrate a bs4 carousel inside all the posts of a wordpress page that is a portfolio. I'm thinking to use the attached images of a post, I don't want to use custom post type to do this. Can anyone with a good wordpress knowledge tell me a nice way to achieve this? My idea is to create a template part that will hold the carousel.
EDIT: Here is the code that I'm using for create a carousel. It's based on custom post type, but as I write I want to use post attachements and not custom post type
function custom_slider() {
$labels = array(
'name' => _x( 'Slider', 'post type general name'),
'singular_name' => _x( 'Slide', 'post type singular name'),
'menu_name' => _x( 'Slider sede', 'admin menu'),
'name_admin_bar' => _x( 'Slide', 'add new on admin bar'),
'add_new' => _x( 'Add New', 'Slide'),
'add_new_item' => __( 'Name'),
'new_item' => __( 'New Slide'),
'edit_item' => __( 'Edit Slide'),
'view_item' => __( 'View Slide'),
'all_items' => __( 'All Slide'),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'search_items' => __( 'Search Slide'),
'parent_item_colon' => __( 'Parent Slide:'),
'not_found' => __( 'No Slide found.'),
'not_found_in_trash' => __( 'No Slide found in Trash.'),
);
$args = array(
'labels' => $labels,
#'menu_icon' => 'dashicons-star-half',
'description' => __( 'Description.'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title','editor','thumbnail')
);
register_post_type( 'slider', $args );
}
add_action('init', 'custom_slider');
<div class="container-fluid" id="carousel-wrapper">
<div id="sede-carousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php $slider = get_posts(array('post_type' => 'slider', 'posts_per_page' => 5)); ?>
<?php $count = 0; ?>
<?php foreach($slider as $slide): ?>
<div class="carousel-item <?php echo ($count == 0) ? 'active' : ''; ?>">
<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($slide->ID)) ?>" class="img-responsive d-block w-100 slide"/>
</div>
<?php $count++; ?>
<?php endforeach; ?>
</div>
<a class="carousel-control-prev" href="#scarousel" role="button" data-slide="prev">
<span class="carousel-control-next-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#scarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>