Skip to main content

Get Google Calendar Event List in WordPress

<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function  get_calender_events() { $params = array(); /*Get current date*/ $current_date  = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key =  "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...

show all post in anther page in wordpress

show all post in anther page in wordpress


<?php
$catid = trim($_GET['catid']);
// Include the wp-load'er
include('wp/wp-load.php');

?>
<div class="wp-catlist-all">
<?php
if($catid!='') {
$postargs = array(
'posts_per_page'   => '10',
'category'         => $catid,
'orderby'          => 'post_date',
'order'            => 'DESC',
'post_type'        => 'post',
'post_status'      => 'publish',
'suppress_filters' => true );
$myposts = get_posts( $postargs );
?>
<?php
if(count($myposts)) {
            foreach ( $myposts as $post ) : setup_postdata( $post );
$ptitle = $post->post_title;
                $content = $post->post_excerpt;
        ?>
        <div class="wp-cat-single">
            <div class="wp-post-title"><?php echo $ptitle; ?></div>
            <div class="inner-content">
                <div class="wp-featured-img"><?php if(get_the_post_thumbnail($post->ID, 'thumbnail')) { echo get_the_post_thumbnail($post->ID, 'thumbnail'); } else { ?><img src="images/no-image.jpg" width="150" height="150" title="<?php the_title(); ?>" /><?php }; ?></div>
                <div class="wp-content">
                    <div class="wp-short-desc"><?php if(strlen($content)>400) { echo substr($content,0,400).".."; } else { echo $content; } ?></div>
                    <div class="wp-view-more"><a href="view_post.php?postid=<?php echo $post->ID; ?>" title="<?php the_title(); ?>"> READ MORE&nbsp;<img src="images/arrow-right.png" class="wp-arrow-right" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" /></a></div>
                </div>
            </div>
        </div>
        <?php endforeach;
wp_reset_postdata();
} else {
?>
<div align="center"><b>No Posts Found!</b></div>
<?php
}
?>
<?php } else { ?>
<div align="center"><b>No Category Found!</b></div>
<?php } ?>
</div>

----------------------------------------------
view_post.php

<?php
$postid = trim($_GET['postid']);
// Include the wp-load'er
include('wp/wp-load.php');

if($postid!='') {
$post = get_post($postid);
?>
<div class="wp-catlist-all">
        <div class="wp-cat-full">
            <div class="wp-post-title"><?php echo $post->post_title; ?></div>
            <div class="inner-content">
                <div class="wp-featured-img"><?php if(get_the_post_thumbnail($post->ID, 'thumbnail')) { echo get_the_post_thumbnail($post->ID, 'thumbnail'); } else { ?><img src="images/no-image.jpg" width="150" height="109" title="<?php echo $category->name; ?>" /><?php }; ?></div>
                <div class="wp-content">
                    <div class="wp-short-desc"><?php echo $post->post_content; ?></div>
                </div>
            </div>
        </div>
</div>
<?php } ?>


----------------------------------
all Posts

<?php
// Include the wp-load'er
include('wp/wp-load.php');

$catargs = array(
'type'                     => 'post',
'child_of'                 => 0,
'parent'                   => '',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'exclude'                  => '1',
'include'                  => '',
'number'                   => '',
'taxonomy'                 => 'category',
'pad_counts'               => false
);

$arrayData = array();
$arrayTransfer = array();
$arrayTransferKeys = array();

$cntr = 0;
$categories = get_categories( $catargs );
foreach($categories as $category) {
$arrayData[$cntr]['catID'] = $category->cat_ID;
$arrayData[$cntr]['catTITLE'] = $category->name;
$arrayData[$cntr]['catPOST'] = array();
$postargs = array(
'posts_per_page'   => '1',
'category'         => $category->cat_ID,
'orderby'          => 'post_date',
'order'            => 'DESC',
'post_type'        => 'post',
'post_status'      => 'publish',
'suppress_filters' => true );
$myposts = get_posts( $postargs );
foreach ( $myposts as $post ) : setup_postdata( $post );
$ptitle = $post->post_title;
$content = $post->post_content;
$arrayData[$cntr]['catPOST']['ptitle'] = $post->post_title;
$arrayData[$cntr]['catPOST']['content'] = $post->post_excerpt;
$arrayData[$cntr]['catPOST']['date_added'] = $post->post_date;
$arrayData[$cntr]['catPOST']['thumb'] = get_the_post_thumbnail($post->ID, 'thumbnail');
$datetotime = strtotime($post->post_date);
endforeach;
$arrayTransfer[$datetotime] = $arrayData[$cntr];
$arrayTransferKeys[] = $datetotime;
wp_reset_postdata();
$cntr++;
}
rsort($arrayTransferKeys);
?>
<script type="text/javascript">
function loadMore() {
$("#cat_list_less").hide();
$("#cat_list_more").show();
}
</script>
<div class="wp-catlist-all" id="cat_list_less">
<?php if(count($arrayTransferKeys)) { ?>
<?php $index = 0; foreach($arrayTransferKeys as $datakey) { ?>
<?php
$cname = $arrayTransfer[$datakey]['catTITLE'];
$cid = $arrayTransfer[$datakey]['catID'];
$ptitle = $arrayTransfer[$datakey]['catPOST']['ptitle'];
$content = $arrayTransfer[$datakey]['catPOST']['content'];
$pthumb = $arrayTransfer[$datakey]['catPOST']['thumb'];
$pdate = $arrayTransfer[$datakey]['catPOST']['date_added'];
?>
<div class="wp-cat-single">
<div class="wp-post-title"><?php echo $ptitle; ?></div>
<div class="inner-content">
<div class="wp-featured-img"><?php if($pthumb != '') { echo $pthumb; } else { ?><img src="images/no-image.jpg" width="150" height="150" title="<?php echo $cname; ?>" /><?php }; ?></div>
<div class="wp-content">
<div class="wp-short-desc"><?php if(strlen($content)>400) { echo substr($content,0,400).".."; } else { echo $content; } ?></div>
<div class="wp-view-more"><a href="view_all_posts.php?catid=<?php echo $cid; ?>" title="<?php echo $cname; ?>">MORE <?php echo $cname; ?> NEWS&nbsp;<img src="images/arrow-right.png" class="wp-arrow-right" title="<?php echo $cname; ?>" alt="<?php echo $cname; ?>" /></a></div>
<?php if ($index == 5) { ?>
<br /><div class="wp-view-more wp-load-more"><a href="javascript:loadMore();" title="">Load More</a></div>
<?php } ?>
</div>
</div>
</div>
<?php
$index++;
if ($index >= 6) break;
}
?>
<?php } ?>
</div>
<div class="wp-catlist-all" id="cat_list_more" style="display:none;">
<?php if(count($arrayTransferKeys)) { ?>
<?php foreach($arrayTransferKeys as $datakey) { ?>
        <?php
            $cname = $arrayTransfer[$datakey]['catTITLE'];
            $cid = $arrayTransfer[$datakey]['catID'];
            $ptitle = $arrayTransfer[$datakey]['catPOST']['ptitle'];
            $content = $arrayTransfer[$datakey]['catPOST']['content'];
            $pthumb = $arrayTransfer[$datakey]['catPOST']['thumb'];
$pdate = $arrayTransfer[$datakey]['catPOST']['date_added'];
        ?>
        <div class="wp-cat-single">
            <div class="wp-post-title"><?php echo $ptitle; ?></div>
            <div class="inner-content">
                <div class="wp-featured-img"><?php if($pthumb != '') { echo $pthumb; } else { ?><img src="images/no-image.jpg" width="150" height="150" title="<?php echo $cname; ?>" /><?php }; ?></div>
                <div class="wp-content">
                    <div class="wp-short-desc"><?php if(strlen($content)>400) { echo substr($content,0,400).".."; } else { echo $content; } ?></div>
                    <div class="wp-view-more"><a href="view_all_posts.php?catid=<?php echo $cid; ?>" title="<?php echo $cname; ?>">MORE <?php echo $cname; ?> NEWS&nbsp;<img src="images/arrow-right.png" class="wp-arrow-right" title="<?php echo $cname; ?>" alt="<?php echo $cname; ?>" /></a></div>
                </div>
            </div>
        </div>
    <?php } ?>
<?php } ?>
</div>

------------------------------
Custom Profile field as a Registration Field

<?php
/*
Plugin Name: Custom Profile field as a Registration Field
Plugin URI: http://samratparida.blogspot.in/
Description: Sample plugin for adding a custom profile field to WordPress and on the registration page
Author: Samrat Keshari Parida
Version: 0.1
Author URI: http://samratparida.blogspot.in/
*/

/**
 * Add additional custom field
 */

add_action ( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action ( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields ( $user )
{
?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="twitter">Twitter</label></th>
<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Twitter username.</span>
</td>
</tr>
</table>
<?php
}

add_action ( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action ( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id )
{
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
}

/**
 * Add cutom field to registration form
 */

add_action('register_form','show_first_name_field');
add_action('register_post','check_fields',10,3);
add_action('user_register', 'register_extra_fields');

function show_first_name_field()
{
?>
<p>
<label>Twitter<br/>
<input id="twitter" type="text" tabindex="30" size="25" value="<?php echo $_POST['twitter']; ?>" name="twitter" />
</label>
</p>
<?php
}

function check_fields ( $login, $email, $errors )
{
global $twitter;
if ( $_POST['twitter'] == '' )
{
$errors->add( 'empty_realname', "<strong>ERROR</strong>: Please Enter your twitter handle" );
}
else
{
$twitter = $_POST['twitter'];
}
}

function register_extra_fields ( $user_id, $password = "", $meta = array() )
{
update_user_meta( $user_id, 'twitter', $_POST['twitter'] );
}

?>

----------------------------------------------------------

login-by-emailid


<?php
/*
Plugin Name: Login By Emai Id
Plugin URI: http://samratparida.blogspot.in/
Description: Change loging form Username  to Email Id
Author: Samrat Keshari Parida
Version: 0.1
Author URI: http://samratparida.blogspot.in/
*/

/**
 * Change loging form Username  to Email Id
 */


/* Change loging form Username  to Email Id*/

//remove wordpress authentication
remove_filter('authenticate', 'wp_authenticate_username_password', 20);

add_filter('authenticate', function($user, $email, $password){

    //Check for empty fields
        if(empty($email) || empty ($password)){      
            //create new error object and add errors to it.
            $error = new WP_Error();

            if(empty($email)){ //No email
                $error->add('empty_username', __('<strong>ERROR</strong>: Email field is empty.'));
            }
            else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ //Invalid Email
                $error->add('invalid_username', __('<strong>ERROR</strong>: Email is invalid.'));
            }

            if(empty($password)){ //No password
                $error->add('empty_password', __('<strong>ERROR</strong>: Password field is empty.'));
            }

            return $error;
        }

        //Check if user exists in WordPress database
        $user = get_user_by('email', $email);

        //bad email
        if(!$user){
            $error = new WP_Error();
            $error->add('invalid', __('<strong>ERROR</strong>: Either the email or password you entered is invalid.'));
            return $error;
        }
        else{ //check password
            if(!wp_check_password($password, $user->user_pass, $user->ID)){ //bad password
                $error = new WP_Error();
                $error->add('invalid', __('<strong>ERROR</strong>: Either the email or password you entered is invalid.'));
                return $error;
            }else{
                return $user; //passed
            }
        }
}, 20, 3);
?>
-------------------------


Comments

Popular posts from this blog

Create Signature pad with save on database in php

Create Signature pad with save on database in php 1.create a folder images index.php ============   <!DOCTYPE >     <head>     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />     <title>Signature Pad</title>     <script type="text/javascript" src="jquery-1.8.0.min.js"></script>     <script type="text/javascript"> $(document).ready(function () {     /** Set Canvas Size **/     var canvasWidth = 400;     var canvasHeight = 100;     /** IE SUPPORT **/     var canvasDiv = document.getElementById('signaturePad');     canvas = document.createElement('canvas');     canvas.setAttribute('width', canvasWidth);     canvas.setAttribute('height', canvasHeight);     canvas.setAttribute('id', 'canvas');     canvasDiv.appendChild(canvas);    ...

Get Google Calendar Event List in WordPress

<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function  get_calender_events() { $params = array(); /*Get current date*/ $current_date  = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key =  "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...

WooCommerce Mini cart With Ajax

WooCommerce Mini cart //MINI CART SECTION   <div class="productdiv rightcart">                                                         <?php if ( ! WC()->cart->is_empty() ) : ?>     <ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">         <?php             do_action( 'woocommerce_before_mini_cart_contents' );             foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {                 $_product     = apply_filters( 'woocommerce_cart_item_pro...