How do you get children of primary links to output in the HTML? Only my parent-level primary links are generating LI's.
I have a very very simple two-level primary links menu. There are 5 pages on the site: three parents, and the third parent has two children. In the administrative menu settings I have the parents' and childen's 'expanded' checkbox checked.
I have tried adding all kinds of functions from stackoverflow (including Drupal 6: Printing Unadulterated Primary Links and all children) and drupal and elsewhere to template.php to get the children to output... nothing!
How do you make primary links expanded?? This seems like such a stupid question. Why wouldn't checking 'expand' checkboxes print the children?
A direct solution to your problem. For Drupal 6:
<?php
// gets whatever is set as the primary menu source,
// prints the whole tree,
// pays attention to expanded settings
$menu_name = variable_get('menu_primary_links_source', 'primary-links');
print menu_tree($menu_name);
?>
I then wrap that in a "primary" div id, in my page.tpl.php and page-front.tpl.php
Remember to set each menu item that has children to expanded if you want them to start laid out rather than collapsed. /admin/build/menu
This solution will take notice of your settings on this page: /admin/build/menu/settings
For more info see the Drupal 6 code on this page http://drupal.org/node/68578
The problem is displaying all the children of the primary menu, so the secondary menu is irrelevant, although it can be set to point to the 2nd level of the primary menu as the above link discusses.
I wasn't able to get primary links to print their children when using theme('links', $primary_links) in page.tpl.php regardless of configuration settings.
Instead, after hours of searching, I found this page on drupal.org which mentions that primary links will output differently depending on whether they're being used as links in a theme or as a block:
http://drupal.org/node/187932
It's a discussion about how primary links' 'expanded' option may appear as 'not working' when they are being used as a theme option instead of as a block. When used as a block, primary links will show the full hierarchy of the list you set up, including children. When used in the theme, unless you overwrite the default settings for how primary links display for your theme, it will only list the top-level primary links. This is what Mark mentioned as the default behavior above, and what I was experiencing.
To solve my issue, I simply took the code to print the menus out of the page template entirely, and then assigned primary links to the region in my template where the code was before.
so instead of:
<div id="nav">
<?php if ($primary_links): ?>
<div id="primary">
<?php print theme('links', $primary_links); ?>
</div>
<?php endif; ?>
<?php if ($secondary_links): ?>
<div id="secondary">
<?php print theme('links', $secondary_links); ?>
</div>
<?php endif; ?>
</div>
I now have:
<div id="nav">
<?php if ($navigation): ?>
<?php print $navigation ?>
<?php endif ?>
</div>
AND specified a region in my .info file for 'navigation',
AND went to the block settings and assigned 'primary links' to my new navigation region.
To get rid of extraneous code outputting into my new navigation region, I also created a new block template for this region that just outputs the content of the block without any additional wrapping divs or heading tags. I ended up with a navigation unordered list that is pretty tidy, and I hope anyone else who is new to drupal and struggles with this issue finds my personal work-around helpful.
How primary links display is dependent on your theme. Without knowing more about your theme and how it implements primary links, it'd be impossible to say for sure why your primary links aren't expanding.
One thing you could check is the menu settings; in many themes, the second level is a separate menu called Secondary links. You can change this functionality by going to http://example.com/admin/build/menu/settings and setting Source for the secondary links to Primary links: this will display the second level of the primary links menu instead of the (likely empty) secondary links menu.
This brilliant blog post tells you exactly how you can get the entire tree structure for your primary links (including children) programmatically, and even shows you a way of tidying up this structure for easier use.
http://jamesmorrish.co.uk/blog/get-a-clean-array-of-primary-links-in-drupal/
I believe the Menu block module does what you are looking for. Some more details about this module (from its project page):
So… have you ever used the Main and Secondary menu links feature on your theme and wondered “how the hell do I display any menu items deeper than that?”
Well, that’s what this module does. It provides configurable blocks of menu trees starting with any level of any menu. And more!
So if you’re only using your theme’s Main menu links feature, you can add and configure a “Main menu (levels 2+)” block. That block would appear once you were on one of the Main menu’s pages and would show the menu tree for the 2nd level (and deeper) of your Main menu and would expand as you traversed down the tree. You can also limit the depth of the menu’s tree (e.g. “Main menu (levels 2-3)”) and/or expand all the child sub-menus (e.g. “Main menu (expanded levels 2+)”).
Related
I'm working on a site that sells various products. Currently we're presenting those products as fixed width (no sidebar) pages within Wordpress. I'm using "Simple WP Shopping Cart" to drive the transactions (because all of the other solutions are bloated and break stuff). With this plugin you get a widget that contains the cart...
What I want to do is load that cart to a fixed div that sits on the side of the page, rather like all those "feedback" and "socialise" bars you see on a variety of sites these days. I've done the div, so that's not a problem, but I can't seem to get the widget to load.
So basically: how would one go about loading widgets, or a widget, in a div that isn't the "designated" sidebar in Wordpress?
you need to "designate" it as a sidebar... :-)
A "sidebar" is actually a placeholder for widgets .
<div id="mysidebar">
<?php dynamic_sidebar( 'Right Sidebar' ); ?>
</div>
from the codex :
You can load a specific sidebar by either their name (if given a string) or ID (if given an integer). For example,
dynamic_sidebar('my_name')
will make a sidebar (widget placeholder) for a registered sidebar with :
register_sidebar(array('name'=>'my_name',)).
read here for more : http://codex.wordpress.org/Function_Reference/dynamic_sidebar
I have a couple of pages (home, about me, ...) in my main navigation. Now I'd like to get rid of my sidebar and I have plenty of space in my main navigation. Is there any chance I could get my categories to display in there, preferably with the subcategories displaying as childs (which will work well in the dropdown menu I have)?
Appreciated!
<?php wp_list_cats(); ?> will list your categories. It will however list them vertically so you'll need to use css in your style sheet to create a class to list the horizontally.
As for removing the side bar. If you go to your index.php and your single.php you will set something like <?php sidebar(); ?> or <?php get_sidebar(); ?> by removing this the page will no longer fetch your side bar. I would personally not advise deleting the sidebar.php file(if you have one) or deleting this line of code for formatting reasons. It is probably best to comment it out that way you can add it back if you ever decide you want a sidebar again.
I have recently started on Drupal (v 7) to create a small company website.
After much reading and watching tutorials, I have started to create my new theme from scratch. I have defined regions and customised the page.tpl.php file to place them into the template (and node.tpl.php etc). All these changes are working and the layout is looking good, and any item I add appears in the main content output.
In my footer region, I have created a block in which I would like links to appear. I have also created a content-type called footer links (with relevant fields) and I have created a couple items of content for it.
The block is showing fine (the title and block body appear). However, despite scouring the documentation, I am not sure what needs to be done to make the items of content (footer links) appear in this block.
Any help appreciated, thanks!
info file snippet for a region
regions[footer_one] = Footer Column One
... and code in page.tpl.php
<div class="one">
<?php if ($page['footer_one']): ?>
<?php print render($page['footer_one']); ?>
<?php endif; ?>
</div>
If you just need simple footer links, no need to create a content type for this, you can simple create a menu and add a menu block in footer.
If you really want to use your own content type for these links, you can create a view (with views module) to display what you want in a block.
About creating a theme from scratch, did you try before to create a sub theme ?
PS: I don't think drupal is a good cms for "small company website".
Views is really powerful and sounds like it will do exactly what you need. Otherwise, you can create a menu for your items and place that menu in your region as well.
Regarding your original code, you'd probably need to grab the information about the nodes from the database in order to construct a list on your own, but views basically does that for you :)
i'm new to drupal, but i have a good knowledge about php, and html/css.
I have this drupal site where the primary menu has 2 levels.
In the page.tpl.php of the theme is see this line:
<div class="pr-menu">
<?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>
</div>
the $primary_links variable seems to only hold an array with the first level menu items.
Now my question is: what is the best way to load the entire primary menu as an unordered list in stead of the first level primary links that are displayed now?
Nice, see the Drupal 6 code here, I believe it will also pay attention to what is set as the primary menu source (in /admin/build/menu/settings ):
http://drupal.org/node/68578
Finally found some kind of solution, after looking a bit trough the existing functions in menu.inc
For anyone interested, here is the code to put in your theme's page.tpl.php file, instead of the default primary link code:
<div class="pr-menu">
<?php print menu_tree('primary-links'); ?>
</div>
menu_tree() will return the primary menu as a multi level html-list with all the most important properties (first, last, active,...) accessible trough css classes.
New to php and drupal. I set up drupal and trying to customize the zen theme. Also setup Netbeans for debuggin. Everything is fine, but the menu variables are not filled as expected.
In page.tpl.php, there is a condition, <?php if ($primary_links || $navigation): ?> , which prints main menu if evaluates true. I get primary_links empty, so the menu doesn't print. According to the css provided by the zen theme, below ids should be used for customization.
/*
* Primary and Secondary menu links
*/
#main-menu {
}
#secondary-menu {
}
I may add style elements looking through firebug, but the above id may be the right place to do it. So, why primary link variable is empty for me?
thanks.
The first thing that comes to mind is that, maybe, you haven't assigned anything to the primary links list. Have you?