Creating a drop down menu - drupal

Full disclosure: I feel like this is a really dumb question, but I'm brand new to Drupal and am having quite a time getting something so simple to take place. I'm used to the Wordpress community so finding things on Drupal has been a challenge. Maybe it's a lack of help compared to WP or maybe it's just that I haven't learnt quite how to look for (or where to look for) what I need.
Whatever the case. I've sliced up a designers work and laid it atop Zurb's Foundation. I'm now in the process of placing this over the Bartik theme (feel free to point me in another direction if this is a bad choice..).
Here's how the menus are setup in Baritk, with slight tweaking by me (ie taking the header out):
<?php if ($main_menu): ?>
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu-links',
'class' => array('main-nav'),
)
)); ?>
<?php endif; ?>
and
<?php if ($secondary_menu): ?>
<?php print theme('links__system_secondary_menu', array(
'links' => $secondary_menu,
'attributes' => array(
'id' => 'secondary-menu-links',
'class' => array('links', 'inline', 'clearfix'),
)
)); ?>
I've set the secondary links to read from the Main Menu I've setup which has the main pages and subsequent sub pages. This is the best setup, right?
If so, what's the best Drupal-esque way to merge these two? Is there an easier call, function, etc. besides using both of these separately?

The easiest way for you is probably to use the nice menus module.

Related

'next_or_number' => 'next' not working - need to show only next/previous buttons in Wordpress pagination

I am trying to remove numbers from pagination links on a paginated Wordpress post to leave only next/previous buttons. I have the code as follows and it still does not work as required. If I set a display:none; css rule to the tags within the .paging p class this affects all links including the next/previous links as the links do not have a separate class to them.
<?php
wp_link_pages(array(
'before' => '<p class="paging" style="margin-bottom: 5em;">' . __(''),
'after' => '</p>',
'next_or_number' => 'next', # activate parameter overloading
'nextpagelink' => __('<span class="pagelink right">NEXT</span>'),
'previouspagelink' => __('<span class="pagelink left">PREVIOUS</span>'),
'pagelink' => '%',
'echo' => 1 )
); ?>
Here is an example of a post illustrating the problem: http://famtrav.staging.wpengine.com/destinations/uk/15-fun-things-july-2016/
Is there another way of me achieving the required result? I hope this makes sense. Many thanks.
I have now solved this. The problem was caused by conflicting code. Specifically the wp_link_pages function was being defined both in the themes functions.php file and in the post-template.php file within the /wp-includes/ folder with instructions in one incidence contradicting the other. I commented out the instructions in the functions.php file and altered the post-template.php file with the correct code and this solved the problem.

Why should I use theme() function in page.tpl.php?

Im working on my first site in drupal and I have also read some basics of theming and module development. Now I am creating (overriding stark theme) my own theme, i.e. page.tpl.php and there is an theme() function called for outputting main menu items:
<?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Main menu'))); ?>
I roughly understand what this function is for, but why should I use it in this case? It would make sense if outputting data from module - to stylize that output by selected theme. But in this case everything I need is directly in $main_menu array and I can stylize it however I want, so what's the use for theme() function in page.tpl.php?
Why should I use theme() function in page.tpl.php?
You shouldn't.
To avoid calling theme() function in your page template, you can do this in your template.php:
/**
* Implements hook_preprocess_page().
*/
function yourtheme_preprocess_page(&$vars) {
$vars['main_menu'] = theme('links__system_main_menu', array('links' => $vars['main_menu'], 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Main menu')));
}
And then simply print $main_menu; in your page.tpl.php.
The point of using theme('links__system_main_menu', ...) is to re-use the existing generic links theme implementation of the theme. The system_main_menu suffix (after the two _), allow you to provide a more specific implementation of the generic links. If you then override the page template for the front page (ie. page-front.tpl.php) and for nodes of a specific content, you don't have to duplicate your HTML code. Which make it easier to maintain since you won't have to duplicate changes to multiple files.
The point is that if you go trough drupal's theme system it gives a chance to other installed modules to do their changes - their hook functions will be called:
https://www.drupal.org/node/933976
In other words, if you don't do it "clean" way it may happen that some other's module feature won't work.

wordpress - excluding a category from a post list in a custom theme that doesn't look like the codex

I'm hoping someone can help. I'm not a php coder, but I've been tweeking and customising a premium theme for wordpress anyway, and I'm stuck.
I'm trying to exclude a specific category from a page which lists all the categories by default. Ok, no problem. It should be:
<?php query_posts($query_string . '&cat=-134'); ?>
right?
I'm pretty sure the category number is 134, but I could be wrong. The premium theme I'm using is called Risen, and there's a lot of different kinds of posts - so maybe what I think is a category is really a tag in a custom taxonomy - in which case ???
When I hover over it in the category listing I get this:
example.com/wp-admin/edit-tags.php?action=edit&taxonomy=risen_multimedia_category&tag_ID=134&post_type=risen_multimedia
I'm pretty sure I've found where I need to include my argument, and that is here in the template:
// Get posts
$multimedia_query = new WP_Query( array(
'post_type' => 'risen_multimedia',
'posts_per_page' => risen_option( 'multimedia_per_page' ) ? risen_option( 'multimedia_per_page' ) : risen_option_default( 'multimedia_per_page' ),
'paged' => risen_page_num() // returns/corrects $paged so pagination works on static front page
) );
I've tried adding
'tag' => -134
to this array to no avail.
Being a premium, and apperently tweaked, theme there is a lot of guessing here but I think you have talked yourself into the solution, except for one detail. Use tag__not_in not tag=-134
// Get posts
$multimedia_query = new WP_Query( array(
'post_type' => 'risen_multimedia',
'posts_per_page' => risen_option( 'multimedia_per_page' ) ? risen_option( 'multimedia_per_page' ) : risen_option_default( 'multimedia_per_page' ),
'paged' => risen_page_num() // returns/corrects $paged so pagination works on static front page
'tag__not_in' => array(134)
) );
tag_id=-134 might work (I'd have to test it) but tag expects the tag slug not an ID.
tag (string) - use tag slug
http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

user-menu in secondary-menu: why?

I've created a sub of the zen-theme. And am mighty proud of it, but up in the top right corner (#secondary-menu) the user-menu shows up - perfectly.
I just don't understand how it get's there?
In structure/blocks the user-menu appears in the Disabled section (Region: None)
In fact, there IS no region called "secondary-menu" (id of the element gotten from Firebug)
Isn't that strange?
I can't comment on your specific template files but the standard Zen page.tpl.php file has this in it:
<?php if ($secondary_menu): ?>
<nav id="secondary-menu" role="navigation">
<?php print theme('links__system_secondary_menu', array(
'links' => $secondary_menu,
'attributes' => array(
'class' => array('links', 'inline', 'clearfix'),
),
'heading' => array(
'text' => $secondary_menu_heading,
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
</nav>
<?php endif; ?>
Which should answer how the menu gets printed to the page. If you want to dig one step deeper, the $secondary_menu variable is set up in template_preprocess_page().
As to why it's the user menu...if you go to admin/structure/menu/settings you should see this:
If you change the secondary link source to something else you should see that reflected in your theme too.

How to print a custom menu in Drupal 7?

I have created a menu in Drupal 7 and created links to pages under that menu.
I named my new menu "Site Menu"
In my page.tpl.php where I want my menu to appear I have put this in place:
<?php print theme('links', menu_navigation_links('menu-site-menu')); ?>
After I have cleared my cache and refreshed my page my menu doesn't appear.
I am stumped. Any help would be greatly appreciated.
Berdir answer is correct. Drupal 7 theme_links function also more vastly uses arrays. For example if you would like to add another class name to the so that it is you would code it like this:
<?php print theme('links', array('links' => menu_navigation_links('menu-site-menu'), 'attributes' => array('class'=> array('links', 'site-menu')) ));?>
theme() now recieves an array of arguments. For example:
<?php
print theme('links', array('links' => menu_navigation_links('menu-site-menu')));
?>
Well, it is bit confusing from above solutions to print menu. But below code worked for me, hope this will work for y'all,
$search_menu_name = "menu-search-box-menu";
print theme('links', array('links' => menu_navigation_links($search_menu_name), 'attributes' => array('id' => $search_menu_name, 'class'=> array('links', 'inline'))));
The above code is like this, "menu-search-box-menu" is my custom menu name/ID. You can find it in that particular menu edit link.
Enjoy. :)

Resources