Category Archives: Tasks

Insert and Display form Data Using JOIN in PHP

Create table ‘category’


CREATE TABLE category
(
c_id int AUTO_INCREMENT,
c_name varchar(255),
b_name varchar(255),
PRIMARY KEY (c_id)
);

Create table ‘product’


CREATE TABLE product
(
p_id INT(11) AUTO_INCREMENT,
c_id INT(11),    
p_name varchar(255),
p_price INT(11),
p_color varchar(255),
PRIMARY KEY (p_id)
);

Create “category.php”


<?PHP include 'connect.php'; ?>

<form method="post">
  Product Category
  <input type="text" name="category">
  </br>
  </br>
  Brand Name
  <input type="text" name="bname">
  </br>
  </br>
  <input type="submit" name="add_category" value="Add Category" />
</form>
<?php 
if(isset($_POST['add_category'])){
	$product_category = $_POST['category'];
	$brand_name = $_POST['bname'];
	$query2 = "INSERT INTO `category` (`c_name`,`b_name`) VALUES ('".$product_category."','".$brand_name."')";
	$result2 = mysql_query($query2) or die(mysql_error());
}

?>

Create “product.php”


<?php include 'connect.php'; ?>

<form method="post">
  Category Name
  <?php 
  $category = "SELECT c_name, c_id FROM category";
	$cat_result = mysql_query($category);
	?>
  <select name="category">
    <?php
	while($cat_row = mysql_fetch_array($cat_result)) { ?>
    <option value="<?php echo $cat_row['c_id']; ?>"><?php echo $cat_row['c_name']; ?></option>
    <?php }	?>
  </select>
  </br>
  </br>
  Product Name
  <input type="text" name="pname">
  </br>
  </br>
  Product Price
  <input type="text" name="price">
  </br>
  </br>
  Product Color
  <input type="checkbox" value="red" name="color[]" />
  Red,
  <input type="checkbox" value="blue" name="color[]" />
  Blue,
  <input type="checkbox" value="black" name="color[]" />
  Black</br>
  </br>
  <input type="submit" name="add_product" value="Add Product" />
</form>
<?php
if(isset($_POST['add_product'])){
	$c_id = $_POST['category'];
	$product_name = $_POST['pname'];
	$product_price = $_POST['price'];
	$product_color = implode(', ',$_POST['color']);
	
	$query1 = "INSERT INTO `product` (`c_id`,`p_name`,p_price,p_color) VALUES ('".$c_id."','".$product_name."','".$product_price."','".$product_color."')";
	$result1 = mysql_query($query1) or die(mysql_error());
}

?>

Create “result.php”


<?php
include 'connect.php';
$query = "SELECT product.*, category.* 
		  FROM product 
		  JOIN category 
		  ON product.c_id=category.c_id";	  

$result = mysql_query($query);

?>

<table border="1">
<tr>
  <td>Product ID</td>
  <td>Product Name</td>
  <td>Product Price</td>
  <td>Product Color</td>
  <td>Product Category ID</td>
  <td>Product Category </td>
  <td>Brand Name</td>
</tr>
<?php while($row = mysql_fetch_array($result)) { ?>
<tr>
  <td><?php echo $row['p_id']; ?></td>
  <td><?php echo $row['p_name']; ?></td>
  <td><?php echo $row['p_price']; ?></td>
  <td><?php echo $row['p_color']; ?></td>
  <td><?php echo $row['c_id']; ?></td>
  <td><?php echo $row['c_name']; ?></td>
  <td><?php echo $row['b_name']; ?></td>
</tr>
<?php } ?>

Create “connect.php”


<?php

$dbname = 'php';
$dbuser = 'root';
$dbpass = '';
$dbhost = 'localhost';

$con = mysql_connect($dbhost,$dbuser,$dbpass);
$db =  mysql_select_db($dbname, $con) or die(mysql_error());
 
?>

Advertisements

add user with ajax by submiting form

<form id="ajaxform" action="ajaxform" method="post">
	<p class="status"></p>
    <label for="uname">User name:</label>
    <input type="text" name="uname" id="uname" required>
    <label for="uemail">User email:</label>
    <input type="email" name="uemail"id="uemail" required>
    <input type="submit" value="Login" name="submit">
</form>

.js file

jQuery(document).ready(function($) {
// Perform AJAX login on form submit
	$('form#ajaxform').on('submit', function(e){
	$('form#ajaxform p.status').show().text(ajax_signup_object.loadingmessage);
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: ajax_signup_object.ajaxurl,
			data: {
			'action': 'signup', //calls wp_ajax_nopriv_ajaxsignup
			'uname': $('form#ajaxform #uname').val(),
			'uemail': $('form#ajaxform #uemail').val(),
			},
			success: function(data) {
			   
			}
		});
	e.preventDefault();
	});
});

functions.php

/* Enque script for ajax */
function prefix_ajax_signup() {
wp_register_script('ajax-signup-script', get_template_directory_uri() . '/js/deafult.js', array('jquery'));
wp_enqueue_script('ajax-signup-script');
wp_localize_script('ajax-signup-script', 'ajax_signup_object', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'loadingmessage' => __('User created successfully')
));
}
add_action('wp_enqueue_scripts', 'prefix_ajax_signup');
/* End Enque script for ajax */

/* Insert user using ajax */
function insert_user() {
$uname = $_POST['uname'];
$uemail = $_POST['uemail'];
$userdata = array(
'user_login' => $uname,
'user_email' => $uemail,
);
$user_id = wp_insert_user($userdata);
}
add_action( 'wp_ajax_signup', 'insert_user' );
add_action( 'wp_ajax_nopriv_signup', 'insert_user' );

Featured Post with meta in custom post type

/* custom post type trove */

function trove_custom_init() {
$labels = array(
'name' => __('Treasure Trove','themename'),
'singular_name' => __('trove','themename'),
'add_new' => __('Add New','themename'),
'add_new_item' => __('Add New Treasure Trove','themename'),
'edit_item' => __('Edit Treasure Trove','themename'),
'new_item' => __('New Treasure Trove','themename'),
'all_items' => __('All Treasure Trove','themename'),
'view_item' => __('View Treasure Trove','themename'),
'search_items' => __('Search Treasure Trove','themename'),
'not_found' => __('No Treasure Trove found','themename'),
'not_found_in_trash' => __('No Treasure Trove found in Trash','themename'),
'parent_item_colon' => "",
'menu_name' => __('Treasure Trove','themename')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'trove' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'menu_icon'   => 'dashicons-sos',
'supports' => array( 'title', 'editor','thumbnail','page-attributes'),             
);
register_post_type( 'trove', $args );

/*metabox*/
add_action( 'add_meta_boxes', 'meta_box_trove' );
function meta_box_trove()
{
add_meta_box( 'meta_box_trove_id', 'Treasure Trove info', 'trove_info', 'trove', 'normal', 'high' );
}



function trove_info( $post )
{
$values = get_post_custom( $post->ID );
$fragrances = isset( $values['fragrances'] ) ? esc_attr( $values['fragrances'][0] ) : "";
$house = isset( $values['house'] ) ? esc_attr( $values['house'][0] ) : "";
$size = isset( $values['size'] ) ? esc_attr( $values['size'][0] ) : "";
$stregenth = isset( $values['stregenth'] ) ? esc_attr( $values['stregenth'][0] ) : "";
$orn = isset( $values['orn'] ) ? esc_attr( $values['orn'][0] ) : "";
$price = isset( $values['price'] ) ? esc_attr( $values['price'][0] ) : "";

wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<input type="checkbox" name="featured_post" <?php if( get_post_meta($post->ID,'featured_post',true) == true ) { ?>checked="checked"<?php } ?> />  Set Featured Post.
<p>FRAGRANCE:</p>
<input type="text" name="fragrances" value="<?php echo esc_attr( $fragrances ); ?>" class="widefat" placeholder="fragrances" />
<p>HOUSE:</p>
<input type="text" name="house" value="<?php echo esc_attr( $house ); ?>" class="widefat" placeholder="house" />
<p>SIZE:</p>
<input type="text" name="size" value="<?php echo esc_attr( $size ); ?>" class="widefat" placeholder="size" />
<p>STRENGTH:</p>
<input type="text" name="stregenth" value="<?php echo esc_attr( $stregenth ); ?>" class="widefat" placeholder="stregenth" />
<p>Order Ref No:</p>
<input type="text" name="orn" value="<?php echo esc_attr( $orn ); ?>" class="widefat" placeholder="Order Ref No" />
<p>PRICE:</p>
<input type="text" name="price" value="<?php echo esc_attr( $price ); ?>" class="widefat" placeholder="price" />

<?php
}
/*save metabox*/
add_action( 'save_post', 'trove_meta_box_save' );
function trove_meta_box_save( $post_id )
{
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
if( isset( $_POST['featured_post'] ) ) 
{
	update_post_meta( $post_id, 'featured_post', true );
}
else
{
	update_post_meta( $post_id, 'featured_post', false );
}
if( isset( $_POST['fragrances'] ) ) update_post_meta( $post_id, 'fragrances', esc_attr( $_POST['fragrances'] ) );
if( isset( $_POST['house'] ) ) update_post_meta( $post_id, 'house', esc_attr( $_POST['house'] ) );
if( isset( $_POST['size'] ) ) update_post_meta( $post_id, 'size', esc_attr( $_POST['size'] ) );
if( isset( $_POST['orn'] ) ) update_post_meta( $post_id, 'orn', esc_attr( $_POST['orn'] ) );
if( isset( $_POST['stregenth'] ) ) update_post_meta( $post_id, 'stregenth', esc_attr( $_POST['stregenth'] ) );
if( isset( $_POST['price'] ) ) update_post_meta( $post_id, 'price', esc_attr( $_POST['price'] ) );
}
}
add_action( 'init', 'trove_custom_init' );

Display


$featured_post_args = array(
					'post_type' => 'trove',
					'posts_per_page' => -1,
					'meta_value' => 1,
					'meta_key' => 'featured_post'
		);
			
		$featured_post_query = new WP_Query($featured_post_args);
		
		while($featured_post_query->have_posts()):$featured_post_query->the_post();
			echo '<div class="advertisement">';
				?><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a><?php
			echo '</div>';
		endwhile;

custom pagination for custom post type

/** pagination **/
function fruit_pagination($pages = '', $range = 5)
{  
     $fruit_showitems = ($range * 2)+1;  
     global $paged;
     if(empty($paged)) $paged = 1;
     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     } echo '<div class="site-pagination">';  
     if(1 != $pages)
     {
		 
         echo "<ul>";
         if($paged > 2 && $paged > $range+1 && $fruit_showitems < $pages) echo "<li class='pagination-previous-all'><a href='".get_pagenum_link(1)."'><span class='sprite previous-all-icon'><<</span></a></li>";
         if($paged > 1 && $fruit_showitems < $pages) echo "<li class='pagination-previous'><a href='".get_pagenum_link($paged - 1)."'><span class='sprite previous-icon'><</span></a></li>";
         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $fruit_showitems ))
             {
                 echo ($paged == $i)? "<li class='active'><a href='#' >".$i."</a></li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
             }
         }
         if ($paged < $pages && $fruit_showitems < $pages) echo "<li class='pagination-next'><a href='".get_pagenum_link($paged + 1)."'><span class='sprite next-icon'>></span></a></li>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $fruit_showitems < $pages) echo "<li class='pagination-next-all'><a href='".get_pagenum_link($pages)."'><span class='sprite next-all-icon'>>></span></a></li>";
         echo "</ul>\n";
     }
	echo '</div>';
}
/** End pagination **/

For Display:

if (function_exists('fruit_pagination')) {
                        fruit_pagination($legal_ourteam->max_num_pages, '2');
                    }

Our team – custom post type

/***** Adding custom post type - Our Team *****/

function ourteam_custom_init() {
	$labels = array(
		'name' => __('Our Teams','legal'),
		'singular_name' => __('ourteam','legal'),
		'add_new' => __('Add New','legal'),
		'add_new_item' => __('Add New Our Team','legal'),
		'edit_item' => __('Edit Our Team','legal'),
		'new_item' => __('New Our Team','legal'),
		'all_items' => __('All Our Teams','legal'),
		'view_item' => __('View Our Teams','legal'),
		'search_items' => __('Search Our Team','legal'),
		'not_found' => __('No Our Teams found','legal'),
		'not_found_in_trash' => __('No Our Teams found in Trash','legal'),
		'parent_item_colon' => '',
		'menu_name' => __('Our Teams','legal')
	);
	$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true,
		'show_in_menu' => true,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'ourteam' ),
		'capability_type' => 'post',
		'has_archive' => true,
		'hierarchical' => false,
		'menu_position' => null,
		'supports' => array( 'title', 'editor' , 'thumbnail')
	);

register_post_type( 'ourteam', $args );
}
add_action( 'init', 'ourteam_custom_init' );
/***** Testimonial Title Change *****/

/*****  Custom Meta Box - our Team *****/
/*1*/
add_action( 'add_meta_boxes', 'meta_box_ourteam_details' );
function meta_box_ourteam_details()
{
add_meta_box( 'meta_box_details', 'Details', 'ourteam_details', 'ourteam', 'normal', 'high' );
	add_meta_box( 'meta_box_details_title', 'Open Hours', 'ourteam_hours', 'ourteam', 'normal', 'high' );
}
function ourteam_details( $post )
{
	$values = get_post_custom( $post->ID );
	$title_speciality = isset( $values['title_speciality'] ) ? esc_attr( $values['title_speciality'][0] ) : '';
	$speciality = isset( $values['speciality'] ) ? esc_attr( $values['speciality'][0] ) : '';
	
	$title_degrees = isset( $values['title_degrees'] ) ? esc_attr( $values['title_degrees'][0] ) : '';
	$degrees = isset( $values['degrees'] ) ? esc_attr( $values['degrees'][0] ) : '';
	
	$title_address = isset( $values['title_address'] ) ? esc_attr( $values['title_address'][0] ) : '';
	$address = isset( $values['address'] ) ? esc_attr( $values['address'][0] ) : '';
	
	wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
	?>
		<p>
		<?php _e('Change Title [ Speciality ]','legal'); ?>
		<input type="text" name="title_speciality" value="<?php echo esc_attr( $title_speciality ); ?>" class="widefat" placeholder="<?php _e('Speciality','legal'); ?>" />
		<?php _e('Speciality :- ','legal'); ?>
		<input type="text" name="speciality" value="<?php echo esc_attr( $speciality ); ?>" class="widefat" placeholder="<?php _e('Speciality','legal'); ?>" />
		</p><br>
		<p>
		<?php _e('Change Title [ Degrees ]','legal'); ?>
		<input type="text" name="title_degrees" value="<?php echo esc_attr( $title_degrees ); ?>" class="widefat" placeholder="<?php _e('Degrees','legal'); ?>" />
		<?php _e('Degrees :- ','legal'); ?>
		<input type="text" name="degrees" value="<?php echo esc_attr( $degrees ); ?>" class="widefat" placeholder="<?php _e('Degrees','legal'); ?>" />
		</p><br>
		<p>
		<?php _e('Change Title [ Address ]','legal'); ?>
		<input type="text" name="title_address" value="<?php echo esc_attr( $title_address ); ?>" class="widefat" placeholder="<?php _e('Address','legal'); ?>" />
		<?php _e('Address :- ','legal'); ?>
		<input type="text" name="address" value="<?php echo esc_attr( $address ); ?>" class="widefat" placeholder="<?php _e('Address','legal'); ?>" />
		</p><br>
	<?php
}
function ourteam_hours( $post )
{
	$values = get_post_custom( $post->ID );
	$hours_monday_friday = isset( $values['hours_monday_friday'] ) ? esc_attr( $values['hours_monday_friday'][0] ) : '';
	$title_monday_friday = isset( $values['title_monday_friday'] ) ? esc_attr( $values['title_monday_friday'][0] ) : '';
	$title_saturday = isset( $values['title_saturday'] ) ? esc_attr( $values['title_saturday'][0] ) : '';
	$hours_saturday = isset( $values['hours_saturday'] ) ? esc_attr( $values['hours_saturday'][0] ) : '';
	$title_sunday = isset( $values['title_sunday'] ) ? esc_attr( $values['title_sunday'][0] ) : '';
	$hours_sunday = isset( $values['hours_sunday'] ) ? esc_attr( $values['hours_sunday'][0] ) : '';
	wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
	?>
		<p>
		<?php _e('Change Title [ Monday-Friday ]','legal'); ?>
		<input type="time" name="title_monday_friday" value="<?php echo esc_attr( $title_monday_friday ); ?>" class="widefat" placeholder="<?php _e('Change Title','legal'); ?>" />	
		<?php _e('Monday-Friday Time:- ','legal'); ?>
		<input type="time" name="hours_monday_friday" value="<?php echo esc_attr( $hours_monday_friday ); ?>" class="widefat" placeholder="<?php _e('Monday-Friday Time','legal'); ?>" />
		</p>
		<br>
		<p>
		<?php _e('Change Title [ Saturday ]	','legal'); ?>
		<input type="time" name="title_saturday" value="<?php echo esc_attr( $title_saturday ); ?>" class="widefat" placeholder="<?php _e('Change Title','legal'); ?>" />
		<?php _e('Saturday Time:- ','legal'); ?>
		<input type="time" name="hours_saturday" value="<?php echo esc_attr( $hours_saturday ); ?>" class="widefat" placeholder="<?php _e('Saturday Time','legal'); ?>" />
		</p>
		<br>
		<p>
		<?php _e('Change Title [ Sunday ]','legal'); ?>
		<input type="time" name="title_sunday" value="<?php echo esc_attr( $title_sunday ); ?>" class="widefat" placeholder="<?php _e('Change Title','legal'); ?>" />
		<?php _e('Sunday Time:- ','legal'); ?>
		<input type="time" name="hours_sunday" value="<?php echo esc_attr( $hours_sunday ); ?>" class="widefat" placeholder="<?php _e('Sunday Time','legal'); ?>" />
		</p><br>
	<?php
}
add_action( 'save_post', 'ourteam_meta_box_save' );
function ourteam_meta_box_save( $post_id )
{
	if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
	if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
	
	if( isset( $_POST['title_speciality'] ) ) update_post_meta( $post_id, 'title_speciality', esc_attr( $_POST['title_speciality'] ) );
	if( isset( $_POST['speciality'] ) ) update_post_meta( $post_id, 'speciality', esc_attr( $_POST['speciality'] ) );
	
	if( isset( $_POST['title_degrees'] ) ) update_post_meta( $post_id, 'title_degrees', esc_attr( $_POST['title_degrees'] ) );
	if( isset( $_POST['degrees'] ) ) update_post_meta( $post_id, 'degrees', esc_attr( $_POST['degrees'] ) );
	
	if( isset( $_POST['title_address'] ) ) update_post_meta( $post_id, 'title_address', esc_attr( $_POST['title_address'] ) );
	if( isset( $_POST['address'] ) ) update_post_meta( $post_id, 'address', esc_attr( $_POST['address'] ) );
	
	if( isset( $_POST['title_monday_friday'] ) ) update_post_meta( $post_id, 'title_monday_friday', esc_attr( $_POST['title_monday_friday'] ) );
	if( isset( $_POST['hours_monday_friday'] ) ) update_post_meta( $post_id, 'hours_monday_friday', esc_attr( $_POST['hours_monday_friday'] ) );
	
	if( isset( $_POST['title_saturday'] ) ) update_post_meta( $post_id, 'title_saturday', esc_attr( $_POST['title_saturday'] ) );
	if( isset( $_POST['hours_saturday'] ) ) update_post_meta( $post_id, 'hours_saturday', esc_attr( $_POST['hours_saturday'] ) );
	
	if( isset( $_POST['title_sunday'] ) ) update_post_meta( $post_id, 'title_sunday', esc_attr( $_POST['title_sunday'] ) );
	if( isset( $_POST['hours_sunday'] ) ) update_post_meta( $post_id, 'hours_sunday', esc_attr( $_POST['hours_sunday'] ) );
}

Display

<div class="row">
                <?php
                $legal_ourteam_args = array(
                    'paged' => $paged,
                    'orderby' => 'post_date',
                    'order' => 'ASC',
                    'post_type' => 'ourteam',
                    'post_status' => 'publish'
                );
                $legal_ourteam = new WP_Query($legal_ourteam_args);
                while ($legal_ourteam->have_posts()) {
                    $legal_ourteam->the_post();
                    ?> 
                    <div class="col-md-6 col-sm-6 attorneys">
                        <div class="our-section-box">
                            <?php if (has_post_thumbnail()) { ?>
                                <div class="col-md-6 no-padding our-box-left">
                                    <div class="img-hover">
                                        <?php the_post_thumbnail('legal-ourteam-thumbnail-image', array('alt' => get_the_title(), 'class' => 'img-responsive')); ?>
                                    </div>
                                </div>
                            <?php } ?>
                            <div class="col-md-6 our-box-right">
                                <a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4></a>
                                <span><?php echo get_post_meta(get_the_ID(), 'speciality', true); ?></span>
                                <?php the_excerpt(); ?>

                            </div>
                        </div>
                    </div>
                <?php } ?>		
            </div>

Testimonial – custom post type

/***** Adding custom post type - Testimonial *****/
function testimonials_custom_init() {
	$labels = array(
		'name' => __('Testimonials','legal'),
		'singular_name' => __('testimonials','legal'),
		'add_new' => __('Add New','legal'),
		'add_new_item' => __('Add New Testimonial','legal'),
		'edit_item' => __('Edit Testimonial','legal'),
		'new_item' => __('New Testimonial','legal'),
		'all_items' => __('All Testimonials','legal'),
		'view_item' => __('View Testimonials','legal'),
		'search_items' => __('Search Testimonial','legal'),
		'not_found' => __('No testimonials found','legal'),
		'not_found_in_trash' => __('No testimonials found in Trash','legal'),
		'parent_item_colon' => '',
		'menu_name' => __('Testimonials','legal')
	);
	$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true,
		'show_in_menu' => true,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'testimonials' ),
		'capability_type' => 'post',
		'has_archive' => true,
		'hierarchical' => false,
		'menu_position' => null,
		'supports' => array( 'title', 'editor' , 'thumbnail')
	);

register_post_type( 'testimonials', $args );
}
add_action( 'init', 'testimonials_custom_init' );

Page Template:

<div class="col-md-12 home-image-section testimonial-home">
                        <div class="blur-effect">
                            <div class="container theme-container">
                                <?php echo '<h2>' . esc_attr($legal_options['bg-title']) . '</h2>'; ?>
                                <div class="testimonial-gallarey-container">
                                    <div class="row">
                                        <div id="owl-testimonial-demo" class="gallery-row">
                                            <?php
                                            $legal_partner_args = array(
                                                'order' => 'DESC',
                                                'post_type' => 'testimonials',
                                                'posts_per_page' => -1,
                                                'post_status' => 'publish',
                                               
                                            );
                                            $legal_query_partner = new WP_Query($legal_partner_args);
                                            ?>
                                            <?php while ($legal_query_partner->have_posts()) : $legal_query_partner->the_post(); ?>
                                                <?php if (has_post_thumbnail()) : ?>
                                                    <div class="item testimonial-item">
                                                        <div class="testimonial-person">
                                                            <?php the_post_thumbnail('legal-testimonials-thumbnail-image', array('alt' => get_the_title(), 'class' => 'img-responsive')); ?>
                                                        </div>
                                                        <span><?php the_title(); ?></span>
                                                        <?php the_content(); ?>
                                                    </div>
                                                <?php endif; ?>
                                            <?php endwhile; ?>
                                        </div>
                                    </div> 
                                </div>    
                            </div>
                        </div>
                    </div>

js

jQuery(document).ready(function () {
    jQuery("#owl-client-demo").owlCarousel({
        autoPlay: 3000, //Set AutoPlay to 3 seconds
        items: 5,
        itemsDesktop: [1199, 5],
        itemsDesktopSmall: [1024, 5],
        itemsTablet: [800, 4],
        itemsSmallTablet: [767, 3],
        itemsMobile: [380, 1]
    });
});

diffrent background image for every pages

functions.php

<?php
/* if image in child theme then use 'get_stylesheet_directory_uri'
   otherwise you can use 'get_templatet_directory_uri' */
   
function photoshoot_admin_scripts() {
wp_enqueue_script('custom',get_stylesheet_directory_uri() . '/js/media-uploader.js', array());
}
add_action( 'admin_enqueue_scripts', 'photoshoot_admin_scripts');

/* header image */
/*****  Custom Meta Box - Page *****/
add_action( 'add_meta_boxes', 'meta_box_portfolio' );
function meta_box_portfolio()
{
	add_meta_box( 'meta_box_header_id', 'Enter Portfolio info', 'portfolio_website_info', 'page', 'normal', 'high' );
}

function portfolio_website_info( $post )
{
$values = get_post_custom( $post->ID );
$header_text = isset( $values['header_text'] ) ? esc_attr( $values['header_text'][0] ) : '';
$header_image = isset( $values['header_image'] ) ? esc_attr( $values['header_image'][0] ) : '';
 
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>

<p>Header Text</p>
<input type="text" name="header_text" value="<?php echo esc_attr( $header_text ); ?>" class="widefat" placeholder="Header Text" />
<p>Header Image</p>
<input id=""  type="text" class=" mytheme_media_url upload" name="header_image" value="<?php echo esc_attr( $header_image ); ?>" placeholder="No file chosen"  />
<?php if(!empty($instance['image'])) { ?>
<img src="<?php echo $instance['image']; ?>"  />
<?php } ?>
<input id="mytheme_image_uploader"  class="button mytheme_media_upload" type="button" value="Upload" />
<?php
}
add_action( 'save_post', 'portfolio_meta_box_save' );
function portfolio_meta_box_save( $post_id )
{
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
if( isset( $_POST['header_text'] ) ) update_post_meta( $post_id, 'header_text', esc_attr( $_POST['header_text'] ) );
if( isset( $_POST['header_image'] ) ) update_post_meta( $post_id, 'header_image', esc_attr( $_POST['header_image'] ) );
}
/*** end ***/

/* custom header background */
add_action('wp_head', 'legal_home_bgimg');
function legal_home_bgimg() {
   
	$header_image = get_post_meta( get_the_ID(), 'header_image', true );
	$header_image_default = get_stylesheet_directory_uri()."/images/header-bg.jpg";
	if(!empty($header_image)){
		$header_image_style = "<style> 
									.my-page-header-bg 
										{ 
											background :url('" . $header_image . "');
											height:370px;
											margin-top: -16px; 
										} 
							  </style>";
	} else {
		$header_image_style = "<style> 
									.my-page-header-bg 
										{ 
											background :url('".$header_image_default."');
											height:370px;
											margin-top: -16px; 
										} 
							  </style>"; 
	}
    echo $header_image_style;
}
/* end */
?>

Display

<div class="entry-header my-page-header-bg">
	<div class="container">
    	<?php $header_text = get_post_meta( get_the_ID(), 'header_text', true ); ?>
   		<h1 itemprop="headline" class="entry-title"><?php echo $header_text ?></h1>
    </div>
</div>
%d bloggers like this: