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:

1<?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>

01<?php
02$long_url = 'http://images.purabtech.in/';
03$short_url = get_short_url($long_url,'hexio');
04echo $short_url;
05echo '
06';
07$short_url = get_short_url($long_url,'isgd');
08echo $short_url;
09echo '
10';
11$short_url = get_short_url($long_url,'trim');
12echo $short_url;
13echo '
14';
15 
16?>

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.

01if (navigator.geolocation) {
02/* geolocation is available */
03} else {
04alert("I'm sorry, but geolocation services and HTML5 are not supported by your browser.");
05}
06 
07or
08 
09if (window.postMessage) {
10/* postMessage method is available */
11} else {
12alert("I'm sorry, but postMessage method and HTML5 are not supported by your browser.");
13}

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:

01[kapil@kapilk-pc ~]$ cd /var/www/html/yii/
02[kapil@kapilk-pc yii]$ cd framework/
03[kapil@kapilk-pc framework]$ ./yiic webapp ../testdrive
04PHP Warning:  Module 'memcache' already loaded in Unknown on line 0
05Create a Web application under '/var/www/html/yii/testdrive'? [Yes|No] y
06unchanged css/bg.gif
07unchanged css/main.css
08unchanged css/form.css
09unchanged css/print.css
10unchanged css/screen.css
11unchanged css/ie.css
12unchanged index.php
13unchanged themes/classic/views/.htaccess
14unchanged index-test.php
15unchanged protected/components/Controller.php
16unchanged protected/components/UserIdentity.php
17unchanged protected/yiic.php
18unchanged protected/config/main.php
19unchanged protected/config/console.php
20unchanged protected/config/test.php
21unchanged protected/yiic
22unchanged protected/models/ContactForm.php
23unchanged protected/models/LoginForm.php
24unchanged protected/data/schema.mysql.sql
25unchanged protected/data/testdrive.db
26unchanged protected/data/schema.sqlite.sql
27unchanged protected/.htaccess
28unchanged protected/controllers/SiteController.php
29unchanged protected/yiic.bat
30unchanged protected/views/site/pages/about.php
31unchanged protected/views/site/index.php
32unchanged protected/views/site/error.php
33unchanged protected/views/site/contact.php
34unchanged protected/views/site/login.php
35unchanged protected/views/layouts/main.php
36unchanged protected/tests/bootstrap.php
37unchanged protected/tests/WebTestCase.php
38unchanged protected/tests/phpunit.xml
39unchanged protected/tests/functional/SiteTest.php
40 
41Your application has been created successfully under /var/www/html/yii/testdrive.
42[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.

01<?php
02//The Query
03query_posts('posts_per_page=1');
04 
05//The Loop
06if ( have_posts() ) : while ( have_posts() ) : the_post();
07 
08global $post;
09$thePostID = $post->ID;
10$custom_read_more = get_post_meta($post->ID, 'custom_read_more', true);
11 
12if ($custom_read_more) {
13add_post_meta($thePostID, 'custom_read_more', 'You need to read this article');  //custom read more value
14}
15 
16endwhile;
17endif;
18?>
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.

1<?php $custom_read_more = get_post_meta($post->ID, 'custom_read_more', true); ?>
2 
3<?php if (!$custom_read_more) { $custommore = 'Read More &raquo;'; } ?>
4 
5<?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.

01<?php
02/*
03Plugin Name:  WordPressapi Meta Box
04Plugin URI: http://images.purabtech.in/
05Description: Adding the Meta box to admin panel -> post
06Version: 0.0
07Author: WordPressapi
08Author URI: http://images.purabtech.in/
09*/
10 
11function wordpressapi_meta_box() {
12add_meta_box(
13'wordpressapi',
14'Wordpressapi Box', //Meta box title
15'write_in_meta_box',
16'post' // You can define here where to add the Meta box(post, page, link)
17);
18}
19 
20function write_in_meta_box(){
21echo "Wordpressapi is writing something in admin meta box";
22}
23 
24if (is_admin())
25add_action('admin_menu', 'wordpressapi_meta_box');
26?>
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.”]

01$wordpressapi_db_version = "1.0";
02 
03global $wpdb;
04global $wordpressapi_db_version;
05 
06$table_name = $wpdb->prefix . "liveshoutbox";
07if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
08 
09$sql = "CREATE TABLE " . $table_name . " (
10id mediumint(9) NOT NULL AUTO_INCREMENT,
11time bigint(11) DEFAULT '0' NOT NULL,
12name tinytext NOT NULL,
13text text NOT NULL,
14url VARCHAR(55) NOT NULL,
15UNIQUE KEY id (id)
16);";
17 
18require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
19dbDelta($sql);
20 
21$welcome_name = "Mr. WordPress";
22$welcome_text = "Congratulations, you just completed the installation!";
23 
24$insert = "INSERT INTO " . $table_name .
25" (time, name, text) " .
26"VALUES ('" . time() . "','" . $wpdb->escape($welcome_name) . "','" . $wpdb->escape($welcome_text) . "')";
27 
28$results = $wpdb->query( $insert );
29 
30add_option("wordpressapi_db_version", $wordpressapi_db_version);
31 
32}

[/viral-lock]

1register_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

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

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

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

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

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

and then use following code.

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

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