The sample code below shows how to add a new argument to each link from wp_list_pages:
<?php
function mam_add_query_arg ($key,$value,$link) {
// Adds the parameter $key=$value to $link, or replaces it if already there.
// Necessary because add_query_arg fails on wp_list_pages entries.
if (strpos($link,'href')) {
$hrefpat = '/(href *= *([\"\']?)([^\"\' ]+)\2)/';
} else {
$hrefpat = '/(([\"\']?)(http([^\"\' ]+))\2)/';
}
if (preg_match($hrefpat,$link,$matches)) {
$url = $matches[3];
$newurl = add_query_arg($key,$value,$url);
// echo '<p>OLDURL:' . htmlspecialchars($url) . '</p>';
// echo '<p>NEWURL:' . htmlspecialchars($newurl) . '</p>';
$link = str_replace($url,$newurl,$link);
}
return $link;
}
$pagelist = wp_list_pages('title_li=&child_of=327&echo=0');
echo '<p>Before Loop:';print_r(htmlentities($pagelist));echo '</p>';
$pagearray = explode('<li ',$pagelist);
$junk = array_shift($pagearray); // First entry is empty
for ($i=0;$i<sizeof($pagearray);++$i) {
$newarray[$i] = mam_add_query_arg('newkey','newval',$pagearray[$i]);
echo '<p>i='.$i.' NewLINK=' . htmlentities($newarray[$i]) . '</p>';
}
$newlist = '<li ' . implode('<li ',$newarray);
echo '<p>After Loop:';print_r(htmlentities($newlist));echo '</p>';
?>