Sunday, 3 March 2019

WordPress custom theme development Tutorial


first downlaod wordpress from wordpress website 
then extarct and copy this kit and paste on xammp or any local server example with xampp htdocs folder 
or wamp www folder then open browser  and type localhost with  back slash with project name open wodpress configure before  create a data base and use this databse file and step by step configure and log in dashboard simple open a default theme so i want a create theme and use 

first html template copy and paste in wordpress to wp content then theme folder 
create style.css file and index.php file and header and footer separate and screenshot.png i template 
.Go to dashboard and appearance and theme option and show on this template in theme and select the theme 

dynamically call-
get_template_directory_uri()/source path;
for secure- esc_uri(get_template_directory_uri());


header part dynamic

<!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js no-svg">


<meta charset="<?php bloginfo( 'charset' ); ?>">

for site title - <?php bloginfo('name') ?>

<title><?php bloginfo('name') ?> | <?php bloginfo('description') ?></title>

another process change title tag - 

write on functions.php 
add_theme_support('title-tag') and first use the function before end the head tag wp_head();




dynamic css and js

css dynamic for wp_enquee_style($handle,$src,$ver,$media)

and for js wp_enquee_script()
  
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); $Infooter if delacare true so this is footer otherwise called header when i declare false and blank


1st create a function in functions.php

example with-

function joy_enquee_scripts()

{
wp_enqueue_style($handle,$src,$deps,$ver,$media) //five parameter are not necessary 1st theree parameter is enough 

$handle - this means wich file called id and file name this are uniq
$src - src function get_template_directory after path uri with concatenation 
$deps -dependancy means arry this are optioanl 
$ver - this are version 
$media are optional
}


function flipmart_enqueue_scripts()

{
// Bootstrap Core CSS
    
wp_enqueue_style( 'bootstrap', get_template_directory_uri().'/assets/css/bootstrap.min.css', array(), 
'3.2.0' );

wp_enqueue_style( 'main', get_template_directory_uri().'/assets/css/main.css', array(), 
'3.2.0' );

wp_enqueue_style( 'font-awesome', get_template_directory_uri().'/assets/css/font-awesome.css', array(),'3.2.0' );

after get main style sheet which file manualy create when create theme -->

main css file called theme style sheet
wp_enqueue_style('style',get_stylesheet_uri());



 dynamically called js file 

 wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );

 $handle - id or file name 
 $src= file source 
 $deps= dependency or array declare with out value just declare
 $ver = verson in file name 
  $in_footer = default false .false means - call data in header and true means call from footer 


  for latest jquery from wordpress  automatically added 
  wp_enqueue_script('jquery');

 script call 

wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );

example-
  wp_enqueue_script( 'bootstrap.min', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array(), '3.2.0', true );

if when i declare false so script will show in header show bye view source page 
}
add_action('wp_enqueue_scripts','flipmart_enqueue_scripts');



 create navigation menu 
in declare in functions page ->

function register_my_menus() {
    register_nav_menus(
        array(
            'header-menu' => 'Header Menu',
        )
    );
}
add_action( 'init', 'register_my_menus' );


then declare call the funtion in ui page 

in menu class 

<?php
wp_nav_menu(array(
    'menu' => 'Header Menu',
    'container' => 'ul',
    'menu_class' => 'nav nav-tabs',
    'echo' => true,
    'fallback_cb' => 'wp_page_menu',
    'items_wrap' => '<ul data-in="fadeInDown" data-out="fadeOutUp" id="%1$s" class="%2$s">%3$s</ul>',
    'item_spacing' => 'preserve',
    'depth' => 3,
));
 ?>





/* create post */
1st declare functions upper page 
add_theme_support('post-thumbnails');


functions.page how to create won post  page 
example with a gallery post  --->

add_action('init', 'codex_slider_init'); //Define function --> this code will write on after ending function name as your choice 
function codex_slider_init() //Define function name
{
    $labels = array(
        'name' => _x('sliders', 'post type general name', 'your-plugin-textdomain'), //Edit
        'singular_name' => _x('slider', 'post type singular name', 'your-plugin-textdomain'), //Edit
        'add_new' => 'Add New slider', //Edit
        'all_items' => 'All sliders', //Edit
        'edit_item' => 'Edit slider', //Edit
    );
    $args = array(
        'labels' => $labels,
        'description' => __('Description.', 'your-plugin-textdomain'),
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'slider'), //URL Friendly
        'capability_type' => 'post', //Post or Page
        'has_archive' => true,
        'menu_position' => 5,
        'supports' => array('title', 'editor', 'thumbnail'),
        'menu_icon' => 'dashicons-admin-site' //Icon or Image Location
    );
    register_post_type('slider', $args); //URL Friendly
}
add_action('init', 'codex_slider_init'); //Define function


then how to call the post in ui template using loop

1st foreach loop delaration -->

<?php
$query_posts = new WP_Query(array(
  'post_type' => 'gallary', //Post slug name here
  'post_status' => 'publish',
  'orderby' => 'date',
  'order' => 'ASC',
  'posts_per_page' => -1 // -1 = display all
));
if($query_posts->have_posts()): //Check if posts available
  $get_posts = $query_posts->get_posts();?>
    <div class="container">
  <?php  foreach ($get_posts as $post):?>
      <div class="col-md-4">
        <figure class="effect-marley">
          <img src="<?php echo get_the_post_thumbnail_url($post->ID);?>" alt="" class="img-responsive"/>
          <figcaption>
            <h4><?php echo get_the_title($post); ?></h4>
            <p><?php the_content(); ?></p>       
          </figcaption>     
        </figure>
      </div>
  <?php endforeach;?>
    </div>
  <?php endif;?>
  </div>


while loop declaration (using default post without own create cpt post page)-->


<?php
 while (have_posts()): the_post();

    ?>
<div class="blog-post  wow fadeInUp">
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<?php the_content() ?>
</div>
 <?php endwhile;?>


 create ui template in page.php this page are automatically create a page 

 create ui template in single.php are own default post will be fetch


 how to post data and fetch using acf pro plugin 

 1st install and active then 

 create page name or post name then identify when i will implement 
 and create field feth data using the_field('slug name') and echo get_field('slug name');

 for loop used repeater field then collect repeater slug name  eaxmple - in slider image 

 $slider= get_field('slider slug name');

 then i will chek array and not empty likely - 

 if(arrary($variable name ) && !empty($variablename)):

 foreach($variable name as $value):

 <h1>echo $variablename['slug name '];

 if index page acf data are not show when go to the settings-reading and Your homepage displays
 and another ways is declare global $post in functions.php avobe 

1 comment: