Skip to content

Instantly share code, notes, and snippets.

@deepak-rajpal
deepak-rajpal / mysql-import.html
Last active September 18, 2015 14:26
Importing Big/Large database file into mysql db
1) Use phpmyadmin > (use compressed file) > check partial import and go
2) Using cmd
C:\wamp\bin\mysql\mysql5.0.51b\bin>mysql -u root -p YourDatabaseName < YourFileName.sql
http://stackoverflow.com/questions/14846879/import-sql-file-by-command-line-in-windows-7
3) Best - using BigDumb script
http://www.ozerov.de/bigdump/usage/ (Tested 118 mb data (.sql file import) in 5-10 sec)
4)
@deepak-rajpal
deepak-rajpal / register-custom-menu-wp.php
Created September 14, 2015 16:06
Commonly Used and Popular WordPress Functions
<?php
/* Starts: Registering Custom Menus */
function register_custom_menus() {
register_nav_menus(
array(
'header-top-area-1' => __( 'Header Top Area - 1' ),
'header-top-area-2' => __( 'Header Top Area - 2' ),
'site-navigation-menu' => __( 'Site Navigation Area' ),
'footer-area-1' => __( 'Footer Area' ),
)
@deepak-rajpal
deepak-rajpal / interest-rates-dropdown.php
Last active September 14, 2015 14:26
Creating Unique dropdown list of Interest Rates (from XML), Creating Unique table (with content/rows) for each Interest Rate and then display table depending on the selected rates from dropdown
<!-- Create Interest Rates Dropdown. Selecting any rate will display table of that interest rate data -->
<select name="interestItems" id="interestItems" class="styledGrayMedium" selected="selected">
<option value="All">All</option>
<?php
$rate_type_list = array();
if ($xml) {
foreach ($xml->children() as $second_gen) {
foreach ($second_gen->children() as $third_gen)
{
// 2 ways to collect different interst rate types 1) using $third_gen->type or extract from $third_gen->name
@deepak-rajpal
deepak-rajpal / url-keyword-parsing.php
Last active September 14, 2015 12:16
Converting space and slash into commas from URL variable and making a valid next URL
<?php
// For an current page/URL is: http://mysite.com/currency-pair-detail?fullname=US Dollar / Indonesian Rupiah FX Spot Rate
// Feed URL logic, first check from url keywords, then check url from shortcode else set default one.
if (isset($_REQUEST['fullname']) && $_REQUEST['fullname']!="") {
// create a feed url by finding keywords from current url (fullname variable)
$headlines_keywords = $_REQUEST['fullname'];
$headlines_keywords = strstr($headlines_keywords, 'FX Spot Rate', true);
$headlines_keywords = str_replace(" / ",",", $headlines_keywords);
$headlines_keywords = str_replace(" ","%2B", $headlines_keywords);
@deepak-rajpal
deepak-rajpal / autocomplete-dropdown-using-js-array.php
Created September 14, 2015 11:27
Rates Autocomplete dropdown and redirect:-- > 1) Create JS Arrary using xml elements fetch, 2) Fetch array and autocomplete dropdown, 3) Based on dropdown information, redirect into the commodity detail page.
<body>
<script>
// JS array (commodityList) to store all Commodity for autocomplete dropdown.
var commodityList = new Array();
// JS object to store all Commodity with additional information. Useful to create form action url after submit.
var commodityInfo = new Object();
</script>
<script>
var commodityName = "Soybeans (comp) cvoi1";
var type= "Grains";
@deepak-rajpal
deepak-rajpal / wp-activation-deactivation-hook.php
Last active September 10, 2015 05:23
WordPress - Sample activation deactivation hook
<?php
class Easy_Newsletter{
// Constructor
function __construct() {
add_action( 'admin_menu', array( $this, 'easy_n_add_menu' ));
register_activation_hook( __FILE__, array( $this, 'easy_n_install' ) );
register_deactivation_hook( __FILE__, array( $this, 'easy_n_uninstall' ) );
}
@deepak-rajpal
deepak-rajpal / wp-image-resize.txt
Last active September 6, 2015 16:58
WordPress Image Resize Tips, Code and Scripts
1) add_image_size() doesn't generate the thumbnail, it just registers an image size as available to WordPress. so if you are using many different size of thumbnails on homepage, using add_image_size will generate a new registered size image with each post's featured image. Therefore, there will be so many images created on server. Sometimes, not all post image need to resize, so unnecessary images.
2) so instead of create a new sized image for every image, we can resize image on the fly. So that only certain category images that required can be resized. earlier we use timthumb for this. But it has encounterd with some vulterabilities so can not be used. Other options are
3) Aqua Resizer
4) vt_resizer (default version does not work with wp multisite, but modified scrips are available)
@deepak-rajpal
deepak-rajpal / rss-fetch-feed.php
Created September 4, 2015 15:20
RSS XML News Feeds Fetch using WordPress fetch_feed() - Best and Tested
<?php
/* =============== Starts: Shortcode to display RSS Feeds using WordPress fetch_feed() ================== */
/* Shortcode Example: [news_list]
Example Feed URL:
=> 'http://online.wsj.com/xml/rss/3_8068.xml'
=> 'http://dealbook.nytimes.com/feed/'
=> 'http://www.bloomberg.com/feed/bview/'
*/
function news_page_fx( $atts ) {
extract( shortcode_atts( array(
@deepak-rajpal
deepak-rajpal / custom-tab-type-with-column.php
Created September 4, 2015 12:08
Regsiter Custom Post Types - Taxonomies - Add Taxonomies Column (with Dropdown Sorting) in admin to sort data
<?php
/* Starts: Register Custom Post Type for tab management */
function tab_type_post() {
$labels = array(
'name' => _x( 'Tab-Posts', 'post type general name' ),
'singular_name' => _x( 'Tab-Post', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Tab-Post' ),
'edit_item' => __( 'Edit Tab-Post' ),