Drupal custom theme visibility to all users - drupal

I'm creating a custom drupal 7 theme
<?php print theme('links', array('links' => menu_navigation_links('menu-headermenu'), 'attributes' => array('class'=> array('links', 'headermenu')) )); ?>
Above is the code I'm using in my theme to show a menu I created using the Admin section.
My problem is the menu is getting displayed only for the Admin.
I want it to be shown to anonymous as well as registered users.
Also, I've tried changing the role permission by ticking 'Administer Block' and 'Administer menus and menu items' to all the three kind of users. Nothing helps.
Please help me..

I'm not 100% sure this will answer your question, because it side steps the code above - but, you could try enabling the Menu Block module, then using it to create a block based on your desired menu. Then you can place it any block region, and control it via the normal block controls.
The only trick of it is you might need to add a region to your template if it doesn't exist in the place that you want, but that's easy.

Related

Customizing my account page in woocommerce wordpress

When I customize the my account page in woocommerce, I can edit right side section by creating my_account.php inside my account folder in woocommerce. But In left side it is showing "Define your 'My Account' navigation Apperance > Menus",
After seeing this I tried to create menu called "My account", but there was no theme location existing, so I create a theme location called "my account menu". And I assign "my account" menu with theme location "my account menu".
I don't know how to connect this menu to my account page in woocommerce, the page again showing same "Define your 'My Account' navigation Apperance > Menus".
Try Appearance>Menus>Custom Links
Otherwise:
Is the theme you are trying to edit a pre-built theme?
Is the platform up-to-date or outdated (sometimes updates/bugs can alter functionality of pre existing code)?
Sometimes there are errors in the theme build, as I have seen. In such a case, I would recommend reaching out to the theme developer(s) as they can usually help the best in this situation. If not, check back. Hope this helps.
Call menu by menu name instead of theme_location
<?php wp_nav_menu( array( 'menu' => 'Main Menu' ) ); ?>

Wordpress - Different sidebar for each page

Client needs an website to migrate into WordPress.
In this website each page has an sidebar with different content inside it
In some page accordion comes under sidebar, in some just text and images are visible
How to implement this in WordPress?
If template has to be created, there are many page it cant be done so
Even for every page different sidebar widget is not also possible
Guide me a way to implement this
A different sidebar (widget) are can be added to each page in two steps:
Add the sidebar to the theme template using the page slug as part of the sidebar name. This ensures that the sidebar has a unique name for that page.
Register the sidebars for each page in functions.php for your theme
Add the sidebar to the theme template
In your theme template, add the following code where you want the widget area to be:
<?php
global $post;
dynamic_sidebar( 'widget_area_for_page_'.$post->post_name );
?>
Register the sidebars
In functions.php for your theme add the following block of code to register the sidebars for each page in your site. Note that it includes draft pages etc so that you can edit the widgets while still in draft mode.
function myTheme_registerWidgetAreas() {
// Grab all pages except trashed
$pages = new WP_Query(Array(
'post_type' => 'page',
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit'),
'posts_per_page'=>-1
));
// Step through each page
while ( $pages->have_posts() ) {
$pages->the_post();
// Ignore pages with no slug
if ($pages->post->post_name == '') continue;
// Register the sidebar for the page. Note that the id has
// to match the name given in the theme template
register_sidebar( array(
'name' => $pages->post->post_name,
'id' => 'widget_area_for_page_'.$pages->post->post_name,
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
}
}
add_action( 'widgets_init', 'myTheme_registerWidgetAreas' );
Hope it helps!
There's a great plugin for this:
https://wordpress.org/plugins/custom-sidebars/
Sometimes it is necessary to show different elements on the sidebars
for some posts or pages. The themes nowadays give you some areas to
put the widgets, but those areas are common for all the posts that are
using the same template. NOTE: You need to use a theme that accepts
widgets to make this plugin work.
I think this is what you're looking for.
This can be done with the https://wordpress.org/plugins/jetpack/ plugin. Once activated you can choose what widgets display on what pages:
The Widget Visibility module enables you to configure widgets to appear only on certain pages (or be hidden on certain pages) by using the Visibility panel.
Visibility is controlled by five aspects: page type, category, tag, date, and author. For example, if you wanted the Archives widget to only appear on category archives and error pages, choose “Show” from the first dropdown and then add two rules: “Page is 404 Error Page” and “Category is All Category Pages.”
Just tried custom-sidebars with the latest version of wp. Had a hard time deleting it. Database is still messy. Plugin did not work. Maybe the 'pro' version is useful, but the 'non-pro' version would not add a sidebar to the page. It was clunky and did not allow per-page sidebars. It says its not been tested with the latest wp, maybe that's the problem.
You can create custom sidebar for for each post and pages with the help of plugin. There are a few plugins which enables you to create your custom sidebar. Here in this tutorial we are using Easy Custom Sidebars. Download and install this plugin in your website and activate it.
After successfully activating the plugin go to Appearance > Sidebar Replacement
From this page give a name to your custom sidebar and click on the Create Sidebar button. After that go to the Sidebar Properties option. Here you need to select the properties where you want to replace your created custom sidebar instead of theme sidebar. You can view your available option in the drop-down menu. Select it and provide a description on the Sidebar Description field.
Now in the last step select the post or pages to add this custom sidebar. You can see all the option in the left column. You can select specific post, page, category , tag, author to add this sidebar. Just select it and click Add to sidebar option.
For better understanding you can follow this tutorial

how to list subpages in sidebar without widget - wordpress

I am trying to create a list of subpages of a parent page, which will appear in the sidebar of my wordpress site. This sidebar will appear on every page.
So for example, I have a page with an ID of 54. This page has 7 subpages. I would like to display these 7 pages in the sidebar (just the titles), as well as any more subpages that get added.
There is a currently a widget called 'Pages' that will do this, but I would like to do this via code directly in the sidebar.php rather than using a widget as there are a few constraints with using the widget.
Any help would be greatly appreciated.
Thanks
Try this link: http://codex.wordpress.org/Function_Reference/wp_list_pages
Specifically, look the 'depth' and 'child_of' parameters for the function.
Should be:
<?php wp_list_pages( array( 'depth' => 1, 'child_of' => YOUR_PAGE_ID_HERE ); ?>
furthermore, you can get the page id dynamically too of course.
To write custom code for such purpose will require you to execute php inside the widget. Try using this Php Code Execute Plugin

Need help with Wordpress menu and redirecting pages

I have a template with 2 menus, a top primary menu and a secondary menu.
<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>
and these menu options :
Home
Projects
Contact
Now I have a secondary menu that is visible when someone accesses "Projects". and the follwing menu options :
Overview
Project A
Project B
Now in this scenario I have 6 pages, one for every menu option. But I do not want to use the "Project" page. If someone clicks "Porjects" on the primary menu, I want that the "Overview" page is actually loaded.
The second problem is with the style. When I have "Overview" activated I also want to have the secondary menu option "Overview" highlighted, which works, but also the menu option on the primary menu "Projects".
Any idea ?
At least for your first question, using the custom menu, you should be able to add the Overview page in place of Projects, and rename it Projects. That also may fix your second question as well.

Create dynamic link in drupal

Could anyone tell me how to create a dynamic link in drupal?
I want to create a link to a group membership list. I have created the view with the argument. How do I create the menu item link to the view? It will be different depending on the group.
Thanks
I create a redirect link for such situations. For example, if I want a menu link to direct the user to their user edit page, I will implement hook_menu() as follows:
function my_module_menu()
{
$menu['user/cp'] = array
(
'title' => 'User Control Panel',
'page callback' => 'user_cp_redirect_page',
'access callback' => 'user_is_logged_in',
'type' => MENU_CALLBACK,
);
return $menu;
}
Then, I set the page callback to look like this:
function user_cp_redirect_page()
{
global $user;
drupal_goto('user/' . $user->uid . '/edit');
}
In short, you can't. Drupal's menu system caches the entire menu: menu items can't appear differently for different users (although you can set access permissions for them). If you want menu items to appear, you have to either register them in hook_menu() (which is only called when the menu is rebuilt), or you have to add them manually in Menu administration.
The handbook page on the Menu system provides more information about this.
However, you can create a fake menu using a block display in your view and the HTML list row style. This is useful if you wanted to have a category listing block, outside the main menu structure.
It sounds like you may need to use views arguments to filter your results if you are pulling different "groups" based on a single view. I would start here to learn more about views arguments: http://drupal.org/node/54455, if this is indeed what you are trying to accomplish.
EDIT:
I guess it would help if I read the question fully. It sounds like you are already using arguments for your view. In this case you already have created dynamic links to your page. Try putting the arguments for each "group" at the end of the URL. For example if created a page display with a path news, you can pass the argument by appending it at the end of the URL. So, if you created an argument using "Node:Created Year" you could then filter this content by putting something like example.com/news/2009 to access only the nodes that were created in 2009. What you pass is dependent on the type of argument you have created.

Resources