WordPress With Angular

  • Home
  • /
  • WordPress With Angular

Hello Everyone today we are going to do install slider in wordpress and make it dynamic. After that we are going to get those slider data’s via wordpress rest api and then we are going to make same slider in angular and ionic as well.

Now we are going to install wordpress in our local pc or any server. After installing the wordpress we are going to create a new theme in wordpress.

For installing the wordpress please check How To Install WordPress

For creating a new theme in wordpress please check How To Create Theme In wordpress

We are going to add the bootstrap slider in our theme. For that we need to add bootstarp css and js in to our theme. open the header.php file of your theme and paste the following line of code.

<link rel="stylesheet" href="">
<script src=""></script>

Now We are going to add code for the bootstrap slider. For this you need to create a template in your theme folder. For example i am going to create the file named as template-slider.php. In this template we are going to paste the following code.

/* Template Name: Slider Demo */ 
<?php //add your template code here ?>

Now also we need to add code of while loop of wordpress to get the data of the page. For doing this please add the following 

<div id="myCarousel" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1"></li>
    <li data-target="#myCarousel" data-slide-to="2"></li>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
      <img src="la.jpg" alt="Los Angeles">

    <div class="item">
      <img src="chicago.jpg" alt="Chicago">

    <div class="item">
      <img src="ny.jpg" alt="New York">

  <!-- Left and right controls -->
  <a class="left carousel-control" href="#myCarousel" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
    <span class="sr-only">Previous</span>
  <a class="right carousel-control" href="#myCarousel" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
    <span class="sr-only">Next</span>

Please change the image link in the above example

For making this carousal dynamic we need to add custom post type in wordpress backend. For adding new post type you can use any plugins of wordpress. I am going to use online post type generator for wordpress. I am going to name this post type as sliders. You can use any other name that you want to use. Use the following code in functions.php file of your theme

// Register Custom Post Type
function custom_post_type_slider() {

	$labels = array(
		'name'                  => _x( 'Sliders', 'Post Type General Name', 'text_domain' ),
		'singular_name'         => _x( 'Slider', 'Post Type Singular Name', 'text_domain' ),
		'menu_name'             => __( 'Sliders', 'text_domain' ),
		'name_admin_bar'        => __( 'Sliders', 'text_domain' ),
		'archives'              => __( 'Item Archives', 'text_domain' ),
		'attributes'            => __( 'Item Attributes', 'text_domain' ),
		'parent_item_colon'     => __( 'Parent Item:', 'text_domain' ),
		'all_items'             => __( 'All Sliders', 'text_domain' ),
		'add_new_item'          => __( 'Add New Slider', 'text_domain' ),
		'add_new'               => __( 'Add New Slider', 'text_domain' ),
		'new_item'              => __( 'New Slider', 'text_domain' ),
		'edit_item'             => __( 'Edit Slider', 'text_domain' ),
		'update_item'           => __( 'Update Slider', 'text_domain' ),
		'view_item'             => __( 'View Slider', 'text_domain' ),
		'view_items'            => __( 'View Sliders', 'text_domain' ),
		'search_items'          => __( 'Search Slider', 'text_domain' ),
		'not_found'             => __( 'Not found', 'text_domain' ),
		'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
		'featured_image'        => __( 'Featured Image', 'text_domain' ),
		'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
		'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
		'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
		'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
		'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
		'items_list'            => __( 'Items list', 'text_domain' ),
		'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
		'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
	$args = array(
		'label'                 => __( 'Slider', 'text_domain' ),
		'description'           => __( 'This post type will make the slider dynamic', 'text_domain' ),
		'labels'                => $labels,
		'supports'              => array( 'title', 'editor', 'thumbnail' ),
		'taxonomies'            => array( 'category', 'post_tag' ),
		'hierarchical'          => false,
		'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,
		'exclude_from_search'   => false,
		'publicly_queryable'    => true,
		'capability_type'       => 'page',
		'show_in_rest'          => true,
	register_post_type( 'post_type_slider', $args );

add_action( 'init', 'custom_post_type_slider', 0 );

Leave a comment