slider post

PHOTO EMBED

Fri Jan 05 2024 09:59:59 GMT+0000 (Coordinated Universal Time)

Saved by @BilalRaza12

function create_slider()
{

	$labels = array(
		'name' => _x('Slider', 'Post Type General Name', 'textdomain'),
		'singular_name' => _x('Slider', 'Post Type Singular Name', 'textdomain'),
		'menu_name' => _x('Slider', 'Admin Menu text', 'textdomain'),
		'name_admin_bar' => _x('Slider', 'Add New on Toolbar', 'textdomain'),
		'archives' => __('Slider Archives', 'textdomain'),
		'attributes' => __('Slider Attributes', 'textdomain'),
		'parent_item_colon' => __('Parent Slider:', 'textdomain'),
		'all_items' => __('All Slider', 'textdomain'),
		'add_new_item' => __('Add New Slider', 'textdomain'),
		'add_new' => __('Add New', 'textdomain'),
		'new_item' => __('New Slider', 'textdomain'),
		'edit_item' => __('Edit Slider', 'textdomain'),
		'update_item' => __('Update Slider', 'textdomain'),
		'view_item' => __('View Slider', 'textdomain'),
		'view_items' => __('View Slider', 'textdomain'),
		'search_items' => __('Search Slider', 'textdomain'),
		'not_found' => __('Not found', 'textdomain'),
		'not_found_in_trash' => __('Not found in Trash', 'textdomain'),
		'featured_image' => __('Featured Image', 'textdomain'),
		'set_featured_image' => __('Set featured image', 'textdomain'),
		'remove_featured_image' => __('Remove featured image', 'textdomain'),
		'use_featured_image' => __('Use as featured image', 'textdomain'),
		'insert_into_item' => __('Insert into Slider', 'textdomain'),
		'uploaded_to_this_item' => __('Uploaded to this Slider', 'textdomain'),
		'items_list' => __('Slider list', 'textdomain'),
		'items_list_navigation' => __('Slider list navigation', 'textdomain'),
		'filter_items_list' => __('Filter Slider list', 'textdomain'),
	);
	$rewrite = array(
		'slug' => 'slider',
		'with_front' => true,
		'pages' => true,
		'feeds' => true,
	);
	$args = array(
		'label' => __('Slider', 'textdomain'),
		'description' => __('', 'textdomain'),
		'labels' => $labels,
		'menu_icon' => 'dashicons-admin-appearance',
		'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'page-attributes', 'post-formats', 'custom-fields'),
		'taxonomies' => array(),
		'public' => true,
		'show_ui' => true,
		'show_in_menu' => true,
		'menu_position' => 5,
		'show_in_admin_bar' => true,
		'show_in_nav_menus' => true,
		'can_export' => true,
		'has_archive' => true,
		'hierarchical' => true,
		'exclude_from_search' => true,
		'show_in_rest' => true,
		'publicly_queryable' => true,
		'capability_type' => 'post',
		'rewrite' => $rewrite,
	);
	register_post_type('slider', $args);
	register_taxonomy('slider_category', 'slider', array('hierarchical' => true, 'label' => 'Category', 'query_var' => true, 'rewrite' => array('slug' => 'slider-category')));
}
add_action('init', 'create_slider', 0);




function slider_loop()
{
	
	
	$arg = array(
		'post_type' => 'slider',
		'posts_per_page' => -1,
		);
        $sliderPost = new WP_Query($arg);
	?>
	<div id="mainSlider" class="main-slider">
	<?php if ($sliderPost->have_posts()) : ?>
			<?php while ($sliderPost->have_posts()) : ?>
			<?php $sliderPost->the_post(); 
			$url = wp_get_attachment_url(get_post_thumbnail_id($sliderPost->ID)); 
			?>
			<div class="singleBanner" style="background:url('<?php echo $url ?>');">
			    <div class="container">
			         <div class="banner-content">
                         <h1><?php the_field('banner-heading');?></h1>
                          <p><?php the_field('banner-para');?></p>
                      <div class="banner-btn">
                          <a href="<?php the_field('banner-btn-link');?>" class="ban-btn1"><?php the_field('banner-btn');?><span><img src="https://stageportfoilo.com/wp/voyager/wp-content/uploads/2023/10/right-arrow-1-copy-5.png"></span></a>
                        <a href="<?php the_field('banner-btn-link2');?>" class="ban-btn2" ><?php the_field('banner-btn-txt2');?><span><img src="https://stageportfoilo.com/wp/voyager/wp-content/uploads/2023/10/right-arrow-1-copy-5.png"></span></a>
                         </div>
                   </div>
			    </div>
			</div>
			<?php endwhile; ?>
            <?php endif; ?>
</div>
<?php
	wp_reset_postdata();

}
add_shortcode('mainBanner', 'slider_loop');

function slick_cdn_enqueue_scripts()
{
	wp_enqueue_style('slick-style', '//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css');
	wp_enqueue_script('slick-script', '//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js', array(), null, true);
}
add_action('wp_enqueue_scripts', 'slick_cdn_enqueue_scripts');
content_copyCOPY