Saturday, April 12, 2014

How to add menu in Wordpress Admin without Plugin

Here we are talking about Adding a menu item in wordpress admin panel to add manual functionality for your themes and plugins etc. Let's do it You need a Wordpress Function called add_action which get 2 parameter. 
add_action Parameters Explanations:
  1.  First parameter is what do you want to add so we write admin menu.
  2. Second parameter is that we will tell wordpress add action that my other explanation will be in signal_adder function
what will be in signal_adder function

We write function signal_adder(){

==>now our add_action will complete after this function  

we are telling wordpress in next line add_posts_page it means our menu item will be in posts section just copy the code and paste in theme functions.php file and you will see there is a menu called Add Signal.

add_posts_page parameter Explanations
  1. First parameter will be the Menu Title 
  2. Second parameter will be the Page Title 
  3. Third parameter will be manage our page options (Fixed just write as it is)
  4. fourth parameter will be your choice because in our admin panel url will be yourhost.com/wp-admin/edit.php?page=signali 
  5. Fifth parameter will be a function in which our other things lie like what will be the page matter or texts etc. 


add_action('admin_menu','signal_adder');

function signal_adder(){
    add_posts_page('Add Signal','Add Signal','manage_options','signali','signal_adder_text');
}
function signal_adder_text(){
    echo "Hurrah i make a custom admin menu";
}

Beginners always feel very ambiguous while making admin menu just write i will comment and solve your problem as already i am beginner not an expert but the problems i tackle i write here. Just follow the path and you will be lead by me. Hope you will like this tutorial then you going to share and comment your review thanks for reading.

How to get Default Timezone in PHP

Here i will talk about timezone which you can't get in PHP there is no built in function to get that.... But here i am with a new technique to get timezone in PHP using Javascript. Let's do it.

First of all Download a small js file from top of this website. Put this file in js folder and replace the name here bold in code


function timeStamp(){
    echo '<script type="text/javascript" src="'js/jstie.min.js" /></script>';
    echo '<script type="text/javascript">';
    echo "var timezone = jstz.determine();";

    $timezoni = "document.write(timezone.name());";
    echo "</script>"; 

    timeStamp();
    date_default_timezone_set($timezoni);

That's all now your timezone will be save in variable $timezoni nothing difficult just call the function timeStamp();  you will get a variable timezoni and put that in date_default_timezone_set() this is the PHP function to set a specific timezone but we do it dynamically.

Hope you will like this tutorial and you going to comment and share this with your friend.

Friday, April 11, 2014

How to Show Timestamp like Seconds and Minutes Ago

Here i am talking about the timestamp which looks like Twitter or Facebook timestamp , 2 Days ago or 4 Days ago or 2 Minutes ago. Same like here is the simple tutorial which will show you how to implement same like this. Once you need to call this function timeAgo($timestamp);and you will just see this stamp one more thing change your timezone according to your taste or server as you wish. Also for the simple way just make your date like "2014-04-11 11:10:20" and take this in $timestamp variable and just call your function you will see these type of timestamp.

function timeAgo($timestamp){
date_default_timezone_set("Asia/Karachi");
    $datetime1=new DateTime("now");
    $datetime2=date_create($timestamp);
    $diff=date_diff($datetime1, $datetime2);
    $timemsg='';
    if($diff->y > 0){
        $timemsg = $diff->y .' year'. ($diff->y > 1?"'s":'');

    }
    else if($diff->m > 0){
     $timemsg = $diff->m . ' month'. ($diff->m > 1?"'s":'');
    }
    else if($diff->d > 0){
     $timemsg = $diff->d .' day'. ($diff->d > 1?"'s":'');
    }
    else if($diff->h > 0){
     $timemsg = $diff->h .' hour'.($diff->h > 1 ? "'s":'');
    }
    else if($diff->i > 0){
     $timemsg = $diff->i .' minute'. ($diff->i > 1?"'s":'');
    }
    else if($diff->s > 0){
     $timemsg = $diff->s .' second'. ($diff->s > 1?"'s":'');
    }

$timemsg = $timemsg.' ago';
echo $timemsg;
}

If you love this tutorials please share it or comment below.