Link to ‘child pages’ in WordPress with ‘the_post_thumbnail’

Posted in: Programming- Jan 16, 2010 1 Comment

WordPress 2.9 has been released and comes packed with some awesome new features. One of the new feature that I am loving as I have been longing for it, is the post thumbnail. This is a new feature in WordPress that allows you to upload an image to a post that you are creating and attaches to the post as its thumbnail. No longer do you have to use custom fields if all you want is a image for you posts.

It can be used for both posts and pages so I may use both post or page interchangeable throughout this post. I’ve recently used the new ‘Post Thumbnail’ feature in 2.9 to link child pages from a ‘Parent’ page using the Post Thumbnail as an image link.

Wordpress Post Thumbnail

The code below is an example of how to use the ‘get_the_post_thumbnail()’ to list the current page children with its content and a title.

<?php
// get pages
$pages = get_pages("child_of=".$post->ID.'&sort_column=post_title&sort_order=desc&parent='.$post->ID);
// loop through pages pages to get page properties
foreach($pages as $page) {
?>
<div class="wp-caption alignleft">
// create an hyperlink from the get_page_link method and embed the image retrieved from get_the_post_thumbnail in it
<a href="<?php echo get_page_link($page->ID) ?><?php echo get_the_post_thumbnail($page->ID); ?>
// get the title and use it as the caption
<?= $page->post_title ?>
</div>
// get the content
<?php echo $page->post_content; ?>
<?php edit_post_link('Edit.', '', '', $page->ID); ?>
<?php } ?>

Removing ^M From File in Emacs

Posted in: Programming- Dec 06, 2009 1 Comment

If you edit a text file on Windows and you then use it in emacs under a Linux environment you will see the ^M character at the end of each lin.

Do the following to remove it in emacs.

; goto top of buffer
M-x replace-string C-q C-m RET

The control-q will allow you to type control characters into the
input buffer.

Additionally, you could use the dos2unix command.

100 Open Computer Courses

Posted in: Blogs- Dec 05, 2009 1 Comment

While doing my usual random searching through Google I stumbled across a wonderful resource. Something I think every individual not only computer savvy persons or geeks would find useful. It’s a list of 100 open computer courses. Yes, open as in FREE!

The are split into the following categories:

  1. Computer Science and Engineering
  2. Computer Security
  3. Programming
  4. The Web
  5. Software
  6. Information Technology
  7. Communication Technology
  8. Technology in Education
  9. Tech Math
  10. Technology and Society

To see the full list head over to Fred Palmer’s website over at http://fredpalma.com/100-computer-open-courses/.

Converting keystores between JKS and P12

Posted in: Java- Dec 02, 2009 1 Comment

Found these keytool commands that saved me some valuable time working with an already existing .p12 certificate for signing an applet.

It withs in JDK6 and onwards (not in JDK5 and earlier).

JKS → P12

keytool -importkeystore -srckeystore keystore.jks -srcstoretype JKS  -deststoretype PKCS12 -destkeystore keystore.p12

P12 → JKS

keytool -importkeystore -srckeystore keystore.p12 -srcstoretype PKCS12  -deststoretype JKS -destkeystore keystore.jks

Original post by tomas at http://blog.ejbca.org/2008/02/converting-keystores-between-jks-and.html.

Useful Online HTML Tools

Posted in: Blogs- Nov 17, 2009 1 Comment

Ever interested in applying all kind of stuff to text you already have, like converting csv data into a table or reversing the order of words in a sentence without reversing the letters of the words? Well, I have and it has been a nightmare to find online resources to get these quick tasks complete.

As a programmer it is tempting to bake a script to do the trick but sometimes when time is not on your side these tools may come in handy.

Follow this link http://www.textfixer.com/html/csv-convert-table.php to access the tools on the Text Fixer website.

WordPress Automatic Update Issues

Posted in: Linux, Wordpress- Nov 16, 2009 No Comments

When trying to use WordPress automatic update I got this error ‘Error: There was an error connecting to the server, Please verify the settings are correct.’, after trying multiple attempts to rid myself of the problem I had a eureka moment. I thought to myself, “what if it Apache wasn’t seeing the right permissions of the folders?”, and low and behold that was the problem.

Apache was expecting the owner of the folders in the document root to be www-data, I figured this is for some form of security purposes.

How I got rid of the problem

I got rid of the problem by changing the group and owner of my WordPress install folder in apache root to www-data by executing the following command:

cd /yourwordpress_dir/
sudo chown -R www-data:www-data *

How to mount a USB drive in Linux

Posted in: Linux- Oct 17, 2009 No Comments

Most Linux distribution such as Ubuntu automatically mounts your usb drive when it is plugged in. Sometimes we take this for granted and if for some reason the drive doesn’t load we tend to pull our hair out trying to figure out why. If you’re like me then this is a sad reality that you have to overcome perhaps every week.

The other day I was locked out of my Ubuntu after upgrading from Intrepid to Jaunty and GDM decided to take a break. The real problem occurred when I urgently needed my CV to be sent off that day and the most up-to-date CV was on my Ubuntu login, sigh.

What I did

After launching the recovery mode from GRUB I was able to get to a root console. This was good because my girlfriend had her laptop so I could send the CV from her Windows XP system (don’t laugh).

Anyway, here goes… but remember before accessing root you should consider backing up your important files so any mishap wont have you eating your heart out.

Please be careful when running commands under Linux as root, if you are unsure then ask someone before making any changes as root.

Detecting USB hard drive

After you plug in your USB device to your USB port, linux add new device into /dev/ folder. At this stage you are not able to use this device. You need to mount it to your system first in order to be able retrieve any data. To find out what name your device have you can run fdisk command:

# fdisk -l

You will get output similar to this:

Disk /dev/sda: 60.0 GB, 60060155904 bytes 255 heads, 63 sectors/track, 7301 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes     Device Boot      Start         End      Blocks   Id  System /dev/sda1               1        7301    58645251   83  Linux

Creating the mount point

Create directory where you want to mount your device:

mkdir /mnt/sda1

Edit /etc/fstab

To automate this process you can edit /etc/fstab file and add line similar to this:

/dev/sda1       /mnt/sda           vfat    defaults        0       0

Run mount command to mount all not yet mounted devices. Keep in mind that if you have more different USB devices in you system, device name can vary!!!

# mount -a

Original article: http://www.linuxconfig.org/Howto_mount_USB_drive_in_Linux

Taming Ubuntu : Access shared Ubuntu folders from Windows XP

Posted in: Linux- Jul 26, 2009 No Comments

Ubuntu is a wonderful system especially for those who want to be in control of their operating system. On the other hand, sometimes you just want something to work without the hassle. Here is how to overcome one of those hassle if you or your friends want to share files across an Ubuntu installation.

On Ubuntu

Run the following command on your Ubuntu machine as root.

Please be careful when running commands under Linux as root, if you are unsure then ask someone before making any changes as root.

sudo smbpasswd -a 'yourusername'

Add a password when prompted (can be different from pc password).

On Windows

Simply access \\xxx.xxx.xxx.xxx\. Where xxx.xxx.xxx.xxx can either be the machines’ IP address or name.

When asked for credentials, provide user name, password for samba.

That’s it, you now have access to your Ubuntu system.

Migrating Cforms 2 to Production Server

Posted in: Wordpress- Jul 10, 2009 No Comments

Cforms II is one of the most popular plug-ins considered by WordPress. I recently started using this plug-in for the contact form on any website that I create and it works like a charm. The only problem arise when you want to migrate your local development install to your production server. Here I am presenting a nice little script that I put together to help with fixing the form references after migration.

The Problem

When you migrate your cforms plugin from server to server, cform apparently keeps reference to the initial install which for me caused a lot of problem. For instance, when the website was loading I realise that a file was being referenced from my local server. huh!!! I was curious which plugin was doing this and went straight to the database only to find out that the culprit (with no fingers pointing) was cforms.

These are the references that it keeps:

$cformsSettings['global']['cforms_root']
$cformsSettings['global']['tinyURI']
$cformsSettings['global']['cforms_root_dir']
$cformsSettings['global']['cforms_upload_dir']

Because the cforms data is being saved in the database as serialised data changing these from the database would cause the data to be corrupted and in some instances cause your cforms install useless.

For me, I had both problems, I initially tried to update the data from the database and it got corrupted and I tried using the methods prescribed by cforms to fix this problem but that didn’t work. Cforms method is to disable and enable the plugin or edit the data in the little form that the corrupt data page gives you.

Remember, always backup your wordpress install, both database and files before messing around, especially in production environments.

Also, in cforms, go to global settings and backup all settings.

The Solution to Updating the References

After finding that the problem was with cforms I went into cforms code and found what they were doing and here is the final result. Use this method if you have moved over your installation and want to update the references to your production server.

/**
 * Updates cforms data to reflect the current host that it is on
 *
 * @return
 */
function update_cforms_data() {
	if($cformsSettings['global']['cforms_root'] != WP_PLUGIN_URL . '/cforms') :
		$cformsSettings['global']['cforms_root'] = WP_PLUGIN_URL . '/cforms';
		update_option('cforms_settings',$cformsSettings);
	endif;

	if($cformsSettings['global']['tinyURI'] != get_option('siteurl') . '/wp-includes/js/tinymce') :
		$cformsSettings['global']['tinyURI'] = get_option('siteurl') . '/wp-includes/js/tinymce';
		update_option('cforms_settings',$cformsSettings);
	endif;

	if($cformsSettings['global']['cforms_root_dir'] != WP_PLUGIN_DIR . '/cforms') :
		$cformsSettings['global']['cforms_root_dir'] = WP_PLUGIN_DIR . '/cforms';
		update_option('cforms_settings',$cformsSettings);
	endif;

	if($cformsSettings['global']['cforms_upload_dir'] != WP_PLUGIN_DIR . '/cforms$#$') :
		$cformsSettings['global']['cforms_upload_dir'] = WP_PLUGIN_DIR . '/cforms$#$';
		update_option('cforms_settings',$cformsSettings);
	endif;
}

The Solution to Remove Cforms Totally and Reinstall

Use this method to totally remove cforms data from the database, especially if cforms constantly reports that its data is corrupt and doesn’t give you the option to remove it.

$wpdb->query("DELETE FROM `$wpdb->options` WHERE option_name LIKE 'cforms%'");
$wpdb->query("DROP TABLE IF EXISTS $wpdb->cformssubmissions");
$wpdb->query("DROP TABLE IF EXISTS $wpdb->cformsdata");

Remember to backup your website before messing around.

  • WordPress version: WordPress 2.8.1
  • Cforms version: Cforms 2 10.5.2

My Personal Online Portfolio

Posted in: Uncategorized- Mar 12, 2009 No Comments

JamalahBryan.com (JB) is an expansion of the WordPress Maasahan theme originally created by Padd IT Solution. While most of the original layout was maintained I added a lot of new features to suit my needs along with the color change. The original theme used multiple CSS files to match layout, colours etc., but I prefer to have all my CSS in one stylesheet which is much easier for future editing. Similar to my choice to combine the stylesheets I also changed the implementation of some features.

I added the ability for persons to log in to the website using their existing Facebook username and password or create a JB account if they feel the need to. I also expended the footer to be able to extend the blog features more. The footer now hosts the category links, archives etc. which is convenient than having a menu item for those. The reason is that the website has scope to be expanded to more than just a portfolio, it can be used to represent my virtual world and in order to facilitate this growth I needed to utilize as less menu space as possible :) .

I also added a custom write panel for creating a portfolio item. It allows easier input of project details such as client, company and other useful project details.

Here are the original features of the theme followed by the extended version. You may need to browse both websites to understand the extent of the changes – or maybe they are evident enough.

Original Features:

  • WordPress version 2.7 compatible
  • Twitter Account Integration
  • Built-in Page Navigation
  • Featured Post Gallery
  • Option Page for Easy Customization
  • Feedburner Email Subscriber
  • Popular Posts
  • Tabbed Sidebar
  • Automatic Thumbnail Resizer
  • Adsense Ready
  • Advertisement Blocks Ready
  • Gravatar Enabled

Features added:

  • Single CSS Stylesheet
  • Facebook Login
  • Extended Footer
  • Custom Write Panel for Portfolio Item