Blank page for wp-admin

Just now, I had been in a horrible situation that I can see all my blog pages but when I go to http://worth2read.org/blog/wp-admin/ it appears as blank. That is I am completly locked out of the admin area.

I made a Google search for the solution and confused with lots of solutions that appeared.

However atlast I manged to get my admin page back, the solution that worked for me is as follows…

I checked the functions.php in my theme folder. There were some spaces at the top and bottom of the page. i deleted it.

I got my admin page back so that I can post this for you now.

I am posting it here thinking if anyone else came through such situation, it will be helpful for them.

Adding new widgets in wordpress themes

We can add new widgets by using functions.php in the theme folder.

For example I can add “Services I offer and Google Adsense in 2 ways
to the sidebars.

1. Code both to the page sidebar.php
3. Create widgets using functions.php file in the theme folder

Following code shows how I added a simple Adsense widget using functions.php

if (function_exists(‘register_sidebar’))
{
register_sidebar_widget(__(‘Adsense’), ‘google_widget’);
}

function google_widget() {
echo $before_widget;
echo $before_title;

echo”<li><h2>Sponsors</h2></li>”;
echo $after_title; 
?>
 <ul>
 <li>

Here comes Adsense code

</li>
 </ul>
 <?php echo $after_widget; 
}

function init_adsense(){
    register_adsense_widget(“Sponsors”, “google_widget”);    
}

add_action(“plugins_loaded”, “init_adsense”);

The above code gives a simple widget named adsense in the widget panel. From the widget list I can add it to the sidebar without disturbing sidebar.php file.

Update:

Just now, I  noticed another method,  if the widget contains text or HTML only. In such cases you can use text widgets. Add the already existing “Text widget”.

In the example above give the title as “Sponsors” and write adsense code in the box. It is the easiest way if the widget you are making contains only text or HTML.

Adding Separate boxes for wordpress excerpts

In most of the themes the post container lists all the excerpts of the most recent posts in the home page. The following code will help you to break up each post into separate boxes.

Example: Theme Home page Preview

Using css we can make a 10px gap in-between each post, where the background of the page shows through.

In the page index.php we have

————————————-

<div id=”content”>

<?php while (have_posts()) : the_post(); ?>

   <div class=”post” id=”post-<?php the_ID(); ?>”>

 <div class=”title-bg”>   <h2 class=”title”>

<a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></a>

</h2></div>
 <div class=”entry”>

     <?php the_excerpt(); ?>

     <p class=”links”>

<a href=”<?php the_permalink() ?>” class=”more”>&laquo;&laquo;&nbsp;&nbsp;Read More</a></p>

    </div>   </div>

  <?php endwhile; ?>

——————————————–

I was just copying the index page. Ignore the div tags you don’t want , but the following css code for content and post will help to add a separation between each post.

—————————–

#content {

float: left;

width: 600px;

border-left: 1px #BBBBBB dashed;

margin-left:10px;

}

.post {

padding-bottom: 15px;

line-height: 200%;

background-color:#FFFFCC;

margin-top:10px;

}

——————–

Here “background-color:#FFFFCC;” gives an yellow background and “margin-top:10px;” gives a gap with the background color mentioned in #content background color.

In this example it is white.

Changing background color of an image using Photoshop

Step1: Open Photoshop, click on the “Set background color”

Step2: Click File –> Add New, Set Background contents as “Background color”

Step3: Open up your image by selecting file -> open

As you can see there are now two windows on your work space.

Now follow the following steps to make the background transparent. Click on the window of your image and then…

Step 4: Double click on the layer in the layers palette on the right hand side of the screen by default. Click OK on the box that comes up.

Step5: Grab the magic wand tool and click on the white background.

Step6: Hit Delete on your keyboard.

Step7: Hit Ctrl + D on your keyboard.

Step8: Hit Ctrl + Shift + S on your keyboard and select CompuServe (*.gif) in the File Type dropdown. And select where you want your image to be saved.

Now you can drag your transperant object to your colourd canvas, for this use the Move tool.

Finally save it. Done !

How to Detemine The Number Of Fridays In A Month

The following code determines the number of Fridays in a month :

$year = 2008;
$month = 1; //Aug
$day = 1;
$startDate = mktime(0, 0, 0, $month, $day, $year);
$NoD = date( “t”, $startDate);

While(date( “D”, $startDate) != “Fri”) //find first Friday
{
$day++;
$startDate = mktime(0, 0, 0, $month, $day, $year);
}
$day–;
$days = ceil(($NoD-$day)/7);
echo “$days Fridays”;

Replace the $month=1; to the number of the month you want.

Function to Get the variable name

This is a PHP Function to get the name of the variable (not the value) :

function getvarname(&$var)
{
$ret = ”;
$tmp = $var;
$var = md5(uniqid(rand(), TRUE));

$key = array_keys($GLOBALS);
foreach ( $key as $k )
if ( $GLOBALS[$k] === $var )
{
$ret = $k;
break;
}

$var = $tmp;
return $ret;
}

$another = ‘test’;
$testvar = ‘test’;
echo getvarname($testvar); //echoes ‘testvar’
?>

How to display how many weeks and days left when a start date and an end date is given?

Following code in php displays how many weeks and days left when a start date and an end date is given:
function daysWeeks($start,$end)
{
$days_left=$end-$start;
$weeks = (int) ($days_left / 7) ;
$days = $days_left % 7;
echo “$weeks weeks and $days days left!”;
}
$start=”05/08/2008″;
$end=”25/08/2008″;
daysWeeks($start,$end);

Using 301 Redirect To Redirect A Webpage

When I hosted the site, the pages were html files. Later to add more functionality I converted them to php files.

But search engines have already indexed those .html files. So when a visitor comes after a search in Google, the ‘ File Not Found’ error is displayed.

We can avoid this using 301 redirect.

.htaccess file
When a visitor searches for a webpage, the webserver looks for .htaccess file. This file contains information about redirection, security etc.

If your server already has this file always update it rather than replacing it with a new file.

If the server does not have the .htaccess file open a .txt file and save it as .htaccess file.

Redirect a webpage using 301 Redirect
Example :

redirect 301 /Kids.html http://www.worth2read.org/kids.php

Edit the .htaccess file or open notepad, add redirect 301 statement, save it as .htaccess file.

The search engines won’t read the .htaccess file, but follow the rules that are created in .htaccess.

We can test this by typing the old URL, for example www.worth2read.org/kids.html

Actually this file is not in the server. Instead kids.php is there.

When Google updates it next time, the new file name will replace the old file.

The notes I am writing here help me (perhaps others as well) to remember the solutions I figured out for the Wordpress / PHP issues that I have come across …