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, ...

Create custom Post type In Wordpress

add in function.php

add_action('init', 'samrat_testimonial');

function samrat_testimonial() {
    $labels = array(
        'name' => __('Testimonials', 'samrat-toolkit'),
        'singular_name' => __('Testimonial', 'samrat-toolkit'),
        'add_new' => __('Add New', 'samrat-toolkit'),
        'add_new_item' => __('Add New Item', 'samrat-toolkit'),
        'edit_item' => __('Edit Item', 'samrat-toolkit'),
        'new_item' => __('New Item', 'samrat-toolkit'),
        'all_items' => __('All Items', 'samrat-toolkit'),
        'view_item' => __('View Item', 'samrat-toolkit'),
        'search_items' => __('Search Items', 'samrat-toolkit'),
        'not_found' => __('No items found', 'samrat-toolkit'),
        'not_found_in_trash' => __('No items found in Trash', 'samrat-toolkit'),
        'parent_item_colon' => '',
        'menu_name' => __('Testimonials', 'samrat-toolkit')
    );

    $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,
        'exclude_from_search' => true,
        'menu_position' => 100,
        'supports' => array('title', 'thumbnail', 'editor', 'excerpt'),
        'can_export' => true,
        'register_meta_box_cb' => ''
    );

    register_post_type('testimonials', $args);

    $taxonomy_category_args = array(
        'public' => true,
        'hierarchical' => true,
        'labels' => array(
            'name' => __('Testimonial Categories', 'taxonomy general name', 'samrat-toolkit'),
            'singular_name' => __('Category', 'taxonomy singular name', 'samrat-toolkit'),
            'search_items' => __('Search Category', 'samrat-toolkit'),
            'popular_items' => __('Popular Testimonials', 'samrat-toolkit'),
            'all_items' => __('All Testimonials', 'samrat-toolkit'),
            'parent_item' => null,
            'parent_item_colon' => null,
            'edit_item' => __('Edit Testimonial', 'samrat-toolkit'),
            'update_item' => __('Update Testimonial', 'samrat-toolkit'),
            'add_new_item' => __('Add New Testimonial', 'samrat-toolkit'),
            'new_item_name' => __('New Testimonial Name', 'samrat-toolkit'),
            'separate_items_with_commas' => __('Separate categories with commas', 'samrat-toolkit'),
            'add_or_remove_items' => __('Add or remove category', 'samrat-toolkit'),
            'choose_from_most_used' => __('Choose from the most used categories', 'samrat-toolkit'),
            'menu_name' => __('Testimonial Categories', 'samrat-toolkit')
        ),
        'show_ui' => true,
        'show_admin_column' => true,
        'update_count_callback' => '',
        'query_var' => true,
        'show_in_nav_menus' => true,
        'show_tagcloud' => true,
        'rewrite' => array('slug' => 'testimonial_category')
    );

    register_taxonomy('testimonial_category', 'testimonials', $taxonomy_category_args);

    #TAXONOMY TAG
    $taxonomy_tag_args = array(
        'public' => true,
        'hierarchical' => false,
        'labels' => array(
            'name' => __('Testimonial Tags', 'taxonomy general name', 'samrat-toolkit'),
            'singular_name' => __('Tag', 'taxonomy singular name', 'samrat-toolkit'),
            'search_items' => __('Search Tag', 'samrat-toolkit'),
            'popular_items' => __('Popular Tags', 'samrat-toolkit'),
            'all_items' => __('All Tags', 'samrat-toolkit'),
            'parent_item' => null,
            'parent_item_colon' => null,
            'edit_item' => __('Edit Tag', 'samrat-toolkit'),
            'update_item' => __('Update Tag', 'samrat-toolkit'),
            'add_new_item' => __('Add New Tag', 'samrat-toolkit'),
            'new_item_name' => __('New Tag Name', 'samrat-toolkit'),
            'separate_items_with_commas' => __('Separate tags with commas', 'samrat-toolkit'),
            'add_or_remove_items' => __('Add or remove tag', 'samrat-toolkit'),
            'choose_from_most_used' => __('Choose from the most used tags', 'samrat-toolkit'),
            'menu_name' => __('Testimonial Tags', 'samrat-toolkit')
        ),
        'show_ui' => true,
        'show_admin_column' => true,
        'update_count_callback' => '',
        'query_var' => true,
        'show_in_nav_menus' => true,
        'show_tagcloud' => true,
        'rewrite' => array('slug' => 'testimonial_tag')
    );

    register_taxonomy('testimonial_tag', 'testimonials', $taxonomy_tag_args);

    flush_rewrite_rules(false);  
}


//for pagination

function pagination($pages = '', $range = 2)
{
$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;
}
}

if(1 != $pages)
{
echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
}
}

if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
echo "</div>\n";
}
}


Add php file for show post with pagination
<?php
/**
 * Template Name: Samrat Testimonials
 */
?>
<style>
.pagination{clear:both; padding:20px 0; position:relative; font-size:11px; line-height:13px;}

.pagination span, .pagination a{ display:block; float:left; margin: 2px 2px 2px 0; padding:6px 9px 5px 9px; text-decoration:none; width:auto; color:#fff; background: #555;}

.pagination a:hover{ color:#fff; background: #3279BB;}

.pagination .current{ padding:6px 9px 5px 9px; background: #3279BB; color:#fff;}

</style>
<?php get_header(); ?>

        <div id="container">
            <div id="content">
            <?php
   $type = 'testimonials';
$status='publish';
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page=1'.'&paged='.$paged.'&post_type='.$type.'&post_status='.$status);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
               <!-- ***************-->
                  <p class="date"><?php the_time('F jS, Y'); ?></p>
<?php //get_template_part( 'content', get_post_format() ); ?>
                 <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
                  <?php if ( ! post_password_required() && ! is_attachment() ) :
the_post_thumbnail();
endif; ?>
                 <p>  <?php the_content(); ?>   </p>
               <!--  ********************
                 or-->
               
                  <?php //get_template_part( 'content', get_post_format() ); ?>
                   
                     <!-- ***************-->
                 <?php
$terms = get_the_terms($post->ID, 'testimonial_category' );
if ($terms && ! is_wp_error($terms)) :
$term_slugs_arr = array();
foreach ($terms as $term) {
   $term_slugs_arr[] = $term->slug;
}
$terms_slug_str = join( " ", $term_slugs_arr);
endif;
echo $terms_slug_str;
?>
<?php endwhile; ?>
<?php if (function_exists("pagination")) {
pagination($additional_loop->max_num_pages);
 } ?>
 <?php $wp_query = null; $wp_query = $temp;?>
                       </div><!-- #content -->
        </div><!-- #container -->
                  <?php get_sidebar(); ?>
<?php get_footer(); ?>



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...