Posted: Apr 23 | Filed under: Wordpress

If you should ever come in the situation that you want a default custom field on your “write page” you should first of all create a draft with your default custom fields.
After that go to your phpMyAdmin interface and lookup the postid.
Once you got the postid simply goto “wp_postmeta” and find the postid of that draft. Change the id to zero.
VoilĂ  now you will have the custom field you defined in the draft at your write page. This is especially handy if you always need the same custom field because you can simply copy it.

  Posted: Apr 19 | Filed under: Wordpress

To realize a multilingual wordpress you have to follow the following steps:

1. Check if your theme is ready for localization.

To do that open for example comments.php in your theme folder and search for text that is currently displayed on your blog e.g.”Leave a comment”.

If it’s looking similar to

 " _e("Leave a comment", "mytheme");  "

then your theme should already be ready for localization.

2. Optional

If not then you will have to wrap the “_e” around every text passage in your theme. Replace mytheme with your theme’s name. Also don’t forget that this has to be inside a php statement!

You can do it like that:

<?php  _e("Text", "mytheme"); ?>

Inside a function:

'__('Text', "mytheme")'

e.g.

 comments_rss_link(__('Subscribe to the comments via RSS Feed', "mytheme"));

3. Add load_theme_textdomain to your functions.php

This is a very important step because it will load the text via gettext before sending out the headers. Add the following at the very first line of your functions.php inside your theme folder: (if you don’t have one create a functions.php!)

 <?php load_theme_textdomain('mytheme'); ?>
  Posted: Apr 13 | Filed under: General

The bash_history is a file that saves your command line entries. If you execute any commands via SSH it will save them in the file .bash_history, so that you are able to quickly execute older commands again.

However you can imagine that this is a security risk you can easily avoid by cleaning the history after you logout.

First of all you should locate your bash_history.
Nothing easier than that, simply execute:
“locate bash_history” via SSH and it will show you where it is.
The File “.bash_profile” should be in the same directory.

Now either use a SSH editor like nano to open the file “.bash_profile” or simply open it via WINSCP. This is really a personal taste but I prefer using nano instead of vim because it’s easier to handle. Execute “nano .bash_profile”. If it’s in a subdirectory then you will have to “cd” there.

Now add the following lines at the very end:

export HISTSIZE=100
export HISTFILESIZE=100
unset HISTFILE

You can change “100″ to the number of commands you want to keep while being logged on. If you logout it will “unset” everything and delete your commands.
VoilĂ ! Now it will automatically delete your bash_history if you logout.

  Posted: Apr 10 | Filed under: Cpanel/WHM

The following commands are very useful to make sure that imap is running properly:

 

/scripts/restartsrv_courier
Simple restart of courier.

 

/scripts/convert2maildir
This will convert your mail boxes into a proper format.

 

/scripts/courierup –force
This will make sure that the latest imap is running.

  Posted: Apr 10 | Filed under: Cpanel/WHM

If you are on a WHM/Cpanel server and you might want to update your cpanel including all components like FTP, Courier, etc., then you can run the following command via SSH:

 

/scripts/upcp --force

 

This will not only make sure you have got the latest Cpanel software, but will also “auto-heal” your system, which means that it will fix some server settings.

  Posted: Apr 07 | Filed under: Wordpress

If you are looking for a solution to exclude subcategories, here is a very simply way:

$categories= get_categories();
foreach ($categories as $cat) {
if($cat->category_parent == 0){
DO WHATEVER YOU WANT TO DO 
}
}

You could use this code to make a dropdown box without subcategories.
Here is the wordpress reference for “get_categories” with an example of a categories dropdown box.
Dropdown box

  Posted: Mar 30 | Filed under: Wordpress

One of the most important thing for a wordpress developer is to know where the user is right now. The wordpress reference has a very important site that shows all the necessary functions to do that.

 

Conditional Tags

 

That links is definetly a must-have-bookmark for every WP developer!

  Posted: Mar 29 | Filed under: General

Today I had to convert a multidimensional array and found a very simply solution at PHP.net that I want to share with you.

A multidimensional array is an array that stores arrays. Usually a normal array is easier to handle, that’s why converting the array is a good solution.

That will turn this:

Array
(
[1] => Array
(
[0] => 1
[1] => 2
)
[2] => Array
(
[0] => 3
[1] => 4
)
)

Into this simple array:


Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)

Here’s the very efficient and short code:

function flatten_array($value, $key, &$array) {
if (!is_array($value))
array_push($array,$value);
else
array_walk($value, 'flatten_array', &$array);
}

Then you are able to to use “array_walk”, simply rename $oldarray to the name of your multidimensional array!

$newarray = array();
array_walk($oldarray, 'flatten_array', &$newarray);

 

Happy converting !

  Posted: Mar 27 | Filed under: Wordpress

A lot of people are sick of the wordpress editor because it will mess up their posts.

Here is the solution that worked for me. I do not say that this will work for anyone. A lot of people don’t want to turn of the Visual Editor to quickly edit their posts, but you will have to.

Turn it off Go to “Users” -> “Your Profile” and uncheck “Use the visual editor when writing”.

  Posted: Mar 27 | Filed under: Wordpress

Here’s the code to save the current wordpress tag, if you are on a “tag site”:

<?php $current_tag = single_tag_title(”", false); ?>

 

Taken from the wordpress reference.