Create slider plugin in WordPress
here Simple Code
create country.php file.(wp-content\plugins\country\contry.php)
?>
Below create plugin, it's name, country slider.
For slider you want to create the first custom post
Here code for custom post
function country_slider_init( ) {
}
After addingjquery and css for the slider
function gina_abroad_scripts( ) { ( 'wp_enqueue_scripts', 'gina_abroad_scripts' ) ;
after create shortcode for use it.
function latest_country_slider( ) { ? >
global $post; ?> jQuery ( '. media'). bxSlider ( { minSlides : 2, maxSlides : 2, slideWidth : 170, slideMargin : 10 ( 'display_latest_country_slider', 'latest_country_slider' ) ;
here i will full code check it
function country_slider_init( ) {
function latest_country_slider( ) { ? >
global $post; ?> jQuery ( '. media'). bxSlider ( { minSlides : 2, maxSlides : 2, slideWidth : 170, slideMargin : 10
function gina_abroad_scripts( ) {
add_action( 'wp_enqueue_scripts', 'gina_abroad_scripts' ) ;
Step create plugin plugin folder, create folder and
<? php
/**
* Plugin Name: Country slider
* Plugin URI: http://myphpinformation.blogspot.in//
* Description: A brief description of the plugin.
*/?>
Below create plugin, it's name, country slider.
For slider you want to create the first custom post
Here code for custom post
add_action( 'init ', 'country_slider_init' ) ;
/**
* Register a Country post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
$labels = array(
'name ' => _x( 'Countries', 'post type general name', 'your-plugin-textdomain ' ) ,
'singular_name' => _x( 'Country', 'post type singular name', 'your-plugin-textdomain ' ) ,
'menu_name' => _x( 'Countries', 'admin menu', 'your-plugin-textdomain ' ) ,
'name_admin_bar' => _x( 'Country', 'add new on admin bar ', 'your-plugin-textdomain ' ) ,
'add_new' => _x( 'Add New', 'Country', 'your-plugin-textdomain ' ) ,
'add_new_item' => __( 'Add New Country ', 'your-plugin-textdomain ' ) ,
'new_item' => __( 'New Country', 'your-plugin-textdomain ' ) ,
'edit_item' => __( 'Edit Country', 'your-plugin-textdomain ' ) ,
'view_item' => __( 'View Country', 'your-plugin-textdomain ' ) ,
'all_items' => __( 'All Countries', 'your-plugin-textdomain ' ) ,
'search_items' => __( 'Search Countries', 'your-plugin-textdomain ' ) ,
'parent_item_colon' => __( 'Parent Countries:', 'your-plugin-textdomain ' ) ,
'not_found' => __( 'No Countries found.', 'your-plugin-textdomain ' ) ,
'not_found_in_trash' => __( 'No Countries found in Trash .', 'your-plugin-textdomain ' )
);
$args = array(
'labels' => $labels,
'public ' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite ' => array( 'slug' => 'country_slider' ) ,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical ' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor','thumbnail', )
);
register_post_type( 'country_slider', $args ) ;
After adding
wp_enqueue_script( 'bxslider-js', get_stylesheet_directory_uri(). '/bxslider /jquery . bxslider . min. js' , array( 'jquery ' ) ) ;
wp_enqueue_style( 'bxslider-css', get_stylesheet_directory_uri(). '/bxslider /jquery . bxslider . css' ) ;
}
add_action <? php $args = array( 'post_type' => 'country_slider', 'posts_per_page' => 10 ) ;
$loop = new WP_Query( $args ) ;
<ul class="media">
<? php while ( $loop->have_posts( ) ) {
$loop->the_post( );
$postid = get_the_ID( );
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<li >
<div class="media-left">
<a href="<? php echo get_the_permalink( ); ?>"><img src="<? php echo $url;?>" title="<? php echo get_the_title( );?>" alt="<? php echo get_the_title( );?>"/></a>
</div >
<div class="media-body">
<h4 class="media-heading"><? php echo get_the_title( ); ?></h4>
<p ><i class="fa fa-caret-right"></i ><? php echo get_the_content( ); 1 ? ></p >
</div >
</li >
<? php } ? >
</ul >
<script type="text/javascript">
});
</script >
<? php
}
add_shortcodeYou cane use [display_latest_country_slider] short code in your post and page.
<? php
/**
* Plugin Name: Country slider
* Plugin URI: http://myphpinformation.blogspot.in//
* Description: A brief description of the plugin.
*/
add_action( 'init ', 'country_slider_init' ) ;
/**
* Register a Country post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
$labels = array(
'name ' => _x( 'Countries', 'post type general name', 'your-plugin-textdomain ' ) ,
'singular_name' => _x( 'Country', 'post type singular name', 'your-plugin-textdomain ' ) ,
'menu_name' => _x( 'Countries', 'admin menu', 'your-plugin-textdomain ' ) ,
'name_admin_bar' => _x( 'Country', 'add new on admin bar ', 'your-plugin-textdomain ' ) ,
'add_new' => _x( 'Add New', 'Country', 'your-plugin-textdomain ' ) ,
'add_new_item' => __( 'Add New Country ', 'your-plugin-textdomain ' ) ,
'new_item' => __( 'New Country', 'your-plugin-textdomain ' ) ,
'edit_item' => __( 'Edit Country', 'your-plugin-textdomain ' ) ,
'view_item' => __( 'View Country', 'your-plugin-textdomain ' ) ,
'all_items' => __( 'All Countries', 'your-plugin-textdomain ' ) ,
'search_items' => __( 'Search Countries', 'your-plugin-textdomain ' ) ,
'parent_item_colon' => __( 'Parent Countries:', 'your-plugin-textdomain ' ) ,
'not_found' => __( 'No Countries found.', 'your-plugin-textdomain ' ) ,
'not_found_in_trash' => __( 'No Countries found in Trash .', 'your-plugin-textdomain ' )
);
$args = array(
'labels' => $labels,
'public ' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite ' => array( 'slug' => 'country_slider' ) ,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical ' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor','thumbnail', )
);
register_post_type( 'country_slider', $args ) ;
}
<? php $args = array( 'post_type' => 'country_slider', 'posts_per_page' => 10 ) ;
$loop = new WP_Query( $args ) ;
<ul class="media">
<? php while ( $loop->have_posts( ) ) {
$loop->the_post( );
$postid = get_the_ID( );
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<li >
<div class="media-left">
<a href="<? php echo get_the_permalink( ); ?>"><img src="<? php echo $url;?>" title="<? php echo get_the_title( );?>" alt="<? php echo get_the_title( );?>"/></a>
</div >
<div class="media-body">
<h4 class="media-heading"><? php echo get_the_title( ); ?></h4>
<p ><i class="fa fa-caret-right"></i ><? php echo get_the_content( ); 1 ? ></p >
</div >
</li >
<? php } ? >
</ul >
<script type="text/javascript">
});
</script >
<? php
}
add_shortcode( 'display_latest_country_slider', 'latest_country_slider' ) ;
?>
wp_enqueue_script( 'bxslider-js', get_stylesheet_directory_uri(). '/bxslider /jquery . bxslider . min. js' , array( 'jquery ' ) ) ;
wp_enqueue_style( 'bxslider-css', get_stylesheet_directory_uri(). '/bxslider /jquery . bxslider . css' ) ;
}
add_action
0 komentar:
Post a Comment