WordPress post navigation with customized post loop using meta_key

What’s that?

I wrote this stupid navigation workout because I can’t found any of good practice on writing customized content unless I go for WordPress 3.0. When I create several content handling in a themes, such as photo post or video post, I was relied on the meta_key value to determine which style to be used.

For each single post or post loop, it’s no problem at all, however when i tried to do navigation on the single.php. I noticed that there is no way to treat them as typical blog post.

        $category = get_the_category();
        $catID = $category[0]->cat_ID;

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content();?>
        <?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
        <?php endif; ?>

<!-- Start navigation here -->
global $post;
$mypostlist = array();
$currentPID = $post->ID;
$myNav[] += $currentPID;  //insert the current post into first array position
$myposts = get_posts('exclude='.$post->ID.'&orderby=date&order=desc&numberposts=-1&meta_key=my_post_type&meta_value=1&offset=1&category='. $catID .'');
setup_postdata($post); // exclude current post from the loop
foreach ($myposts as $post) {
       $myNav[] += $post->ID; // insert the result into the loop
$current = array_search($post->ID, $myNav);
$prevID = $myNav[$current-1];
$nextID = $myNav[$current++];

<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="alignleft"><a href="<?php echo get_permalink($prevID); ?>"
  title="<?php echo get_the_title($prevID); ?>">Previous</a>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright"><a href="<?php echo get_permalink($nextID); ?>"
 title="<?php echo get_the_title($nextID); ?>">Next</a></div>
<?php } ?>
</div><!-- .navigation -->


howto create GFS on DRBD network disk mirroring


This howto will cover how to create a DRBD disk set with GFS concurrent disk access setup.


DRBD disk mirroring benefit as a shared SAN disk to archive higher service resilience with low cost hardware component. Alternately, it may be configured for backup purpose with it’s flexibility.


1. RedHat Cluster Suit and GFS packages


2. drbd83 package

yum install drbd83

3. Create a partition on both node with using same size, we use [sda5] for this show case.
Continue reading “howto create GFS on DRBD network disk mirroring”

PHP sample: howto distinct the subarray value

The Code

$myvars = array(
"myvar1" => array("stock" => "C", "mykey" => "1", "name" => "apple"),
"myvar2" => array("stock" => "D", "mykey" => "1", "name" => "apple"),
"myvar3" => array("stock" => "E", "mykey" => "1", "name" => "apple"),
"myvar4" => array("stock" => "F", "mykey" => "1", "name" => "apple"),
"myvar5" => array("stock" => "G", "mykey" => "2", "name" => "orange"),
"myvar6" => array("stock" => "H", "mykey" => "2", "name" => "orange"),
"myvar7" => array("stock" => "I", "mykey" => "2", "name" => "orange"),
"myvar8" => array("stock" => "J", "mykey" => "2", "name" => "orange"),

$_myvars = array();
foreach($myvars as $myvar)
if ( !in_array($myvar['mykey'], $_myvars) )
echo $myvar['mykey'] . "\n" . $myvar['name'] . "\n";  
$_myvars[] = $myvar['mykey'];

The Result

1 apple 2 orange

Openldap recovery howto

If you are experiencing LDAP errors or startup without error but no ldap port (389|636) is listening for service and you have tried restarting the LDAP server by running /etc/init.d/ldap restart, then you should try running the following recovery procedure:

Typical corruption

1. Stop the LDAP server:

/etc/init.d/ldap stop

2. Run the daemon manually with debug flag

/usr/sbin/slapd -u ldap -h ldap:// -d 256

If the database is corrupted, it may stop at database initiation.
Continue reading “Openldap recovery howto”

Apache Web Load Balancing howto

Setup Overview

A apache load balancer www.mydomain.com setup for redirect incoming request to two underlying web server www1.mydomain.com, www2.mydomain.com.


Host#1 www1.mydomain.com:
Host#2 www2.mydomain.com:
The apache load balancer instance www.mydomain.com running on RedHat Cluster floating IP or you can activate it on either one server using IP alias without using Cluster Suit.

Load balancer setup www.mydomain.com

Parameters Value Description
ProxyPass balancer://<NAME>/ Define your cluster name
stickysession BALANCEID | PHPSESSIONID | JSESSIONID Define your preferred session sticky method,
BALANCEID likely by source IP

PHP|JSESSIONID require to add extra session header on the node member web server

nofailover On | Off If your web servers do not support session replication, turn this flag on in order to NOT failovering the current session to other member while the node is failed.
route node name
lbmethod byrequests | bytraffic | bybusyness
ProxyPreserveHost On | Off While application using mod_rewrite for friendly URL and it rely on the REQUEST_URI , set this On to preserve the URL request header to www.mydomain.com

Continue reading “Apache Web Load Balancing howto”

howto reinstall GRUB in rescue mode while using lvm / mdadm

This article is how to activate LVM and mdadm software raid in rescue and reinstall GRUB boot loader, since the boot CD will not do this job for you. By following the steps, you may able to do system recovery or disk operation.

RedHat 5.x

Activate the RAID

mkdir /etc/mdadm
mdadm --examine --scan > /etc/mdadm/mdadm.conf
mdadm -A --scan

Continue reading “howto reinstall GRUB in rescue mode while using lvm / mdadm”

Enlarge linux software mirror raid 1 howto


A linux box running on a software raid 1 mirror harddisk (120GB), recently the server is running out of disk space. A new pair of harddisk with larger capacity (500GB) is going to replace the existing pair.

Current disk layout

100MB md0:/dev/sda1, /dev/sda2
111GB md1:/dev/sdb1, /dev/sdb2

/boot /dev/md0
VolGroup00 /dev/md1
– LogVol00 swap
– LogVol01 /

Synchronize the data to new harddisk

  1. Shutdown the box
  2. remove sdb from the box
  3. replace with the new 500GB disk

Continue reading “Enlarge linux software mirror raid 1 howto”