How to get Short Url from using PHP API WITH is.gd, api.tr.im, hex.io

Creating the short url is now becoming the popular trend because of twitter and facebook. Tutorial about How to get Short Url from using PHP API WITH is.gd, api.tr.im, hex.io.

 

get Short Url from using PHP
get Short Url from using PHP

If you want to use API in php for creating the short URL. use following code:


<?php //Get short URL from free API with purabtech.in/files/ function get_short_url($long_url,$provider='isgd') { $ch = curl_init(); $timeout = 5; switch(strtolower(trim($provider))) { case "isgd": curl_setopt($ch,CURLOPT_URL,'http://is.gd/api.php?longurl='.$long_url); break; case "hexio": curl_setopt($ch,CURLOPT_URL,'http://hex.io/api-create.php?url='.$long_url); break; case "trim": $return = "http://api.tr.im/v1/trim_url.xml?url=%s"; curl_setopt($ch,CURLOPT_URL,'http://api.tr.im/v1/trim_url.xml?url='.$long_url); break; default: curl_setopt($ch,CURLOPT_URL,'http://is.gd/api.php?longurl='.$long_url); } curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $content = curl_exec($ch); curl_close($ch); // return the short URL return $content; } //uage $short_url = get_short_url('http://images.purabtech.in/'); echo $short_url; ?>

<br>

Sample ofHow to Use<br><br>


<?php
$long_url = 'http://images.purabtech.in/';
$short_url = get_short_url($long_url,'hexio');
echo $short_url;
echo '
';
$short_url = get_short_url($long_url,'isgd');
echo $short_url;
echo '
';
$short_url = get_short_url($long_url,'trim');
echo $short_url;
echo '
';

?>

check html 5 is support in browsers through javascript

HTML5 is new version of HTML and many people does not aware of it.  In article, we checked html 5 is support in browsers through javascript. HTML5 is a new version of HTML and XHTML. The HTML5 draft specification defines a single language that can be written in HTML and XML.

check html 5 is support in browsers through javascript

It attempts to solve issues found in previous iterations of HTML and addresses the needs of Web Applications, an area previously not adequately covered by HTML.

check html 5 is support in browsers through javascript
check html 5 is support in browsers through javascript

In one of my project I need to use HTML5 methods and properties through javascript. So first I need to check or dectect with multiple browsers is there way to find HTML5 compability with browsers.I

Main introduced features are like canvas, video, or geolocation. Using that we can easily dectect the browsers compability.


if (navigator.geolocation) {
/* geolocation is available */
} else {
alert("I'm sorry, but geolocation services and HTML5 are not supported by your browser.");
}

or

if (window.postMessage) {
/* postMessage method is available */
} else {
alert("I'm sorry, but postMessage method and HTML5 are not supported by your browser.");
}

I am still searching for better solution…

install the YII on local machine (PHP framework)

Yii — a high-performance component-based PHP framework best for developing large-scale Web applications. Yii comes with a full stack of features, including MVC, DAO/ActiveRecord, I18N/L10N, caching, jQuery-based AJAX support, authentication and role-based access control, scaffolding, input validation, widgets, events, theming, Web services, and so on.

Written in strict OOP, Yii is easy to use and is extremely flexible and extensible. here in this article I given the steps for install the YII on local machine (PHP framework)

install the YII on local machine (PHP framework)

You can download the YII framework from following URL

http://www.yiiframework.com/download/

Yii PHP Framework: Best for Web 2.0 install the YII on local machine
install the YII on local machine

I copied the folder in my ROOT directory. I am using the fedora on my machine.

 

install the YII on local machine

 

Just follow my commands:


[kapil@kapilk-pc ~]$ cd /var/www/html/yii/
[kapil@kapilk-pc yii]$ cd framework/
[kapil@kapilk-pc framework]$ ./yiic webapp ../testdrive
PHP Warning:  Module 'memcache' already loaded in Unknown on line 0
Create a Web application under '/var/www/html/yii/testdrive'? [Yes|No] y
unchanged css/bg.gif
unchanged css/main.css
unchanged css/form.css
unchanged css/print.css
unchanged css/screen.css
unchanged css/ie.css
unchanged index.php
unchanged themes/classic/views/.htaccess
unchanged index-test.php
unchanged protected/components/Controller.php
unchanged protected/components/UserIdentity.php
unchanged protected/yiic.php
unchanged protected/config/main.php
unchanged protected/config/console.php
unchanged protected/config/test.php
unchanged protected/yiic
unchanged protected/models/ContactForm.php
unchanged protected/models/LoginForm.php
unchanged protected/data/schema.mysql.sql
unchanged protected/data/testdrive.db
unchanged protected/data/schema.sqlite.sql
unchanged protected/.htaccess
unchanged protected/controllers/SiteController.php
unchanged protected/yiic.bat
unchanged protected/views/site/pages/about.php
unchanged protected/views/site/index.php
unchanged protected/views/site/error.php
unchanged protected/views/site/contact.php
unchanged protected/views/site/login.php
unchanged protected/views/layouts/main.php
unchanged protected/tests/bootstrap.php
unchanged protected/tests/WebTestCase.php
unchanged protected/tests/phpunit.xml
unchanged protected/tests/functional/SiteTest.php

Your application has been created successfully under /var/www/html/yii/testdrive.
[kapil@kapilk-pc framework]$

How to schedule events in wordpress

As we all know cron job can be scheduled in linux systems. So scheduling the any job in wordpress is easy because scheduling the events in wordpress is provided by wordpress itself.

How to schedule events in wordpress

How to schedule events in wordpress
How to schedule events in wordpress

WordPress provides the following functions to schedule the events.

wp_schedule_event(); //using this method you can schedule events.

You can pass following parameters to this method.

wp_schedule_event(time(), ‘hourly’, ‘your_event’);

Following params you need to pass to this method.

$timestamp
(integer) (required) The first time that you want the event to occur. This must be in a UNIX timestamp format.

Default: None

$recurrance
(string) (required) How often the event should reoccur. Valid values:

* hourly
* twicedaily
* daily

Default: None

$hook
(string) (required) The name of an action hook to execute.

Default: None

$args
(array) (optional) Arguments to pass to the hook function(s).

Default: None

You can Schedule an hourly event. Example as follows:

register_activation_hook(__FILE__, ‘my_activation’);
add_action(‘my_hourly_event’, ‘do_this_hourly’);

function my_activation() {
wp_schedule_event(time(), ‘hourly’, ‘my_hourly_event’);
}

function do_this_hourly() {
// do something every hour
}

Don’t forget to clean the scheduler on deactivation:

register_deactivation_hook(__FILE__, ‘my_deactivation’);

function my_deactivation() {
wp_clear_scheduled_hook(‘my_hourly_event’);
}

Now I am going to tell you how to extend the wp_schedule_event().
We can add the more recurrences adding following code.

function ten_minute_reccurences() {
return array(
‘ten_minute_reccurences’ => array(‘interval’ => 60*10, ‘display’ => ‘Once in Ten Mintues’),
);
}
add_filter(‘cron_schedules’, ‘ten_minute_reccurences’);

If you want check this recurrences added to wp_schedule_event or not. You need to just use following code to print recurrences

php print_r(wp_get_schedules());  ?>

I found useful following URLs.

http://codex.wordpress.org/Function_Reference/wp_schedule_event
http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
http://codex.wordpress.org/Plugin_API

If you have PHP knowledge than you should open wp-includes/cron.php file. This file has best information and methods about scheduler.

How to customize read more for every wordpress post

So many clients had requirement about customize read more link for every post. Tutorial for, How to customize read more for every wordpress post.

So achieving this functionality in easiest way is following.

Just add following code in your functions.php file.


<?php
//The Query
query_posts('posts_per_page=1');

//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();

global $post;
$thePostID = $post->ID;
$custom_read_more = get_post_meta($post->ID, 'custom_read_more', true);

if ($custom_read_more) {
add_post_meta($thePostID, 'custom_read_more', 'You need to read this article');  //custom read more value
}

endwhile;
endif;
?>
customize read more for every wordpress post
customize read more for every wordpress post

Now you are set to use the custom read more value for each post. You need to just copy paste the following code in your index.php and page.php and single.php file.

<?php $custom_read_more = get_post_meta($post->ID, 'custom_read_more', true); ?>

<?php if (!$custom_read_more) { $custommore = 'Read More &raquo;'; } ?>

<?php the_content($custom_read_more); ?>

How to add Meta box to wordpress admin post page

This article will tell you about, How to add Meta box to wordpress admin post and page.Use following code and create wordpressapi.php file and upload this file to wp-content/plugins/ folder.


<?php
/*
Plugin Name:  WordPressapi Meta Box
Plugin URI: http://images.purabtech.in/
Description: Adding the Meta box to admin panel -> post
Version: 0.0
Author: WordPressapi
Author URI: http://images.purabtech.in/
*/

function wordpressapi_meta_box() {
add_meta_box(
'wordpressapi',
'Wordpressapi Box', //Meta box title
'write_in_meta_box',
'post' // You can define here where to add the Meta box(post, page, link)
);
}

function write_in_meta_box(){
echo "Wordpressapi is writing something in admin meta box";
}

if (is_admin())
add_action('admin_menu', 'wordpressapi_meta_box');
?>
add Meta box to wordpress admin
add Meta box to wordpress admin

Go to your Plugin tab and activate the “WordPressapi Meta Box” plugin.
After activating the plugin you are able to see the Meta box on post page.

How to create or add new tables using wordpress theme

With custom professional theme you need to add the custom table in wordpress database, Using this code you can, add new tables using wordpress theme

add new tables using wordpress theme

If you want to add one more table to wordpress database you need to just use the following code.

Open the functions.php file and copy paste the code.

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]


$wordpressapi_db_version = "1.0";

global $wpdb;
global $wordpressapi_db_version;

$table_name = $wpdb->prefix . "liveshoutbox";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {

$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time bigint(11) DEFAULT '0' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url VARCHAR(55) NOT NULL,
UNIQUE KEY id (id)
);";

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);

$welcome_name = "Mr. WordPress";
$welcome_text = "Congratulations, you just completed the installation!";

$insert = "INSERT INTO " . $table_name .
" (time, name, text) " .
"VALUES ('" . time() . "','" . $wpdb->escape($welcome_name) . "','" . $wpdb->escape($welcome_text) . "')";

$results = $wpdb->query( $insert );

add_option("wordpressapi_db_version", $wordpressapi_db_version);

}

[/viral-lock]

register_activation_hook(__FILE__,'YOUR_FUNCTION_NAME');
add new tables using wordpress theme
add new tables using wordpress theme

How to exclude pages from wordpress menu without plugin

In this tutorial we will show you How to exclude pages from wordpress menu without plugin. We given simple code for adding to your theme file which will remove pages from menu.

How to exclude pages from wordpress menu without plugin

Normally when we are creating wordpress theme for showing the pages we code as follows

<?php wp_page_menu('show_home=1&amp;menu_class=page-navi&amp;sort_column=menu_order'); ?>
How to exclude pages from wordpress menu without plugin
How to exclude pages from wordpress menu without plugin

As per this code all pages will get displayed in menu. For showing selected pages check the page id.

and then use following code.

<?php 
wp_page_menu('show_home=1&amp;exclude=5,9,23&amp;menu_class=page-navi&amp;sort_column=menu_order'); 
?>

You are able to see the I added the exclude parameter in wordpress method.
Your selected page id for excluding from menu, you need to just put there with comma separated.

Put this code in your header.php file for showing the menu. You are able to exclude the pages from wordpress menu

add selected pages in wordpress menu

In this tutorial I will show you how to show the only selected pages in menu. add selected pages in wordpress menu using our code sample. which can be added.

add selected pages in wordpress menu

add selected pages in wordpress menu
add selected pages in wordpress menu

Normally when we are creating wordpress theme for showing the pages we code as follows

<?php 
wp_page_menu('show_home=1&amp;menu_class=page-navi&amp;sort_column=menu_order'); 
?>

As per this code all pages will get displayed in menu. For showing selected pages check the page id.

and then use following code.

<?php
 wp_page_menu('show_home=1&amp;include=5,9,23&amp;menu_class=page-navi&amp;sort_column=menu_order'); 
?>

You are able to see the I added the include parameter in wordpress method. Your selected page id you need to just put there with comma separated.

Put this code in your header.php file for showing the menu. Only selected pages will be shown on wordpress menu.

wordpress get child pages of current page

Using following code you can able to display the subpages of parent page. Tutorial for wordpress get child pages of current page. We have given code sample in this article.

<?php $subpages = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0'); ?>

<?php if ($subpages) { ?>
<ul>
<?php echo $subpages; ?>
</ul>
<?php } ?>

Note: This code you need to copy paste in loop only.

Using following code you can able to display the subpages and subpages of that.

<?php
if($post->post_parent)
$subpages = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);
else
$subpages = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
if ($subpages) { ?>
<ul>
<?php echo $subpages; ?>
</ul>
<?php } ?>

Using css you modify the UI of menu.

wordpress get child pages of current page
wordpress get child pages of current page

More details you can found on following page
http://codex.wordpress.org/Template_Tags/wp_list_pages