vijayjoshi.org - php | javascript | ajax | and all things web

Comment box not visible on a page/post in WordPress 3.2.1

  • October 21st, 2011 Posted by Vijay Joshi in FAQ | Tags:

First of all I will congratulate you on upgrading to wordpress 3.2.1. Having latest version means your site is updated and safe.

Now coming to the point, some of you might have faced this problem. You create a new page or post and do not want to allow comments on that. So you scroll down but cannot find the discussion box. The box which has 2 checkboxes “Allow comments” and “Allow trackbacks and pingbacks”.

To fix this, look at the top right of your screen for the Screen Options button. Click that and you will see a lot of checkboxes there. Click the Discussion  checkbox and close the screen options. Now scroll to bottom of the page and you will find the box sitting there.

Enable comments

WP3.2.1 has several other options like Custom fields, slug, Author which you can also enable from here.


PHP: Get intersecting dates between 2 date ranges

Here is a small code snippet that will give you intersecting dates between 2 date ranges. Say, for example, you have 2 date ranges, 1-Jan-2011 to 31-Mar-2011 and 23-Feb-2011 to 4-May-2011.  This function will give you 23-Feb-2011 to 31-Mar-2011 as result.

Here is the code:

$a1  = "2011-01-01";
$a2  = "2011-03-31";
$b1  = "2011-02-23";
$b2  = "2011-05-04";

$intersection = getIntersection($a1,$a2,$b1,$b2);
if($intersection === false)
{
	echo 'No intersecting dates found';
}
else
{
	echo 'From '.date('d-M-Y', $intersection['start']).' till '.date('d-M-Y', $intersection['end']);
}

function getIntersection($a1,$a2,$b1,$b2)
{
	$a1 = strtotime($a1);
	$a2 = strtotime($a2);
	$b1 = strtotime($b1);
	$b2 = strtotime($b2);
	if($b1 > $a2 || $a1 > $b2 || $a2 < $a1 || $b2 < $b1)
	{
		return false;
	}
	$start = $a1 < $b1 ? $b1 : $a1;
	$end = $a2 < $b2 ? $a2 : $b2;

	return array('start' => $start, 'end' => $end);
}

Above will show the following on browser :

From 23-Feb-2011 till 31-Mar-2011

If the 2 date ranges have any intersecting dates, an array will be returned which will have start and end elements that represent the beginning and end of intersecting range.  Set of dates given below will return false as there are no intersecting dates.

$a1  = "2011-01-01";
$a2  = "2011-03-31";
$b1  = "2011-04-23";
$b2  = "2011-05-04";

$intersection = getIntersection($a1,$a2,$b1,$b2);

This will show

No intersecting dates found

The code is self-explanatory. As you can see, first we have used php function strtotime to convert all dates to timestamps. Then we can compare them easily. This way you can use whatever(allowed) date format you wish.


Book Review: Mastering phpMyAdmin 3.3.x for Effective MySQL Management

Recently I was contacted by Richard from Packt Publication to review their new book “Mastering phpMyAdmin 3.3.x for Effective MySQL Management“. Being a PHP-MySQL developer and an avid reader of technical books myself, I instantly agreed.

It took me a bit longer to read it then I had expected. At first, I had decided to just skim through the important chapters but it was interesting enough to change my decision. I then read all chapters one by one and realized that despite using phpMyAdmin on a daily basis, there is so much more to it that we developers are unaware of.

The author of this book is Marc Delisle, who is contributing to this project for more then 12 years. The book contains 19 chapters and 2 appendices. In my opinion the book can be divided broadly into 5 parts.

Chapter 1 to Chapter 3
I will say these warm up chapters as they cover installation, configuration and overview of phpMyAdmin interface in detail. Experienced users may skip these but beginners should go through each one of them.


Click Here to Read full Article…


Favorite tech links of the week : 17 Jan – 23 Jan, 2011

This post contains some of the useful and interesting tech links I found during last week. To keep up to date with the latest information, subscribe to the feed or follow me on twitter @v08i.

How to write a simple application on jQuery Mobile : http://goo.gl/5DpOO

jQuery Mobile

50 Free Tools and Apps for Web Designers and Developers : http://goo.gl/6YjNL

50 Free tools for developers

10 Useful jQuery Plugins for Images : http://goo.gl/VTk1F

jQuery Image Tools

20 less known Open Source PHP CMS-es : http://goo.gl/cM6f3

php Cms

11 More Things I Learned From the jQuery Source : http://goo.gl/2zBh7

CSSReset : All the most common CSS Reset scripts in one place : http://goo.gl/8OV9E

CSS Resets

JavaScript Slider – TinySlider 2 : http://goo.gl/526cL

js Slider


PHP class for expanding and shortening URLs using Google URL shortener API

I have combined the 2 previous posts for expanding and shortening goo.gl URLs and have created a small class for it. Below is the download link for the class.

Download GAPIClass

Expanding a URL

<?php
include('GAPIClass.php');

$objAPI = new GAPIClass('your_api_key_here');
$result = $objAPI->expand('http://goo.gl/WlFX');
if(FALSE === $result)
{
	echo $objAPI->error;
}
else
{
	echo 'Long URL:'.$result;
}
?>

Shorten A URL

<?php
include('GAPIClass.php');

$objAPI = new GAPIClass('your_api_key_here');
$result = $objAPI->shorten('https://www.packtpub.com/php-jquery-cookbook-to-create-interactive-web-applications/book');

if(FALSE === $result)
{
	echo $objAPI->error;
}
else
{
	echo 'Short URL:'.$result;
}
?>

As I have mentioned earlier that Google recommends an API key. The class has a flag variable called keyWarning. By default it is true and it will show the following warning message if you do not pass an API key while instantiating the class:

Currently you are not using an API key. It is recommended that you use one. Click here to learn more about the API key

To turn this notification off, just use this line:

$objAPI->keyWarning = false;

Download GAPIClass


15 HTML5 resources and tutorials for web developers and designers

Here is a collection of 15 resources on HTML5 that I think will be useful to web developers as well as designers.

What is HTML5? (Infographic)

What Is HTML5

Dive Into HTML5

dive into html5

HTML 5 Demos and Examples

html5 demos

HTML5 Boilerplate :A rock-solid default for HTML5 awesome

html5 boilerplate


Click Here to Read full Article…