asteffensen
Forum Replies Created
-
Forum: Themes and Templates
In reply to: Multilevel horizontal menuHello again.
I finally just put some money into it and “hired” a guy on wpquestions.com to write a custom walker. This should do it. Only downside is that wordpress wraps it into a ul, so there will be two ul’s (menu and sub-menu) inside the menu-ul.
I hope this helps you out!
class My_Custom_Walker extends Walker_Nav_Menu { function walk( $elements, $max_depth) { global $wp_query; $current_page = (int) $wp_query->queried_object_id; $tops = array(); // top level menu items $subs = array(); // sub menu items _wp_menu_item_classes_by_context($elements); foreach ($elements as $element) { if (0 == $element->menu_item_parent) { $tops[] = $element; if ($element->object_id == $current_page) { $current_parent = $element; } } else { $subs[] = $element; if ($element->object_id == $current_page) { $current_child = $element; } } } if (!$current_parent) $current_parent = $this->get_current_parent_from_sub($elements, $current_child); if ($current_parent) { $real_subs = array(); foreach ($subs as $item) { if ($item->menu_item_parent == $current_parent->db_id) $real_subs[] = $item; } } // show top level elements $s = '<li><ul id="tops">'; foreach ($tops as $item) { $s .= $this->display_item($item); } $s .= "</ul></li>"; // show sub menu items if (sizeof($real_subs) > 0) { $s .= "<li><ul id='subs'>"; foreach ($real_subs as $item) { $s .= $this->display_item($item); } $s .= '</ul></li>'; } return $s; } // get the parent page when a sub page is the current page function get_current_parent_from_sub($elements, $current_child) { foreach ($elements as $element) { if ($element->db_id == $current_child->menu_item_parent) { return $element; } } return false; } function display_item($item) { $i = ''; $this->start_el( $i, $item, 0, array() ); $this->end_el( $i, $item, 0, array() ); return $i; } }Forum: Themes and Templates
In reply to: Multilevel horizontal menuI also need to have wp_nav_menu output the sub-menu outside the parent ul… There must be someone out there who has done something similar? Or is the wp_nav_menu function too new? :/
Forum: Hacks
In reply to: Widget won't show up in sidebar, only footerI must be a total idiot. This is embarrassing.. 😀 Looks like it was a silly little mistake after all. I write alot in both English and Norwegian, and has somehow managed to confuse those two while writing the custom field name in the post.. SO the code actually works.
Sorry for wasting your time, and thank you!!! 🙂 Sometimes, a little perspective is all you need.
Forum: Hacks
In reply to: Widget won't show up in sidebar, only footerI wish it was just a silly little mistake like that, but I’m not quite convinced.
Here’s my code (I changed the custom field key to related_sites, just so you know):
global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid,'related_sites',true);This outputs nothing; no warnings, no errors, nothing. (I have WP_DEBUG set to true).
Forum: Hacks
In reply to: Widget won't show up in sidebar, only footerGah, I’ve been trying to work this out for a while without any luck. I am in no way a PHP-guy, although I should probably try to learn a couple of things before diving into something like this..
So here’s where I’m at. I tried http://www.wprecipes.com/wordpress-how-to-get-custom-fields-outside-the-loop <- this solution, and it did not work. It was able to pull the post ID, but that’s it. Didn’t get any output from the custom fields. I’ve tried several functions mentioned in the documentation, but I don’t seem to get anywhere with this. I’m sorry if I’m asking too much, but is there any way you could point me in the right direction? 🙂
Forum: Hacks
In reply to: Widget won't show up in sidebar, only footerWhat the plugin is intended to do, is actually to pull the custom fields to create a related pages-list in the sidebar, for the post/page that is currently being viewed. My theme displays the sidebar all the time, however this widget is only supposed to output something when viewing a post that has the related sites-key in the custom fields.
I’ll post the solution here when (or if..) I come up with something 🙂
Forum: Hacks
In reply to: Widget won't show up in sidebar, only footerYes, that is right, I’m using custom fields to add pages related to the current page, in the sidebar. 🙂
I’m not planning on distributing the plugin, I just need it to work in this website, but for the record, anyone who wants to use it, is free to do so. Although there are probably much better ways to do this…
I _could_ change where the sidebar is output… However, changing the coding is an acceptable solution.. It’s just that I don’t know how I would do that. Do you have any ideas?
Thanks, btw! You’ve been very helpful! 😀
Forum: Hacks
In reply to: Widget won't show up in sidebar, only footerIt is definitely not a CSS issue, I’ve actually checked that before.
Display errors is on, and I tried turning on WP_DEBUG, but I still couldn’t find any warnings or errors regarding my plugin/widget.
I used the “brute force breakpoints” method you described, and.. uhm.. The widget is called, but the if ($relatedsites) is false, so apparently something goes wrong when fetching the data. Now, the get_post_custom_values() function is intended for use inside the loop, and will not work otherwise. So I added this little badboy to my functions.php:
if (!in_the_loop()) { echo "Not in the loop"; }aaaand so it seems, I’m not inside the loop. So.. Any ideas how to solve this? I mean.. I obviously was inside the loop when applying it to the Twenty Ten theme…
Thanks
Forum: Hacks
In reply to: Widget won't show up in sidebar, only footerThank you for your answer! Unfortunately, my widget still won’t show in the sidebar. As I said, every other widget I try in the sidebar, works. I just can’t seem to find out why my widget/plugin doesn’t work with my new theme.
Forum: Hacks
In reply to: Widget won't show up in sidebar, only footerAnyone, please? I really need this to work