PHP Developer

Showing posts with label custom post. Show all posts
Showing posts with label custom post. Show all posts

Thursday, 16 November 2017

Create custom carousel slider with custom post type using Slick slider library

Create custom carousel slider with custom post type using Slick slider library



<!------- Create Custom post Type Crousel Slider Using Slick Slider ---------->
<?php
$team_slider_html = '';

$args = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'posts_per_page' => 10,
);
$query = new WP_Query( $args );
$team_slider_html .= '<section class="center slider hometeam_slider">';
while ( $query->have_posts() ) : $query->the_post();
    if (has_post_thumbnail( get_the_ID() ) ){
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
        $featured_image = $image[0];
    }else{
        $featured_image = site_url().'/wp-content/uploads/2017/10/report-covers.png';
    }
    $team_slider_html .= '<div class="single_team_slide"><div class="single_slide_inner">';
    $team_slider_html .= '<div class="team_member_image"><img src="'.$featured_image.'"></div>';
    $team_slider_html .= '<div class="team_member_excerpt">'.get_the_excerpt().'</div>';
    $team_slider_html .= '<div class="team_member_name">'.get_the_title().'</div>';
    $team_slider_html .= '<div class="team_member_designation">'.get_post_meta( get_the_ID(), '_position', true ).'</div>';
    $team_slider_html .= '</div></div>';
endwhile;
$team_slider_html .= '</section>';

echo $team_slider_html;
?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick-theme.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.js'></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery(document).on('ready', function() {
    jQuery(".center").slick({
        dots: true,
        infinite: true,
        centerMode: true,
        autoplay: true,
        arrows: true,
        slidesToShow: 3,
        slidesToScroll: 1
    });
});
</script>


Thursday, 25 August 2016

How wp_editor and date picker use in Posts Meta Fields(Custom Fields)

How wp_editor and date picker use in Posts Meta Fields(Custom Fields) :


<?php
/*----------- Create Metabox in Custom Post vacancies Code Start ---------------*/

function myplugin_add_custom_box() {
    $screens = array( 'vacancies' );  // Post Type
    foreach ( $screens as $screen ) {
        add_meta_box(
            'myplugin_sectionid',
            __( 'Other Detail', 'myplugin_textdomain' ),
            'myplugin_inner_custom_box',
            $screen
        );
    }
}
add_action( 'add_meta_boxes', 'myplugin_add_custom_box' );

function myplugin_inner_custom_box( $post ) {
  wp_nonce_field( 'myplugin_inner_custom_box', 'myplugin_inner_custom_box_nonce' );
 
  $job_title = get_post_meta( $post->ID, 'job_title', true );
  $opening_date = get_post_meta( $post->ID, 'opening_date', true );
  $last_date = get_post_meta( $post->ID, 'last_date', true );
 
  $pay_scale_desc = get_post_meta( $post->ID, 'pay_scale_desc', false );
 
  ?>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
  <script>
  $( function() {
    $( ".datepicker" ).datepicker();
  } );
  </script>
  <?php
  echo '<table>';
  echo '<tr>';
  echo '<td><label for="myplugin_new_field">';
       _e( "Job Title", 'myplugin_textdomain' );
  echo '</label> </td>';
  echo '<td><input type="text" id="job_title" name="job_title" value="' . esc_attr( $job_title ) . '" size="25" /></td>';
  echo '</tr><tr>';
  echo '<td><label for="myplugin_new_field">';
       _e( "Opening Date", 'myplugin_textdomain' );
  echo '</label> </td>';
  echo '<td><input type="text" class="datepicker" id="opening_date" name="opening_date" value="' . esc_attr( $opening_date ) . '" size="25" /></td>';
  echo '</tr><tr>';
  echo '<td><label for="myplugin_new_field">';
       _e( "Closing Date", 'myplugin_textdomain' );
  echo '</label> </td>';
  echo '<td><input type="text" class="datepicker" id="last_date" name="last_date" value="' . esc_attr( $last_date ) . '" size="25" /></td>';
  echo '</tr>';
  echo '<tr>';
  echo '<td><label for="myplugin_new_field">';
       _e( "Pay Scale Description", 'myplugin_textdomain' );
  echo '</label> </td>';
  echo '<td>';
  wp_editor( $pay_scale_desc[0], 'pay_scale_desc' );
  echo '</td>';
  echo '</tr>';
  echo '</table>';
}
function myplugin_save_postdata( $post_id ) {
  if ( ! isset( $_POST['myplugin_inner_custom_box_nonce'] ) )
    return $post_id;
  $nonce = $_POST['myplugin_inner_custom_box_nonce'];
  if ( ! wp_verify_nonce( $nonce, 'myplugin_inner_custom_box' ) )
      return $post_id;
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
      return $post_id;
  if ( 'page' == $_POST['post_type'] ) {
    if ( ! current_user_can( 'edit_page', $post_id ) )
        return $post_id;
  } else {
    if ( ! current_user_can( 'edit_post', $post_id ) )
        return $post_id;
  }
 
  $job_title = sanitize_text_field( $_POST['job_title'] );
  $opening_date = sanitize_text_field( $_POST['opening_date'] );
  $last_date = sanitize_text_field( $_POST['last_date'] );
 
  update_post_meta( $post_id, 'job_title', $job_title );
  update_post_meta( $post_id, 'opening_date', $opening_date );
  update_post_meta( $post_id, 'last_date', $last_date );
 
  if ( isset ( $_POST['pay_scale_desc'] ) ) {
    update_post_meta( $post_id, 'pay_scale_desc', $_POST['pay_scale_desc'] );
  }
}
add_action( 'save_post', 'myplugin_save_postdata' );

/*----------- Create Metabox in Custom Post vacancies Code END ---------------*/
?>

 =========================================================

And How wp_editor value get in Frontend in same Format :


<?php 
$pay_scale_desc = get_post_meta( $post->ID, 'pay_scale_desc', false );
echo "<pre>";
print_r($pay_scale_desc[0]);
echo "</pre>";
?>

Thursday, 9 April 2015

Create Custom Post with all options like Category, Featured image, Excerpt etc. in wordpress

Create Custom Post with all options like Category, Featured image, Excerpt etc. in WordPress


Copy and Paste this code in function.php file. This function create a post of type "servicerequest".

<?php
/*------------------------ Create Custom Post servicerequest START -------------------------------*/

function service_request() {
    $labels = array(
    'name' => 'Services',
    'singular_name' => 'Services',
    'add_new' => 'Add New Services',
    'add_new_item' => 'Add New Services',
    'edit_item' => 'Edit Services',
    'new_item' => 'New Services',
    'all_items' => 'All Services',
    'view_item' => 'View Services',
    'search_items' => 'Search Services',
    'not_found' => 'No Services Found',
    'not_found_in_trash' => 'No Services found in Trash',
    'parent_item_colon' => '',
    'menu_name' => 'Request Services',
    );
    //register_post_type is use to create new post type.
    //"servicerequest" is a post type

    register_post_type( 'servicerequest', array(
        'labels' => $labels,
        'has_archive' => true,
        'public' => true,
        'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'author', 'revisions', 'post-formats' ),
        'exclude_from_search' => false,
        'capability_type' => 'post',
    )
    );  
}
add_action( 'init', 'service_request' );

Saturday, 25 October 2014

How To Create Custom Post With Meta Boxes Plugin In WordPress

How To Create Custom Post With Meta Boxes Plugin In WordPress


<?php
/*
Plugin Name: Recipe Meta Box
Plugin URI:
Description: With the help of this plugin you can add recipe detail where add post or create recipe for your project.
Author: Sunil Sharma
Author URI: https://plus.google.com/u/0/115833273431242118637
*/

$paths = ABSPATH;
include_once $paths.'wp-load.php';

/*--------------------------------Create Custom Post Code Start---------------------------------------*/
function recipe_init() {
    $args = array(
      'public' => true,
      'label'  => 'Recipe Code',
      'supports'  => array( 'title', 'editor', 'thumbnail' )
    );   
    register_post_type( 'recipe', $args );   
}
add_action( 'init', 'recipe_init' );
/*--------------------------------Create Custom Post Code End---------------------------------------*/