Pages

Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Sunday, April 12, 2015

Wordpress custom pages creation?

functions.php
<?php
register_post_type('contact', array('label' => 'contact','description' => '',
'public' => true, 'publicly_queryable' =>true, 'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post',
 'hierarchical' => true, 'rewrite' => array( 'slug' => 'contact', 'with_front' => false),'query_var' => true,'exclude_from_search' => false,
 'has_archive' => true,'supports' => array('title','editor','thumbnail','author','comments'),'labels' => array (
  'name' => 'List of Contacts',
  'singular_name' => 'contact',
  'menu_name' => 'Contacts',
  //'add_new' => 'Add Users Conference',
  //'add_new_item' => 'Add Users Conference',
  'edit' => 'Edit Contacts',
  'edit_item' => 'Edit Contacts',
  'new_item' => 'New Contacts',
  'view' => 'View Contacts',
  'view_item' => 'View Contacts',
  'search_items' => 'Search Contacts',
  'not_found' => 'No Users Found',
  'not_found_in_trash' => 'No Users Found in trash',
  'parent' => 'Contacts',
),) );
/* Meta box for userconfrence*/
add_action("admin_init", "contact_enquerires_meta_box"); 
    function contact_enquerires_meta_box(){ 
        add_meta_box("contact-meta", "Contact Details", "contact_enquerires_meta_options", "contact", "normal", "high"); 
    } 
    function contact_enquerires_meta_options(){ 
            global $post;
            if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; 
            $custom2 = get_post_custom($post->ID);
            $cname = $custom2["contact_name"][0];
             $cemail = $custom2["contact_email"][0];
             $cphone = $custom2["contact_phone"][0];
             $message = $custom2["contact_comments"][0];

          
          
    ?>
 
<div class="my_custom">
<style>
.register_formadmin div.field {
   
    position:relative;
    width:100%;
}
#userconfregadmin label{
display:block;
font-weight:bold;
width:140px;
margin-top:7px;

}
</style>
    <div  class="register_formadmin" id="userconfregadmin">
    <table>
                <tr>
                    <td>Name: </td>
                    <td><input type="text" name="cname" id="cname" value="<?php echo $cname; ?>"></td>
                </tr>
                <tr>
                    <td>Email: </td>
                    <td><input type="text" name="cemail" id="cemail" value="<?php echo $cemail; ?>"></td>
                </tr>
                <tr>
                    <td>Phone: </td>
                    <td><input type="text" name="cphone" id="cphone" value="<?php echo $cphone; ?>"></td>
                </tr>
                <tr>
                    <td>Message: </td>
                    <td><textarea name="message" id="message"><?php echo $message; ?></textarea></td>
                </tr>
               
            </table>
            <input type="hidden" name="trash_metafield" id="trash_metafield" value="<?php echo wp_create_nonce(plugin_basename(__FILE__).$post->ID); ?>" />
    </div>
   
    <?php
    }
    add_action('save_post', 'save_contacts');
    function save_contacts(){ 
        global $post; 
        if (!wp_verify_nonce($_POST['trash_metafield'], plugin_basename(__FILE__).$post->ID)) {
    return $post->ID;
  }   

        if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
            return $post_id; 
        } else { 
         update_post_meta($post->ID, "contact_name", $_POST["cname"]);
          update_post_meta($post->ID, "contact_email", $_POST["cemail"]);
          update_post_meta($post->ID, "contact_phone", $_POST["cphone"]);
          update_post_meta($post->ID, "contact_comments", $_POST["message"]);


        } 
    }
   
add_filter( 'manage_edit-contact_columns', 'my_edit_contact_columns' ) ;

function my_edit_contact_columns( $columns ) {

    $columns = array(           
        'title' => __( 'Email' ),
        'ContactName' => __( 'Contact Name' ),
        'Phone' => __( 'Phone' ),
        'date' => __( 'Date' )
    );

return $columns;
}



add_action( 'manage_contact_posts_custom_column', 'my_manage_contact_columns', 10, 1 );

function my_manage_contact_columns( $column, $post_id ) {
    global $post;

    switch( $column ) {

        /* If displaying the 'duration' column. */
        case 'ContactName' :

            /* Get the post meta. */
            $userstatus = get_post_meta($post->ID, 'contact_name', true );

            /* If no duration is found, output a default message. */
           
            echo (  ucwords($userstatus));

            break;
        case 'Phone' :

            /* Get the post meta. */
            $userstatus = get_post_meta($post->ID, 'contact_phone', true );

            /* If no duration is found, output a default message. */
           
            echo (  ucwords($userstatus));

            break;


        /* Just break out of the switch statement for everything else. */
        default :
            break;
    }
}

/* add post price */
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page(){
//add_menu_page( 'custom menu title', 'Premium Posts Settings', '', 'premium_post', 'my_custom_premium_post_menu_page', get_template_directory_uri().'/images/admint_settings.png');
add_submenu_page( 'options-general.php', 'My Settings', 'My Settings', 'manage_options', 'premium_post', 'my_custom_premium_post_menu_page');
}

function my_custom_premium_post_menu_page(){
include TEMPLATEPATH .'/price-settings.php';
}
/* end post price */ 
?>

page-contact.php:
<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

get_header();
if(isset($_POST['submit'])){
$cname=$_POST['cname'];
$cemail=$_POST['cemail'];
$cphone=$_POST['cphone'];
$message=$_POST['message'];
$post_title = $cemail;
 global  $wpdb;
/* Checking email exists or not */
 $query = $wpdb->prepare(
      "SELECT ID FROM $wpdb->posts
        WHERE post_title = '$post_title'
        AND post_type = 'contact'
       AND post_status='Publish'"
   );
$wpdb->query( $query );
if ( $wpdb->num_rows ) {
} else{
/*inserting values in to database */
$post_information = array(
'post_title' => $post_title,
'post_type' => 'contact',
'post_status' => 'Publish'
        );
$post_id = wp_insert_post( $post_information, $wp_error );
update_post_meta($post_id,'contact_name',$cname);
update_post_meta($post_id,'contact_email',$cemail);
update_post_meta($post_id,'contact_phone',$cphone);
update_post_meta($post_id,'contact_comments',$message);
echo'<script> window.location="http://www.google.com";</script>';
}
}
?>
<script src="<?php echo get_template_directory_uri()?>/js/jquery.min.js"></script>
<script src="<?php echo get_template_directory_uri()?>/js/jquery.validate.js"></script>
   
 <script type='text/javascript'>
 var $$_ = jQuery;
$$_(document).ready(function(){
 var regxalpha = /^[A-Za-z .-0"']+$/;
var regxalphacaptch = /^[A-Za-z]+$/;
 var regxalpha1 = /^[A-Za-z _.-123456789"'@&-/]+$/;
 var regnum=/^[-0123456789"'-/]+$/;
 var regemail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
$$_.validator.addMethod("vendornamevalidate", function(value, element) {
                    var cname = jQuery('#cname').val();
                    if (regxalpha.test(cname)) {
                        return cname;
                    }
                }, 'Invalid Name');
              
$$_.validator.addMethod("emailvalidate", function(value, element) {
                    var cemail = jQuery('#cemail').val();
                    if (regemail.test(cemail)) {
                        return cemail;
                    }
                }, 'Invalid Email');
              
$$_.validator.addMethod("vendorphone", function(value, element) {
                    var cphone = jQuery('#cphone').val();
                    if (regnum.test(cphone)) {
                        return cphone;
                    }
                }, 'Invalid Phone');               

$$_('#contact_form').validate({// initialize the plugin
                
                    rules: {
                         cname: {
                            required: true,
                            vendornamevalidate: true

                        },  
                      
                          
                      
                        cemail: {
                            required: true,
                            email: true,
                            emailvalidate: true
                          
                        },  
                        cphone: {
                         required: true,
                         number: true,
                         vendorphone: true
                        },
                  
                    },
                    messages: {
                        cname: {
                            required: "Please specify a First Name"
 
                        },
                        
                      
                        cemail: {
                            required: "Please specify your Email",
                            email: "Invalid Email",
                        },
                        cphone: {
                            required: "Please specify your Phone",
                             number: "Enter numbers only",
                        },
                      
                      
                      
                    }
                });

            });

</script>
    <div id="primary" class="site-content">
        <div id="content" role="main">
        <form name="contacts" id="contact_form" action="" method="post">
            <table>
                <tr>
                    <td>Name: </td>
                    <td><input type="text" name="cname" id="cname"></td>
                </tr>
                <tr>
                    <td>Email: </td>
                    <td><input type="text" name="cemail" id="cemail"></td>
                </tr>
                <tr>
                    <td>Phone: </td>
                    <td><input type="text" name="cphone" id="cphone"></td>
                </tr>
                <tr>
                    <td>Message: </td>
                    <td><textarea name="message" id="message"></textarea></td>
                </tr>
                <tr>                  
                    <td clospan="2"><input type="submit" value="Submit" name="submit" id="submit"></td>
                </tr>
            </table>
        </form>
        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

page-contact-list.php
<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

get_header(); ?>

    <div id="primary" class="site-content">
        <div id="content" role="main">
        <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $pr=array(
        'post_type'=>'contact',
        'posts_per_page' => 3,
        'paged' => $paged,
        'post_status'=>'publish'
        );

$obj=new WP_Query($pr);


if($obj ->have_posts() )
{
?>
<table style="width:500px;" cellpadding="1" cellspacing="1">
<tr>
<td>Name</td>
<td>Email</td>
<td>Phone</td>
<tr>
<?php
while($obj ->have_posts())   
   
{
$obj->the_post();
$post_id=$post->ID;
 $page_data =get_page($id); 
 $title = $page_data->post_title;
 //$desc=$page_data->post_content;
 $name=get_post_meta($post_id,'contact_name')[0];
 $phone=get_post_meta($post_id,'contact_phone')[0];
 ?>
 <tr>
<td><?php echo $name?></td>
<td><?php echo $title?></td>
<td><?php echo $phone?></td>
<tr>
 <?php
 }
 ?>
 </table>
 <?php
 }
?>
<!-- pagination -->
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Price-settings.php
<?php
global $wpdb, $PasswordHash, $current_user, $user_ID;
$registeration_cost = get_option( 'registeration_cost', 'default_value' );
$guest_cost = get_option( 'guest_cost', 'default_value' );
$paypal_emailid = get_option( 'paypal_emailid', 'default_value' );
if($_POST['submit']){
$registeration_cost = trim($_POST['registeration_cost']);
$paypal_emailid = trim($_POST['paypal_emailid']);
$guest_cost = trim($_POST['guest_cost']);
update_option( 'registeration_cost', $registeration_cost);
update_option( 'guest_cost', $guest_cost);
update_option( 'paypal_emailid', $paypal_emailid);
}
?>
<style>
div.field {
    float:left;
    position:relative;
    width:100%;
}

label{
display:block;
font-weight:bold;
text-align:right;
width:140px;
margin-top:7px;
float:left;
}
.settings_submit {
    padding-left: 142px;
}
</style>
<section class="main_cont">
<!-- middle block starts here-->
<section class="mid_block">

<script src="<?php echo get_template_directory_uri(); ?>/js/jquery.validate.js"></script>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div class="entry-content">
<div id="container">
<div id="content">
<p>
<?php
if($error)
echo $error;
if($success)
echo $success;
?>
</p>
<?php //the_title(); ?>
<div id="user-registration" class="main">
<div id="pwdReset" class="registrationArea">
<form name="postsettings" class="regForm" id="postsettings" method="post">
<dl>
<div class="divider">
<div class="content">


<div class="field">
<label>Registration Fee&nbsp;<span>*</span>
</label>
<input type="text" name="registeration_cost" id="registeration_cost" value="<?php echo $registeration_cost; ?>" class="text-input" size="20" required="required">
(USD)
</div>
<div class="field">
<label>Guest Fee&nbsp;<span>*</span>
</label>
<input type="text" name="guest_cost" id="guest_cost" value="<?php echo $guest_cost; ?>" class="text-input" size="20" required="required">
(USD)
</div>

<div class="field">
<label>Paypal Emailid<span>*</span>
</label>
<input type="text" name="paypal_emailid" id="paypal_emailid" value="<?php echo $paypal_emailid; ?>" class="text-input" size="20"  required="required">
</p>
</div>
<div class="settings_submit"><input type="submit" name="submit" id="pass_submit" value="UDATE" class="button button-primary button-large"></div>



<table style="margin-left:153px">
  <tr>
    <td>
    
    </td>
  
  </tr>
</table>
</div>
<div class="clear"></div>
</div>
</dl>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- .entry-content -->
</div>
<!-- #content -->
</div>
<!-- #primary -->
</section>
<!-- middle block ends here-->

</section>
<?php //} ?>

Tuesday, January 27, 2015

Why User login stopped working or not working properly using active directory integration? and how to solve?

Sometimes user login won't work properly or stop working because of configurations issue. To solve this.. 1. Login at admin side. 2. Goto active directory integration settings. 3. Uncheck the "Use TLS" and save the settings. 4. Clear the cache and try to login.

Tuesday, August 26, 2014

How to disable hyper links in comments section of Wordpress?

To disable hyper links in comment section of Wordpress need to follow below two steps.

1. Open functions.php in the theme which you are using.
2. Place the below code in functions.php and save it.

add_filter('comment_text', 'wp_filter_nohtml_kses');
add_filter('comment_text_rss', 'wp_filter_nohtml_kses');
add_filter('comment_excerpt', 'wp_filter_nohtml_kses');

Monday, July 7, 2014

How to add a Custom Widget in Wordpress?

To add a custom widget just create a plugin by following below steps.

1. Create a folder in plugins folder.
2. Add a php file with folder name(Suppose if folder name is abc the file in folder should abc.php).
3. Add below code in that file.

<?php
/*
Plugin Name: Widget Plugin Name
Plugin URI: Author Link
Description: A simple plugin that adds a calendar of events at rights side
Version: 1.0
Author: Author Name
Author URI: Author Link
License: GPL2
*/
class wp_my_plugin extends WP_Widget {

// constructor
    function wp_my_plugin() {
        parent::WP_Widget(false, $name = __('My Widget', 'wp_widget_plugin') );
    }
    // widget form creation
function form($instance) {

// Check values
if( $instance) {
     $title = esc_attr($instance['title']);
 } else {
     $title = '';
  }
?>

<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>


 <?php
}

// update widget
function update($new_instance, $old_instance) {
      $instance = $old_instance;
      // Fields
      $instance['title'] = strip_tags($new_instance['title']);
      $instance['text'] = strip_tags($new_instance['text']);
      $instance['textarea'] = strip_tags($new_instance['textarea']);
     return $instance;
}
// display widget
function widget($args, $instance) {
   extract( $args );
   // these are the widget options
   $title = apply_filters('widget_title', $instance['title']);
   $text = $instance['text'];
   $textarea = $instance['textarea'];
   echo $before_widget;
   // Display the widget
   echo '<div class="widget-text wp_widget_plugin_box">';

   // Check if title is set
   if ( $title ) {
      echo $before_title . $title . $after_title;
   }

//add functionality you want add here..
   echo '</div>';
   echo $after_widget;
}
}

// register widget
add_action('widgets_init', create_function('', 'return register_widget("wp_my_plugin");'));
?>

Wednesday, May 14, 2014

How to solve the permalinks issue of /index.php/%postname% but not with just %postname% in IIS?

When we deploy the wordpress in ISS servers or Amazon windows servers .htaccess won't work untill we install httpd.conf and enable the htaccess there. Because of this we will get the issue of url with index.php/%postname% .

To solve this issue go to web.config file in IIS add below code in between of <rewrite><.rewrite>.

<rules>
<rule name="WordPress Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?page_id={R:0}" />
</rule>
</rules>




Tuesday, April 22, 2014

How to Solve White Screen Death problem in wordpress?

To solve the issue we need to first find out where is the problem. For this add the below code in wp-config.php file.

error_reporting(E_ALL);
ini_set('display_errors', 1);

By this you will easily find where is the code error and do the necessary changes and problem maximum get resolves.

How to solve Fatal error: Internal Zend error - Missing class information for in /server/mywebsite/wp-content/plugins/wp-super-cache/wp-cache-base.php on line 5 in wordpress?

To Solve this, just comment the below code in wp-cache-base.php file.

/*if (!class_exists('CacheMeta')) {
    class CacheMeta {
        var $dynamic = false;
        var $headers = array();
        var $uri = '';
        var $post = 0;
    }
}*/

Wednesday, April 2, 2014

How to solve 404 (Page Not Found) Error in wordpress when i moved the code to windows server?

To solve this, need to follow below steps.

1. Change the .htaccess file as per the code folder path..


# BEGIN WordPress
<IfModule mod_rewrite.so>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

2. If its not worked create a web.config file copy the below code and upload into root folder of the project.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
            <rule name="wordpress" patternSyntax="Wildcard">
                <match url="*"/>
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                    </conditions>
                <action type="Rewrite" url="index.php"/>
            </rule></rules>
    </rewrite>
  </system.webServer>
</configuration>

Monday, February 25, 2013

how to change title in mail for wordpress website from wordpress to customized text?

Todo this just goto page..
/wp-includes/pluggable.php

Search $from_name = 'WordPress'; and  Replace Wordpress word with
$from_name = 'your own name';

Tuesday, February 5, 2013

How to display total blog posts in a static page?

To display total blog posts in a static page which are created by the developer, need to follow below steps..

1. Create a page with the name posts.php in theme folder which the site using.
2. Copy paste below code

<?php
/**
 * Template Name: Posts Page
 * Description: A Page Template that adds a sidebar to pages
 *
 * @package WordPress
 * @subpackage Twenty_Eleven

Tuesday, January 22, 2013

How to create a plugin in wordpress?

For creating a new plugin in wordpress need to follow below steps:

1. Create a php file in plugins folder of your wordpress project.

For example : mytestplugin.php

2. Add the below code in that:
 <?php
/*
Plugin Name: My Test Plugin
Plugin URI: http://google.com
Description: This is a my first plugin
Version: 1.0
Author: Kiran
Author URI: http://gmail.com/
*/
?>
Plugin Name: name of the plugin which display at admin side of wordpress in plugins menu.
Plugin URL: describes the link of your plugin site.
Description: description of the plugin.
Version: version of the plugin
Author: Name of the author who creates the plugin
Authod URL: url of the author's site.


Thursday, October 11, 2012

How to do Events as calendar in post/page wordpress?

To make an event Need to follow below steps..

1. Install plugin from http://www.harriswebsolutions.co.uk/event-organiser/.
2. To display events as a calendar use the below short code..
   [eo_fullcalendar]

Wednesday, September 26, 2012

How to display posts in related pages?

First of all we need to create a category in posts. For example i want to display events posts in events page. So i have to create a events category in Posts Category. Then add all posts for events. Now create a page in the themes folder. And copy the below code in that page.

<?php
/**
 * Template Name: Posts Display
 *
 * Selectable from a dropdown menu on the edit page screen.
 */
 get_header();
?>

Monday, September 3, 2012

How to add gallerywise or advanced search in nextgen gallery in wordpress?

To add advance or gallery wise search need to follow below steps....

1. First we need to install both nexgengallery and nexgengallery search.
2. Then change the form structure of searchform.php in the current theme  as below..

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<table>
<tr>
    <td><label for="s" class="assistive-text"><?php _e( 'Search', 'twentyeleven' ); ?></label></td>
    <td><input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search Images', 'twentyeleven' ); ?>" /></td>

Thursday, August 30, 2012

How to add Images search in Nexgen Gallery for wordpress?

To do this first of all we need to install both nexgengallery and nexgengallery search. After activating both the plugins need to follow below steps.

1. Open search.php of your current theme from themes.
2. Copy and paste the below code into the search.php. This code will work for both searching content and images.
<?php
/**
 * The template for displaying Search Results pages.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

get_header(); ?>

        <section id="primary">
            <div id="content" role="main">

Wednesday, August 29, 2012

How to add multiple Featured Images for each page/posts in wordpress?

For adding multiple featured images for pages or posts need to follow below steps.

1. Install the plugin Multiple Featured Images

2. Add the below code to functions.php

a. For adding Featured images to pages..

if( class_exists( 'kdMultipleFeaturedImages' ) ) {

        $args = array(

                'id' = 'featured-image-2',

Tuesday, August 28, 2012

Tuesday, August 21, 2012

How to create template page in wordpress

Copy Any previous template page and change the Template Name as per your requirement. For Example: Template Name: Front Page and this new template page will display in the template lists for each new page adding/editing section. Or Create a new page in the theme.. and paste the below code...

<?php
/**
 * Template Name: Front Page
 * Description: A Page Template that adds a sidebar to pages
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

get_header(); ?>

        <div id="primary">
            <div id="content" role="main">