Wordpress menu items order - wordpress

basically I have a three-level menu in wordpress and I've got the following code in the front-end to call the third-level menu:
$children = get_pages('child_of='.$include_page_ids[$i]);
if (count($children) > 1) {
$sub = "<ul>";
foreach ($children as $child){
$sub .= "<li><a href='#$child->post_title'>";
$sub .= $child->post_title;
$sub .= "</a></li>";
}
$sub .="</ul>";
echo $sub;
}
This calls a list for the children of a certain page and also makes the the anchors (which I also need). The problem is that right now they are being displayed in an alphabetical order, but I need to be able to set the right order myself (ie to be the same as in the backend menu). Please hepl me with it, how can I achieve this? For example this is the page http://www.eboxlab.net/transbeam/support/support/, youcan see the third level-menu as the box right next to the banner (Acceptable Use Policy to Terms & Conditions). THe order of the blocks which it corresponds to is right, but the menu is alphabetically ordered.
Help really appreciated.
PS: if you need I can provide the template code

It's pretty simple actually. Here is what your $children call should look like:
$children = get_pages('child_of=' . $include_page_ids[$i] . '&orderby=menu_order&sort_order =ASC');
That's all you need to add - this tells the query to order pages in ascending fashion by their "menu_order" column(or the "Order" field under Page attributes). You can see more details on the get_pages function at Function Reference/get pages

wp_nav_menu to the rescue! Assuming you're using WP 3 or newer, it will let you wrap elements in whatever markup you'd like, and will correspond to however you've configured the menu in the admin Dashboard.

Related

Single Page Navigation Menu Dynamically Generated

hHi all! I have posted this question on the WP support forums, but the community doesn't seem to be as active as stack's, so I am taking a chance here!
I am looking for a plugin that would automatically create a navigation menu (through the use of shortcodes for example) on a long single page documentation page.
The long page is divided into sections. I can imagine using a shortcode at the beginning of every section, and this will create a menu that would be displayed in a sidebar for example (called through a second shortcode perhaps, or a widget)
Any thoughts? Advice?
Thanks!
Use [section]Section Title[/section] shortcodes, then [section_navigation] where you want the navigation links output.
This works, but with a massive caveat -- that [section_navigation] needs to be in your post/page after the other [section] shortcodes... otherwise it generates an empty list.
You should be ok to use it in your theme by putting <?php echo do_shortcode("[section_navigation]");?> in sidebar.php. It will work as long as get_sidebar() is after the_content() in your theme templates (it usually is).
This to go in functions.php
$whit_sections = "";
// [section]My Section Title[/section]
function whit_section_shortcode( $atts, $title = null ) {
// $content is the title you have between your [section] and [/section]
$id = urlencode(strip_tags($title));
// strip_tags removes any formatting (like <em> etc) from the title.
// Then urlencode replaces spaces and so on.
global $whit_sections;
$whit_sections .= '<li>'.$title.'</li>';
return '<span id="'.$id.'">'.$title.'</span>';
}
add_shortcode('section', 'whit_section_shortcode');
// [section_navigation]
function whit_section_navigation_shortcode( $atts, $title = null ) {
global $whit_sections;
return '<ul class="section-navigation">'.$whit_sections.'</ul>';
}
add_shortcode('section_navigation', 'whit_section_navigation_shortcode');

Drupal - Add custom html in li to menu ul?

Is there any way to write some html (as you might in a block), and have that html appear as a menu item?
My situation is that I want some text that is not a link to say 'Follow us on:', and then I want 2 images which are both links to twitter and facebook.
Menu html cant do this as it requires any html you write to be part of a link, and to be the same link for that menu entry.
http://drupal.org/project/menu_html
I really want the html I add to be within the menu list.
Thanks
UPDATE
Code doesn't work well in the comments so im adding it here. This link seemed to be the closest to what you were suggesting:
http://api.drupal.org/api/drupal/includes--menu.inc/function/theme_menu_item/6
So I added this to my template.php:
function localhost_petitpim_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
if (!empty($extra_class)) {
$class .= ' ' . $extra_class;
}
if ($in_active_trail) {
$class .= 'active-trail myactive';
}
return '<li class="' . $class . '">' . $link . $menu . "</li>\n";
}
All ive done is add a class of 'myactive' so I can see if its working. My theme name is 'localhost_petitpim'. Ive refreshed the cache. My theme is set to 'Rebuild theme registry on every page.' I cant see the new class being applied. Have I done something wrong?
Thanks
You can simply hard-code text and linked images in your tpl.php file(s).
Just put html block with desired code in tpl.php after menu. Make new wraper around menu & block if current html structure of your theme is not supporting this solution. Block should be floated right or displayed inline depending on HTML+CSS of your theme.
Hope this helps.
Not a nice solution, but it works.
Add two dummy menu entrys to your menu.
Override the theme_menu_link method by implementing phptemplate_menu_link in your template.php file.
Inside the phptemplate_menu_link filter for your dummy entry and replace them with what ever html code you like.

Make a visible primary link not clickable

On my Drupal site I've got a set of Primary Links. The ones that expand I'd like to make the parent not click able e.g
-home
-about
-history
-website
Only home, history, website should link to a page. If the user clicks on aboutnothing should happen. I've tried searching around the admin panels as well as leaving the field blank but it doesn't seem to be working. I'd assume I'd have to hardcode this? If so, how?
Try this module http://drupal.org/project/special_menu_items
Its probably the simplest way to achieve what you want.
If you can live with it, the easiest solution is to use js to disable clicks.
Adding a yourtheme_menu_item function in template.php seems to be the way to go for this. The documentation for the original function is at http://api.drupal.org/api/function/theme_menu_item
The function passes a $has_children variable and a $menu variable, so it should be pretty easy to adjust Primary Menu items with children as needed.
Some untested example code:
function yourtheme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
// ... original theme code copy-pasted ...
if ($has_children) {
$modified_link_name = youtheme_write_menu_item_without_links($link);
return '<li class="'. $class .'">'. $modified_link_name ."</li>\n";
} else {
// From original function
return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
}
}
You just need to add in the path the phrase <nolink>.
"You just need to add in the path the phrase <nolink>"
i used this before and it worked, but for some reason it didnĀ“t work for a different site that i am using now.
So i tried to write # in the path and worked fine for me.
Hug everybody.

Adding sorting to a view on Drupal?

I used to know how to do this, but I can't seem to get sorting to work on a view where filters are exposed in a block. I want to be able to filter by, for example, type, price etc, but then also have sorting options to sort by these items.
How do I get sorting to work like this?
I used that code to override sorting in non-table views
function views_tweak_views_query_alter(&$view, &$query) {
if ($view->name == 'products'){
if (arg(3) == 'pu') $query->orderby[0]='uc_products_sell_price ASC';
if (arg(3) == 'pd') $query->orderby[0]='uc_products_sell_price DESC';
if (arg(3) == 'nu') $query->orderby[0]='node_title ASC';
if (arg(3) == 'nd') $query->orderby[0]='node_title DESC';
}
}
and placing into view template links with those urls
AFAIK you can't expose sort criteria like you can with filters.
I looked a bit around a found this module. The idea is to create several views each with a different sort criteria and link them together with tabs. It's a bit hackish and might not work with exposed filters. The module is still in beta release, and I haven't tested it, so can't say if it's any good.
If you choose to use a table layout, you can sort by columns. That functionality is built into views.
Just in case you cannot find where to set this, look on the left side of the View (in Edit mode), under Basic Settings, select "Table". The click the "settings" (looks like a little gear icon to the right of the "table" selection), and you'll see a list of all the display fields, where you can select which ones are sortable/not, and which is the default sort.
Adding sorting to a view on Drupal less programm code in hooks.
You need to use arguments in display page.
Use taxonomy menu for pages before.. Next:
Create one display page in view with path (for example):
some_path/%/by_totalcount
1.1. Make sort criteria for this display by totalcount
Make another one dislplay page in this view with path (for example):
some_path/%/by_date
2.1. Make sort criteria for this display by date
Create new block with code:
<?php
$url= urldecode($_SERVER['REQUEST_URI']);
switch($url)
{
case '1':
$class = 'top';
$title_h2 = 'top';
break;
case '/taxonomy/term/6 3 ':
$class = 'travel';
$title_h2 = 'travel';
break;
.................
}
global $base_url;
$url_rating = $base_url.'/'.arg(0).'/'.arg(1).'/'.arg(2).'/rating';
$url_created = $base_url.'/'.arg(0).'/'.arg(1).'/'.arg(2);
?>
<div class="<?php print $class; ?>">
<div class="title">
<h2>
<?php print $title_h2; ?></h2>
<p>Sort node: <span class="sort_type">by rate</span> | <span class="sort_type"> by date</span></p>
</div>
</div>
<p> </p>
VOILA
Sorry for my english.. it isn't my native language ))

fetching only part of a Drupal 6 menu

I'd like to pull out just one section of my navigation menu - a single section of the admin menu structure. I can load the entire navigation menu tree, but I can't see an easy way of pulling out just one segment of it.
Is there an easy way to do this, or do I have to do something hacky?
Have a look at function menu_navigation_links. You pass it a menu name (default = navigation) and a level (default = 0).
Not sure if you'd consider this an easy way, but you could try to grab the whole menu tree via menu_tree_data() or menu_tree_page_data(), find and extract the section you're interested in from the resulting tree structure and render the resulting subtree via menu_tree_output().
EDIT: Stumbled over How to rendering a menu subtree in the meantime - looks like my suggestion could work, but I would definitely not consider this being easy ;)
I found this here which works great for me.
<?php
$menus = menu_tree_page_data(menu_get_active_menu_name()); //get menu tree for active menu
$output='';
foreach($menus as $data) {
if(!empty($data['link']['in_active_trail'])){
$link = theme('menu_item_link', $data['link']);
$extra_class = NULL;
if ($data['below']) {
$output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
}
else {
$output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
}
}
}
return theme('menu_tree', $output);
?>
I'm not sure I entirely understand the situation, but you may want to take a look at Menu Block Split which allows you to split levels of navigation into blocks. Here is an excerpt from its project page:
... split any menu block into two different blocks: a first block with the first level menu entries only and a second block with any second level and sub level menu entries. You can have as many splitted blocks as you need.

Resources