get_post_meta as class into navigation menu
-
OK, I’ve been tearing my hair out with this one – my PHP-fu clearly is not strong enough. I’m trying to get the value of a custom field in each page into a variable so that I can echo that variable into a loop to add a class to each
li in my navigation. Does that make sense? Maybe my code will give you an idea of what I’m trying to acheive…<?php global $wpdb, $acc_col; $pages = $wpdb->get_results( "SELECT id, post_title, post_name, guid FROM wp_posts WHERE post_type = 'page' AND post_status = 'publish' AND post_parent = '0' ORDER BY menu_order, post_date DESC" ); $x = 1; foreach ($pages as $page) { $count = ($x == count($pages)) ? 'last' : ''; $acc_col = get_post_meta(get_the_ID(), 'acc_col', true); ?> <li class="<?php echo $count ?> <?php echo $page->post_name; ?> <?php global $post; $acc_col = get_post_meta($post->ID, 'acc_col', true); echo $acc_col; ?>"> <a href="<?php echo get_permalink($page->id) ?>"<?php if ($active == $page->post_name): ?> class="active"<?php endif ?>><?php echo strtolower($page->post_title)?></a> </li> <?php $x++; } ?>
I have to confess I ‘liberated’ a lot of the code from elsewhere and tried to craft (butcher?) it to meet my needs. Anyone got any idea why this isn’t working?
Any help greatly appreciated ??
David.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘get_post_meta as class into navigation menu’ is closed to new replies.