Ad Code

✨🎆 Diwali Dhamaka Offer! 🎆✨

Get 20% OFF on All Courses at Shiva Concept Solution click

Create Custom Plugin In WordPress

 The custom plugin is the best way to implement plugin functionality by code.


We can inherit all features of POST to create Custom Plugin


<?php

/*


plugin name:  MOVIES Plugin


description:-  ADD MOVIE


*/


function create_posttype() {

register_post_type( 'news',

// CPT Options

array(

  'labels' => array(

   'name' => __( 'news' ),

   'singular_name' => __( 'News' )

  ),

  'public' => true,

  'has_archive' => false,

  'rewrite' => array('slug' => 'news'),

 )

);

}

// Hooking up our function to theme setup

add_action( 'init', 'create_posttype' );


?>


How to call the plugin on code:-



<?php

/*Template Name: News*/

get_header();

query_posts(array(

   'post_type' => 'news'

)); ?>

<?php

while (have_posts()) : the_post(); ?>

<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

<p><?php the_excerpt(); ?></p>

<?php endwhile;

get_footer();

?>







إرسال تعليق

0 تعليقات