Thursday, November 10, 2011

Handy code for City, State, Zip, Country selector via JS


Today I got a new project to work on the client needs a registration form having Country, City, State and Zip Code including the Geo Location and Latitude. There was a location based searching for the system, so what we needed was to do a full validated geo fields without any kind of errors. I tried to do it via Ajax and so that  it will be the best for validation as well as interactive to the user also.
While searching  I got something which is very handy from geonames. I tried to do API calls to their web services so that I can get whatever details I want from them.

Sample API Call


The result obtained was a JSON string, 

jQ({"totalResultsCount":1,"geonames":[{"alternateNames":[{"name":"তিরুবনন্তপুরম","lang":"bn"},{"name":"ত্রিবানদ্রাম","lang":"bpy"},{"name":"Thiruvananthapuram","lang":"de"},{"name":"Thiruvananthapuram","lang":"en"},{"name":"Thiruvananthapuram","lang":"eo"},{"name":"Thiruvananthapuram","lang":"fi"},{"name":"Thiruvananthapuram","lang":"fr"},{"name":"तिरुअनन्तपुरम्","lang":"hi"},{"name":"Thiruvananthapuram","lang":"id"},{"name":"ティルヴァナンタプラム","lang":"ja"},{"name":"http://en.wikipedia.org/wiki/Thiruvananthapuram","lang":"link"},{"name":"തിരുവനന്തപുരം","lang":"ml"},{"name":"Trivandrum","lang":"nl"},{"name":"Trivandrum","lang":"pl"},{"name":"Thiruvananthapuram","lang":"pt"},{"name":"Thiruvananthapuram","lang":"ro"},{"name":"Тируванантапурам","lang":"ru"},{"name":"तिरुवनंतपुरम","lang":"sa"},{"name":"Thiruvananthapuram","lang":"sv"},{"name":"திருவனந்தபுரம்","lang":"ta"},{"name":"特里凡得琅","lang":"zh"}],"countryName":"India","adminCode1":"13","fclName":"city, village,...","score":28.883577346801758,"countryCode":"IN","lng":76.9166667,"adminName2":"","adminName3":"","fcodeName":"seat of a first-order administrative division","adminName4":"","timezone":{"dstOffset":5.5,"gmtOffset":5.5,"timeZoneId":"Asia/Kolkata"},"toponymName":"Thiruvananthapuram","fcl":"P","continentCode":"AS","name":"Thiruvananthapuram","fcode":"PPLA","geonameId":1254163,"lat":8.4833333,"adminName1":"Kerala","population":784153}]});

This API call can be used as an auto-suggestion for a text field which will be very handy for the developer instead of typing all the city, state, country data to the database.

You can also use the web services of geonames for geo location extraction,
http://www.geonames.org/export/web-services.html



GeoNames is mainly using REST webservices.

And finally the AIO,

Important:

I’m sure that this will be the best for the one who seeks this.

Tuesday, November 8, 2011

WordPress code snippets - Cheat Sheet

Here is a list of WordPress Code Snippets that can be used in your every day coding phase. If you take a print out of it then it will be the best so that you can keep it your self and distribute among others. 
 
PHP Snippets for Header
Title of the site < ?php bloginfo(’name’); ? >
Title of specific post or page < ?php wp_title(); ? >
The style.cssfile's theme location < ? php bloginfo(’stylesheet__url’); ? >
Pingback URL for the site < ?php bloginfo('pingback_url');? >
Location for the site's theme file < ?php bloginfo(’template_url');? >
Wordpress version for the site < ?php bloginfo('version');? >
Atom URL for the site < ?php bloiginfo('atom_url');'? >
Exact URL for the site < ?php bloginfo('rss2_url');? >
Name of the site < ?php bloginfo('name');? >
Html version of the site < ?php bloginfo('htm1_type');? >
Charset parameter of the site < ?php bloginfo('charset');? >

Basic Template Files
Style sheet file style.css
Homepage file index.php
Single post page file single.php
Archive/category file a1-chive.php
Search form file searchform.php
Search content file search.php
Error page file 404.php
Footer content file footer.php
Comments template file comments.php
Header content file header-.php
Sidebar content file sideba:-.php
Single page file page.php

Extra Stuff
Custom permalinks /%postname%/
Include any file < ?php include(TEMPLATEPATH .‘/x’); ? >
Value for search form < ?php the_search_query(); ? >
Prints out message < ?php _e(’Message’); ? >
Displays the register link < ?php wp_register(); ? >
Displays the login/logout link < ?php wp_loginout(); ? >
Divides the content into pages
Cuts of" the content <1--more-->
Meta for administrators < ?php wp_meta(); ? >
Time to load the page < ?php timer_stop(1); ? >
Queries to load the page < ?php echo get_num_queries(); ? >

PHP Snippets for Templates
Author of a specific post or page < ?php the_author(); ? >
Content of the posts < ?php the_content(); ? > ‘
ID of a specific post or page < ?php the_ID(); ? >
Checks if there are posts < ?php if(have_posts()) : ? >
Link to edit a specific post or page < ?php edit _post_link(); ? >
Shows posts if posts are available < ?php while(have__posts()) : the _post(); ? >
Links from the blogroll < ?php get_links_list(); ? >
Closes the 'while' PHP function < ?php endwhile; ? >
Comment.php files content < ?php comments_template(); ? >
Closes the 'if PHP function < ?php endif; ? >
List of pages of the site < ?php wp_list_pages(); ? >
Header.php file's content < ?php get_header(); ? >
List of categories for the site < ?php wp_list_cats(); ? >
Sidebar.php files content < ?php get_sidebar(); ? >
Url to the next post < ?php next _post_link(' %link ') ? >
Footer.php file's content < ?php get_footer(); ? >
Url to the previous post < ?php previous _post_link('%link') ? >
The date in '08-18-07' format < ?php the_time('m-d-y') ? >
The built-in calendar < ?php get_calendar(); ? >
Link for the comments on the post < ?php comments_popup_link(); ? >
List of archives for the site < ?php wp_get_archives() ? >
Title of a specific post or page < ?php the_title(); ? >
Next and previous post link < ?php posts_nav_link(); ? >
Url of a specific post or page < ?php the _permalink() ? > ‘
Site’s description < ?php bloginfo(’description’); ? >
Category of a specific post or page < ?php the_category(', ') ? > ‘

Popular Posts