ThemeShaper Forums » Thematic

[closed]

Putting Dynamic classes BACK into Sub-Titled Menu Links

(13 posts)
  • Started 5 years ago by anthonycalzadilla
  • Latest reply from BAC
  • This topic is not resolved
  1. anthonycalzadilla
    Member

    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>";
    		}
    	}
    }
    Posted 5 years ago #
  2. This code is only working on the top-level menu .. see 4th sql line: p.post_parent = 0

    Cheers,

    Chris

    Posted 5 years ago #
  3. anthonycalzadilla
    Member

    Hi Chris, Thanks for your reply. Do you have nay direction or suggestions on how I could modify the script to put the dynamic classes back into the LI?

    Thanks!

    -Anthony

    Posted 5 years ago #
  4. anthonycalzadilla
    Member

    HI, Chris, I was wondering if there is any way to add an id or class to each list item generated by the 'sub_page_list' function - I've tried adding post_ID, page_ID, and any other combination of tags I could find. Is there a way to generate a class or id on each menu list item that I could use for targeted css styling

    Posted 5 years ago #
  5. .. if you could wait 'til the weekend?! .. finished my office move today and need two more days to get my work done from the last couple of days.

    Cheers,

    Chris

    Posted 5 years ago #
  6. anthonycalzadilla
    Member

    Hi Chris,
    Thank you for your consideration! Whenever you can find the time to help with this, it will be greatly appreciated.

    Thanks,
    Anthony

    Posted 5 years ago #
  7. anthonycalzadilla
    Member

    Hi Chris,
    I was wondering about the status of this, I cant seem to figure it out. Thanks in advance for your help.

    Posted 5 years ago #
  8. anthonycalzadilla
    Member

    Does anyone have any idea how to do this?

    Posted 5 years ago #
  9. anthonycalzadilla
    Member

    Hi Chris,
    Thank you for your consideration! Whenever you can find the time to help with this, it will be greatly appreciated.

    Thanks,
    Anthony

    .. if you could wait 'til the weekend?! .. finished my office move today and need two more days to get my work done from the last couple of days.

    Cheers,

    Chris
    Posted 4 weeks ago #

    Posted 5 years ago #
  10. Anthony .. I'm sorry that I wasn't very communicative 'bout your request.

    I'm still not sure how this could be done without adding a lot of overhead due to the necessary data base requests.

    Currently I'm working on some optimizations for Thematic. If this works out as planned, I can write a plugin / code for the functions.php that does whatever you want to the menu without adding overhead to the sql server. The only overhead would be the pure php code.

    Chris

    Posted 5 years ago #
  11. anthonycalzadilla
    Member

    Great, thanks Chris. I'll keep checking the forum regularly for your code/plugin, I'm assuming teh optimizations you're planning are for 1.0?

    Posted 5 years ago #
  12. Let's call it the next version ;)

    There'll be some major changes .. I prefer a 0.9.x

    Chris

    Posted 5 years ago #
  13. BAC
    Member

    If anyone wants a very simple fix for this problem which solves the database request issue.

    1. Install the All in One SEO Pack plugin

    2. Edit relevant page, i.e. home page and look for Menu Label. Add a span tag after the menu label text, and include the subtitle within a span:

    Home <span> about us </span>

    3. put the following CSS within style.css in your child theme

    li.page_item span {
    display:block;
    font-size:.7em;
    }

    Hope this helps.

    BAC

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.