Hello All, I've been lurking here for awhile now. I need some help. Usually I can find what I'm searching for just by doing a few searches here. This time I cant. I recently implemented the "Adding Sub-Titles To Menu Links" technique. Its works great except it strips the navigational list items of their dynamic classes.
Here is the code Ian provides:
// Adds descriptive text to link titles
// With help from http://blog.clearskys.net/2008/12/17/how-to-adding-menu-sub-titles-to-a-theme/
function sub_page_list() {
global $wpdb;
$sql = "SELECT p.ID, p.post_title, p.guid, pm.meta_value FROM " . $wpdb->posts . " AS p LEFT JOIN ";
$sql .= "(SELECT post_id, meta_value FROM " . $wpdb->postmeta . " AS ipm WHERE meta_key = 'subtitle') ";
$sql .= "AS pm ON p.ID = pm.post_id ";
$sql .= "WHERE p.post_type = 'page' AND p.post_parent = 0 AND p.post_status = 'publish' ";
$sql .= "ORDER BY p.menu_order ASC ";
$sql .= "LIMIT 0, 10";
$rows = $wpdb->get_results($sql,OBJECT);
if($rows) {
foreach($rows as $row) {
echo "<li>";
$link_url = get_permalink($row->ID);
echo "<a href=\"$link_url\"" . "\">$row->post_title</a>";
echo "<span style=\"display:block;\">$row->meta_value</span>";
echo "</li>";
}
}
}
// Filter the menu to add the list
function childtheme_page_menu() { ?>
<div class="menu">
<ul>
<?php if (is_front_page()) { ?>
<li><a href="<?php bloginfo('home') ?>/" title="<?php echo wp_specialchars( get_bloginfo('name'), 1 ) ?>" rel="home">
Home <span style="display:block;">This is the home page</span>
</a></li>
<?php } else { ?>
<li><a href="<?php bloginfo('home') ?>/" title="<?php echo wp_specialchars( get_bloginfo('name'), 1 ) ?>" rel="home">
Home <span style="display:block;">Return to the home page</span>
</a></li>
<?php } ?>
<?php sub_page_list(); ?>
</ul>
</div>
<?php }
add_filter('wp_page_menu','childtheme_page_menu');
I thought I could get it to work by changing the opening li tag like this, but it just didnt work. Can someone please point out what I'm doing wrong?
if($rows) {
foreach($rows as $row) {
echo "<li class="/post-<?php the_ID(); ?>/">";
$link_url = get_permalink($row->ID);
echo "<a href=\"$link_url\"" . "\">$row->post_title</a>";
echo "<span style=\"display:block;\">$row->meta_value</span>";
echo "</li>";
}
}
}