Showing posts with label Categorized list of WordPress functions. Show all posts
Showing posts with label Categorized list of WordPress functions. Show all posts

WordPress Post Insert Using Ajax Page Without Refresh

WordPress Post Insert Using Ajax Page Without Refresh

Hi, Today Discussed WordPress Post Insert Using Ajax Page Without Refresh WordPress more then plugin used and then today we discussed blog posting contact form what ever posting insert database ajax without refresh stored db.

WordPress Complete content form-process.php wordpress all file is path wp-content/theme/_____
that the find functions for function.php or other file function wp_insert_post() is not defined, because the WordPress core was not loaded.

WordPress Post Insert Using Ajax Page Without Refresh
WordPress Post Insert Using Ajax Page Without Refresh

add_action( 'admin_ajax_your_form_action', 'wpse_126886_ajax_handler' );

function wpse_126886_ajax_handler() {

    // maybe check some permissions here, depending on your app
    if ( ! current_user_can( 'edit_posts' ) )
        exit;

    $post_data = array();
    //handle your form data here by accessing $_POST

    $new_post_ID = wp_insert_post( $post_data );

    // send some information back to the javascipt handler
    $response = array(
        'status' => '200',
        'message' => 'OK',
        'new_post_ID' => $new_post_ID
    );

    // normally, the script expects a json respone
    header( 'Content-Type: application/json; charset=utf-8' );
    echo json_encode( $response );

    exit; // important
}
your_form_action slug is the >> trigger of your Call Back. you have to append this slug to your request parameter named form input name normally get or post method using jquery ajax  passing data parameter or form data using .serialize(). Input type hidden field passing parameter.

<input type="hidden" name="action" value="your_form_slug" />

and then file path wp-admin/admin-ajax.php


$.ajax({
    type: "POST",
    url: "http://www.mysite.co.uk/wp-admin/admin-ajax.php",
    data: dataString,
    error: function(jqXHR, textStatus, errorThrown){                                        
        console.error("The following error occured: " + textStatus, errorThrown);                                                       
    },
    success: function(data) {                                       
        console.log("Hooray, it worked!");                                                                  
    }                              
});






How to Create New Modules Wordpress without plugin

How to Create New Modules Wordpress without plugin

 Hi, Today Discussed WordPress Theme customized and admin and frontend How to Create new modules Wordpress without plugin created this task discussed today.  New modules without plugin Follows Briefly discussed.

How to Create New Modules Wordpress without plugin
How to Create New Modules Wordpress without plugin
public_html/wp-content/themes/themesname/admin

Create Staff.php

<?php

//
// 'staff' Custom Post Type
//

// Register the Post Type - staff
// http://codex.wordpress.org/Function_Reference/register_post_type
add_action('init', 'register_staff');

function register_staff() {
 
 $labels = array(
  'name' => _x('Staff', 'post type general name'),
  'singular_name' => _x('Staff', 'post type singular name'),
  'add_new' => _x('Add New', 'Staff'),
  'add_new_item' => __('Add New Staff Member'),
  'edit_item' => __('Edit Staff'),
  'new_item' => __('New Staff'),
  'view_item' => __('View Staff'),
  'search_items' => __('Search Staffs'),
  'not_found' =>  __('Nothing found'),
  'not_found_in_trash' => __('Nothing found in Trash'),
  'parent_item_colon' => ''
 );
 
 $args = array(
  'labels' => $labels,
  'public' => true,
  'publicly_queryable' => true,
  'show_ui' => true,
  'query_var' => true,
  'rewrite' => array(
            'slug' => 'staff',
            'with_front' => false
            ),
  'has_archive' => 'staff',
  'capability_type' => 'page',
  'hierarchical' => false,
  'menu_position' => 22,
  'supports' => array('custom-fields') // 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' , 'page-attributes' 
 ); 
 
 register_post_type( 'staff' , $args );
}

//
// Create Profile Images sizes
if ( function_exists( 'add_image_size' ) ) {
 add_image_size( 'staff-profile-small', 45, 45, true ); 
 add_image_size( 'staff-profile-thumb', 124, 124, true );
 add_image_size( 'staff-profile', 204, 204, true );
}

//
// Add Meta Boxes
// http://codex.wordpress.org/Function_Reference/add_meta_box
//

function tpx_staff_init(){
 add_meta_box("metabox_staff_staff", "Staff Details", "metabox_staff_staff", "staff", "normal","high");
 add_meta_box("metabox_staff_description", "Description", "metabox_staff_description", "staff", "normal","high");
 
}
add_action("admin_init", "tpx_staff_init");

function metabox_staff_staff() {
 global $post;
 ?> 
    <div class="custom_meta">
     <div class="photo_profile">
            <label>Photo</label>
         <div class="fileWrapper"><?php
   $photo_profileID = get_post_meta($post->ID, 'staff_file_photo_profile', true);
   $photoArray = wp_get_attachment_image_src( $photo_profileID, 'staff-profile-thumb', false);
   $photoSrc = $photoArray[0];
   if($photoSrc){
    echo '<a class="photo"><img src="' . $photoSrc . '" alt="staffimage" /></a>';
   } else {
    echo '<a class="photo"><span>Upload Photo</span></a>';
   }
   ?>
            <input type="file" name="staff_file_photo_profile" /></div>
        </div>
     <ul class="formfields">
         <li>
            <label>First Name</label>
            <?php tpx_meta_input_text('staff_name_first'); ?>
            </li>
         <li>
            <label>Surname</label>
            <?php tpx_meta_input_text('staff_name_last'); ?>
            </li>
         <li>
            <label>Position</label>
            <?php tpx_meta_input_text('staff_position'); ?>
            </li>
        </ul>
    </div>
 <?php 
}
function metabox_staff_description() {
 global $post;
 ?>
    <div class="custom_meta">
     <?php 
     $staff_description = get_post_meta($post->ID, 'staff_description', true);
  the_editor($staff_description, 'staff_description', 'title', false, 1); ?>
    </div>
<?php
}
add_action('save_post', 'save_staff_meta');

function save_staff_meta(){
 global $post, $initLoop;
 $prefix = "staff_";
 $initLoop = true;
 
 //Upload Headshot
 foreach($_FILES as $field => $file){
  if($field == 'staff_file_photo_profile'){
   $filename = $_POST['staff_name_first'] . ' ' . $_POST['staff_name_last'] . ' Profile Photo';
   tpx_save_attachement($file, $post->ID, $filename, 'staff_file_photo_profile');
   //Remove it from the array to avoid duplicates.
   unset($_FILES[$field]);
  }
 }
 
 //Normal Inputs
 foreach($_POST as $field => $value){
  $has_prefix = strstr($field, $prefix);
    
  if($has_prefix){
   //Capitalize Name
   if($field == 'staff_name_first') $value = ucwords($value);
   if($field == 'staff_name_last') $value = ucwords($value);
   
   if($value){
    update_post_meta($post->ID, $field, $value); // Save Value
   } else {
    delete_post_meta($post->ID, $field); // Remove it if its not there
   }
  } 
 }
}

add_filter('wp_insert_post_data', 'update_staff_title', 10, 2);

function update_staff_title($data, $postarr){
 if($data['post_type'] == 'staff' && $_POST['staff_name_first']){
  $new_title = $_POST['staff_name_first'] . ' ' . $_POST['staff_name_last'];
  $new_slug = strtolower($_POST['staff_name_first']) . '-' . strtolower($_POST['staff_name_last']);
  $new_slug = str_replace(' ', '', $new_slug);
  $data['post_title'] = ucwords($new_title);
  $data['post_name'] = $new_slug;
 }
 return $data;
}


//
// Sort Staff Menu
//

// add the admin options page
add_action('admin_menu', 'tpx_add_page_sort_staff');
function tpx_add_page_sort_staff() {
 add_submenu_page('edit.php?post_type=staff', 'Sort Staff', 'Sort Staff', 'edit_pages', 'tpx-staff-sort', 'tpx_options_staff_sort');
 add_submenu_page('edit.php?post_type=staff', 'Staff Overview', 'Overview', 'edit_pages', 'tpx-staff-overview', 'tpx_options_staff_overview');
}

//
// Sort Staff Page
//
function tpx_options_staff_sort() {
 $tpx_options_staff_sort = get_option( 'tpx_options_staff_sort');
?>
    <div class="wrap">
    <h2>Sort Staff</h2>
    <p>Click and Drag to sort the order of staff members</p>
    <div id="poststuff" class="tpx_options">
    <form action="options.php" method="post">
    <?php settings_fields('tpx_options_staff_sort'); ?>
    <ul class="tpx_sort_list">
     <?php
  $args = array(
   'post_type' => 'staff',
   'orderby' => 'menu_order',
   'order' => 'ASC',
   'posts_per_page' => -1
  );
  $staff_list = get_posts($args);
  foreach($staff_list as $staff){
   echo '<li class="draggable" id="' . $staff->ID . '">'. $staff->post_title . '<li>';
  }
  ?>
    </ul>
    <input name="tpx_options_staff_sort[staff_order]" type="hidden" value="" class="sort_value" />
    <input name="Submit" type="submit" value="<?php esc_attr_e('Publish'); ?>" class="button-primary" />
    </form></div></div>
<?php
}


//
// Staff Overview Page
//

function tpx_options_staff_overview() {
 $tpx_options_staff_overview = get_option( 'tpx_options_staff_overview');
?>
    <div class="wrap">
    <h2>Staff Overview</h2>
    <p>This text will appear on the front page of the website.</p>
    <div id="poststuff" class="tpx_options tpx_options_staff_overview">
    <form action="options.php" method="post" enctype="multipart/form-data" encoding="multipart/form-data"  accept-charset="utf-8">
    <?php settings_fields('tpx_options_staff_overview'); ?>
    <div class="feature_image ">
        <h3>Feature Image</h3>
        <?php 
        $attachment_ID = $tpx_options_staff_overview['feature_id'];
        tpx_attachment_uploader($attachment_ID, 'feature_attachment', 'photo-medium') 
  ?>
    </div>
    <div class="tiny_mce_wrapper"><?php the_editor($tpx_options_staff_overview['html'], 'tpx_options_staff_overview[html]', 'title', false, 1); ?></div>
    <input name="Submit" type="submit" value="<?php esc_attr_e('Publish'); ?>" class="button-primary" />
    </form></div></div>
<?php
}


// add the admin settings and such
add_action('admin_init', 'tpx_staff_admin_init');

function tpx_staff_admin_init(){
 register_setting( 'tpx_options_staff_sort', 'tpx_options_staff_sort', 'tpx_options_staff_sort_validate' );
 register_setting( 'tpx_options_staff_overview', 'tpx_options_staff_overview', 'tpx_options_staff_overview_validate' );
 add_settings_section('tpx_staff_main', 'Main Settings', 'tpx_staff_section_text', 'tpx_staff_section');
 add_filter( 'option_page_capability_tpx_options_staff_sort', 'tpx_options_staff_sort_capability' );
}
function tpx_options_staff_sort_capability( $capability ) {
 return 'edit_pages';
}

// validate our options
function tpx_options_staff_sort_validate($input) {
 $list_string = $input['staff_order'];
 if($list_string){
  $IDs = explode(',', $list_string);
  $count = 0;
  //print_r($staff_IDs);
  foreach($IDs as $ID){
   if($ID != ''){
    $staff_post = array();
    $staff_post['ID'] = $ID;
    $staff_post['menu_order'] = $count;
    wp_update_post($staff_post);
    $count++;
   } else {
    unset($ID);
   }
  }
  $newinput['staff_order'] = implode(',', $IDs);
 }
 return $newinput;
}

// validate our options
function tpx_options_staff_overview_validate($input) {
 $attachment_id = tpx_save_attachement($_FILES['feature_attachment'], 0, 0, 0, true);
 if($_POST['remove_feature_attachment']) $newinput['feature_id'] = '';
 //echo '$attachment_id - ' . $attachment_id;
 if($attachment_id) $newinput['feature_id'] = $attachment_id;
 $newinput['html'] = $input['html'];
 return $newinput;
}
?>
Create Function.php

Include('staff.php');
function menu_order_filter($menu) {
 $dev_menu = array(
   
  'edit.php?post_type=staff',  
  
  );
 array_splice($menu, 1, 0, $dev_menu);
 return array_unique($menu);
}

add_filter('custom_menu_order', create_function('', 'return true;'));
add_filter('menu_order', 'menu_order_filter');
Frontend
public_html/wp-content/themes/themename

Create sidebar-staff-profiles.php


<div class="staff_profiles">
<ul class="staff">
<?php
$args = array(
 'post_type' => 'staff',
 'posts_per_page' => -1,
 'orderby' => 'menu_order',
 'order' => 'ASC'
);
$staffs = get_posts($args);
foreach($staffs as $staff){
 $profile_id = get_post_meta($staff->ID, 'staff_file_photo_profile', true);
 $profile_img = tpx_attachment_src($profile_id, 'staff-profile-thumb');
 $fname = get_post_meta($staff->ID, 'staff_name_first', true);
 $lname = get_post_meta($staff->ID, 'staff_name_last', true);
 setup_postdata($staff);
?>
 <li>
     <?php
  if($profile_img){ 
  ?>
        <div class="row">

     <div class="small-12 large-4 columns headshot">
         <a href="<?php echo get_permalink($staff->ID) ?>">
<img src="<?php echo $profile_img ?>" alt="vinoth" class="photo"/>
</a><!---->
        </div>
        <?php } ?>
        <div class="small-12 large-8 columns details">
            <h4 class="name">
                <?php
                echo $fname . ' ' . $lname
                ?>
            </h4>
            <div class="excerpt">
                <?php
                $excerpt = substr(get_post_meta($staff->ID, 'staff_description', true), 0, 180) . '...';
                echo wpautop($excerpt);
                ?>
            </div>
            <div class="readmore"><a href="<?php echo get_permalink($staff->ID) ?>" class="button small">View <?php echo $fname ?>'s Profile</a></div>
        </div>
        </div>
    </li>
 
<?php  } ?>
</ul>
</div>
Create Single-staff.php

<?php get_header(); ?>
<section class="feature fixed bg-1">
 <div class="row">
        <div class="small-12 columns">
    <?php 
    $current_post_type = get_post_type_object(get_post_type($post->ID));
    ?>
         <ul class="breadcrumb">
       <li><a href="<?php echo get_permalink(6) ?>">About Us</a></li>
                <li><?php echo $post->post_title ?></li>
            </ul>
        </div>
    </div>
</section>
<section class="main">
    <div class="row">
     <?php 
  $profile_id = get_post_meta($post->ID, 'staff_file_photo_profile', true);
  $profile_img = tpx_attachment_src($profile_id, 'staff-profile');
  if($profile_img){
  ?>
     <div class="small-12 medium-4 large-3 columns mrg-1">
            <div class="headshot">
         <?php
   echo '<img src="' . $profile_img . '" alt="singlestaffphotos" class="photo" />';
   ?>
            </div>
        </div>
        <?php } // endif ?>
        <div class="small-12 medium-8 large-9 columns">
            <div class="page content">
                <?php if (have_posts()) : ?>
                    <?php while (have_posts()) : the_post(); ?>    
                        <article class="tiny_mce">
                        <?php echo wpautop(get_post_meta($post->ID, 'staff_description', true)) ?>
                        </article>
                    <?php endwhile; ?>
                <?php endif; ?>
                <div class="options"><a href="<?php echo get_permalink(6) ?>" class="button back">All Staff</a></div>
            </div>
        </div>
    </div>
</section>
<?php get_footer(); ?>

Categorized list of WordPress functions

Categorized list of WordPress functions that are commonly used when building, updating and maintaining templates.

Wordpress Basics Temlate Files and updates customized data and categorized listed and funcation loop functions and basics function and default functions follows.

Categorized list of WordPress functions
Categorized list of WordPress functions


Basic Template Files

File Name Description
style.css style sheet file
index.php   ome page file
header.php header content file
single.php single post page file
archive.php archive/category file
searchform.php search form file
search.php search content file
404.php error page file
comments.php  comments template file
footer.php footer content file
sidebar.php sidebar content file
page.php single page file
front-page.php latest posts or static page
tag.php display tags in archive format
category.php display categories in archive format


Header Functions

Function Description

<?php site_url(); ?>   root url for website

<?php wp_title(); ?> title of specific  post/page

<?php bloginfo('name'); ?> title of site

<?php bloginfo('description'); ?> site description

<?php get_stylesheet_directory(); ?> stylesheet folder location

<?php bloginfo('stylesheet_url'); ?> style.css file location

<?php bloginfo('pingback_url'); ?>  pingback url

<?php bloginfo('template_url'); ?> template folder path

<?php bloginfo('version'); ?> wordpress blog version

<?php bloginfo('atom_url'); ?> atom url

<?php bloginfo('rss2_url'); ?>  rss2 url

<?php bloginfo('url'); ?> root url for website

<?php bloginfo('html_type'); ?> html version

<?php bloginfo('charset'); ?> charset parameter

Navigation Menu

Default Navigation Menu

<?php wp_nav_menu(); ?>

Specific Navigation Menu

<?php wp_nav_menu( array('menu' => 'Project Nav' )); ?>

Category Based Navigation

<ul id="menu">

<li <?php if(is_home()) { ?> class="current-cat" <?php } ?>>

<a href="<?php bloginfo('home'); ?>">Home</a></li>

<?php wp_list_categories('title_li=&orderby=id');?>

</ul>

Page Based Navigation

<ul id="menu">

<li <?php if(is_home()) { ?> class="current-page-item" <?php } ?>>

<a href="<?php bloginfo('home'); ?>">Home</a></li>

<?php wp_list_pages('sort_column=menu_order&depth=1&title_li=');?>

</ul>

The Loop

Basic Loop

<?php if(have_posts()) { ?>

<?php while(have_posts()) { ?>

<?php the_post(); ?>

<?php // custom post content code for title, excerpt and featured image ?>

<?php } // end while ?>

<?php } // end if ?>

Template Functions

Function Description

<?php the_content(); ?> content of posts/pages

<?php if(have_posts()): ?> check if there are posts

<?php while(have_posts()): the_post(); ?> shows posts

<?php endwhile; ?> closes loop

<?php endif; ?> closes if

<?php get_header(); ?> header.php file contents

<?php get_sidebar(); ?> sidebar.php file contents

<?php get_footer(); ?> footer.php file contents

<?php the_time('m-d-y'); ?> the date is '08-18-07'

<?php comments_popup_link(); ?> link to comments of post

<?php the_title(); ?> title of post/page

<?php the_permalink(); ?> url of post/page

<?php the_category(); ?> category of post/page

<?php the_author(); ?> author of post/page

<?php the_ID(); ?> id of post/page

<?php edit_post_link(); ?> edit link of post/page

<?php wp_list_bookmarks(); ?> links from blogroll

<?php comments_template(); ?> comment.php file contents

<?php wp_list_pages(); ?> list all pages

<?php wp_list_categories(); ?> list all categories

<?php next_post_link('%link'); ?> url to next post

<?php previous_post_list('%link'); ?> url to previous post

<?php get_calendar(); ?> show post calendar

<?php wp_get_archives(); ?> list of archive urls

<?php posts_nav_link(); ?> next and previous post link

<?php rewind_posts(); ?> rewinds post for a second loop



Extra Functions

Function Description

/%postname%/ custom permalinks

<?php include(TEMPLATEPATH . '/x'); ?> include file from template folder

<?php the_search_query(); ?> value returned from search from

<?php _e('Message'); ?> return translated text from translate()

<?php wp_register(); ?> register link

<?php wp_loginout(); ?> login/logout link

<!--nextpage--> divide content into pages

<!--more--> cut off content and create link to full
post


<?php wp_meta(); ?> admin meta data

<?php timer_start(); ?> start page timer (header.php)

<?php timer_stop(1); ?> time to load the page (footer.php)

<?php echo get_num_queries(); ?> show queries executed to generate
page


Books Will Give More Knowledge - Purchase Books