Friday, 30 May 2014

Wordpress Text Widget Logic

The Widget Logic uses Conditional tags that controls where a widget should appear and conversely where it should not. We can write more than one conditional statements inside widget logic.
we’ll put our WordPress Conditional tags inside widget logic input filed as shown in figure.

Different Conditional statements syntax: 

global $post;

if((is_page('page id') || ($post->post_parent=="page id"))){
return (is_page('page id') || ($post->post_parent=="page id"));
}

Display widget on page 

is_front_page() : on front page.
is_home() : on home page.
is_page('page name') : on given page name.
is_page('page id') :on given page id.
is_page( array('abc', 'xyz', 50, 75) ) : on array of multiple pages.
is_front_page() || is_page('xyz') : on front page and xyz page
is_page('2715') || ($post->post_parent=="2715") : on page id 2715 and its sub-pages.

Display widget on Post
is_single('Abc') : on given post name.
is_single(451) : on given post id.
is_single( array('ABC', 45) ) : on array of multiple post name and id.

Display widget on Category
in_category('abc') : on given category name.
in_category( array('abc', 'xyx', 'Cat1') ) : on array of multiple category.

Thursday, 29 May 2014

Close the Browser forcefully using javascript

<HTML>
<head>
<script language="JavaScript">
//window.onbeforeunload = confirmExit(); // close on befor load
function confirmExit()
{
window.close();
}
</script>
</head>
<body>
<input type="button" id="B1" value="Test" onclick="javascript:confirmExit();">
</body>
</HTML>

Friday, 23 May 2014

Array filter in PHP

Function name : array_filter()
Discriptyion :  Used to filters elements of an array using a callback function

Syntex : array array_filter ( array $array = array() [, callable $callback = Function() ] )

Examples 1 : Filter odd and even number from array elements

<?php
$array1 = array("p1"=>1, "p2"=>2, "p3"=>3, "p4"=>4, "p5"=>5);
$array2 = array(16, 17, 18, 19, 20, 11, 12);

echo "Odd :\n";
print_r(array_filter($array1, "odd"));
echo "Even:\n";
print_r(array_filter($array2, "even"));
?>

Output:
Odd :
Array
(
[a] => 1
[c] => 3
[e] => 5
)
Even:
Array
(
[0] => 16
[2] => 18
[4] => 20
[6] => 12
)

Examples 1 : Filter null,blank value and false from array elements

<?php
$array1 = array(
0 => 'test',
1 => '',
2 => 200,
3 => null,
4 => false,
5 -> -1
);

print_r(array_filter($array1));
?>

Output:

Array
(
[0] => test
[2] => 200
[3] => -1
)

Wednesday, 21 May 2014

Set minDate older than current date in jquery date picke

<HTML>
<input name="date" type="text" id="date">
</HTML>

<Script>
var d = new Date();
d.setDate(d.getDate()-60);
$("#date").datepicker({
minDate : d
});
</script>

Live Demo : < href="http://jsfiddle.net/pankaj7418/t9RED/1/">http://jsfiddle.net/pankaj7418/t9RED/1/