Showing posts with label Core PHP. Show all posts
Showing posts with label Core PHP. Show all posts

Sunday, March 29, 2015

wordpress Create new custom page like posts page on backend side


add_action('init', 'article_register');

function article_register() {

$labels = array(
'name' => _x('Articles', 'post type general name'),
'singular_name' => _x('Article Item', 'post type singular name'),
'add_new' => _x('Add New', 'Article item'),
'add_new_item' => __('Add New Article Item'),
'edit_item' => __('Edit Article Item'),
'new_item' => __('New Article Item'),
'view_item' => __('View Article Item'),
'search_items' => __('Search Article'),
'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,
'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail')
 );

register_post_type( 'article' , $args );
}
register_taxonomy("Skills", array("article"), array("hierarchical" => true, "label" => "Skills", "singular_label" => "Skill", "rewrite" => true));

Wednesday, November 6, 2013

Custom Social networking sharing link

https://www.linkedin.com/cws/share?url=SITE_URL
http://twitter.com/home?status=SITE_URL
https://plus.google.com/share?url=SITE_URL
http://www.facebook.com/share.php?u=SITE_URL

Thursday, October 10, 2013

HTML and Javascript to share page on social networing site

<a href="#" onclick="window.open('https://plus.google.com/share?url='+encodeURIComponent(location.href), 'facebook-share-dialog', 'width=626,height=436'); return false;" class="icon">Google Icon</a>
            <a href="#" onclick="window.open('http://twitter.com/home?status='+encodeURIComponent(location.href), 'facebook-share-dialog', 'width=626,height=436'); return false;" class="icon">Twitter Icon</a>
            <a href="#" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href), 'facebook-share-dialog', 'width=626,height=436'); return false;" class="icon">Facebook Icon</a>

Monday, August 5, 2013

PHP Script to calculate time from specific date(Like Facebook)

function time_passed($timestamp)

    $timestamp      = (int) $timestamp;
    $current_time   = time();
    $diff           = $current_time - $timestamp;
  
    $intervals      = array ('year' => 31556926, 'month' => 2629744, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'minute'=> 60);
  
    if ($diff == 0)
    {
        return 'just now';
    }  

    if ($diff < 60)
    {
        return $diff == 1 ? $diff . ' second ago' : $diff . ' seconds ago';
    }      

    if ($diff >= 60 && $diff < $intervals['hour'])
    {
        $diff = floor($diff/$intervals['minute']);
        return $diff == 1 ? $diff . ' minute ago' : $diff . ' minutes ago';
    }      

    if ($diff >= $intervals['hour'] && $diff < $intervals['day'])
    {
        $diff = floor($diff/$intervals['hour']);
        return $diff == 1 ? $diff . ' hour ago' : $diff . ' hours ago';
    }  

    if ($diff >= $intervals['day'] && $diff < $intervals['week'])
    {
        $diff = floor($diff/$intervals['day']);
        return $diff == 1 ? $diff . ' day ago' : $diff . ' days ago';
    }  

    if ($diff >= $intervals['week'] && $diff < $intervals['month'])
    {
        $diff = floor($diff/$intervals['week']);
        return $diff == 1 ? $diff . ' week ago' : $diff . ' weeks ago';
    }  

    if ($diff >= $intervals['month'] && $diff < $intervals['year'])
    {
        $diff = floor($diff/$intervals['month']);
        return $diff == 1 ? $diff . ' month ago' : $diff . ' months ago';
    }  

    if ($diff >= $intervals['year'])
    {
        $diff = floor($diff/$intervals['year']);
        return $diff == 1 ? $diff . ' year ago' : $diff . ' years ago';
    }
}
echo time_passed(strtotime('2012-08-05')) . '<br />';