Wordpress show sub menu items on index page - wordpress

I am using wordpress and on the page "sidebar.php" I have the following code:
<?php wp_list_pages('post_type=wiki&depth=1'); ?>
It works great but what I need to do it that what I click on a Menu item on the sidebar I need the sub items to display on the main page.
UPDATE:
What I basically need to do is to have the first level items on the left (As it currently is), and when those links are clicked then the sub items of those items will be listed on the index.php (main page).
I am using the wp-wiki plugin to display the pages as wiki pages but the actual but the list is the same, just showing as a different type:
post_type=wiki
Can anyone help please?
Thanks

<?php
wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->ID.'&depth=0');
?>

There's several ways you can accomplish this. WordPress actually has an example of exactly what you're looking to do in the Codex. (link - the last example in that section, right above the "List subpages even if on a subpage" heading)
There's several ways to do this though - that's just one example. But that code above, you just pop into your sidebar.php file. You can also create a widget out of it. And as someone else mentioned, you can use the new menu system for WordPress (but you can indeed, make it dynamic.) But the above example in the Codex is the simplest method.
Actually, an easier method would be just to list all subpages and use CSS to hide and show the child items based on what page you're on. The classes are already set up for you. Just view your source code and you can see it. So you'd do something like:
`li ul.children {display:none; }
li.current_page ul.children { display:block; }`
and variations thereof.

What about using the new menu function in wp 3?
That way you could include your type with any sub page you want (won't be dynamic though) and then add your favorite javascript or good css to show those sub-pages.

Related

Remove sub menus from the admin view for a plugin that registers a custom post type

I know there are 357,982 other posts about this BUT they all kinda lack something ie. an actual example that works for those of us who don't write 4,594,334 line of code every day.
SO - As it stands the scenerio is:
A plugin that registers a custom post type
A sub-menu you want to hide
What next?
The best solution I have found is actually pretty easy and requires a bit of inspection of the source and a good understanding of what to look for.
In this example woocommerce is registering the custom post type 'product' with a sub-menu that appears as 'Product Options'. We want to hide this for non-admin users.
Doing an inspection of the menu items we find that the hyperlink for the parent menu is 'edit.php?post_type=event_ticket' - looking a little further we see that the hyperlink for the sub-menu is 'https://websitename.com/wp-admin/edit.php?post_type=product&page=product_attributes'
We will use the 'add_action' hook as shown below. Please note that we are using the url for the parent menu however we are ONLY using the page parameter for the child.
add_action('admin_menu', 'remove_menu_pages', 999);
function remove_menu_pages()
{
if (current_user_can('manage_options') == false)
{
//1st parameter is parent URL | second is the 'page' parameter from the child url
remove_submenu_page('edit.php?post_type=product', 'product_attributes');
}
}
Add this to your functions.php and then login as a non-admin user and the submenu should now be hidden.

Hook menu to unset a link with conditions

I'm stuck with an issue on Drupal 7.
I have my main menu containing multiple links.
With the module menu_fields, I added a taxonomy to the menu links, and I want to alter this menu display based on the chosen one.
Problem is I do not know how to write my development.
I tested hook_menu(), hook_menu_alter(), hook_menu_alter_link() in my module but the dpm() I wrote in it never appears.
What I hope for is a hook with a param containing an array of the menu items.
Do you have an idea ?
Progress:
I manage to display something with hook_menu_alter() -I had to empty cache- but I can't find the main menu in the $items var.
Problem solved using mymodule_translated_menu_link_alter(&$item, $map).
You just have to do a if ($item['menu_name'] == 'main-menu') {} statement and add your code in it.
The best solution I can think of is to collect menu tree with menu_tree_all_data() function:
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_all_data/7.x
and then to crawl tree structure (recursevly) and manually generate menu html.

Trigger a class to hide meta-data of posts on WordPress blog page

Basically on my bakery's WordPress blog page http://www.omigretchen.de/novedades/ I would like to hide the meta data displayed below each post preview. Usually I always succeed in using the console and trigger the class.
As it shows in this case I use a display:none on the class .entry-meta. Nevertheless it does not work. Does anyone has an idea what to do?
Are you certain that you've added .entry-meta { display: none; }? Because I don't see it. Make sure you put it where it'll be printed to the page.
A better way to do it is by editing the archive.php and either remove or comment the code that prints the entry-meta block.

Drupal 7 - Wanting content (of certain content-type) to appear in block

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 :)

Making wordpress menu remain highlighted (class="current-page-item" in the menu) for a category listing (not a page)

I have a site that I have completely customized the theme.
Unfortunately the theme and the way it's set up doesn't like you to view the actual page permalink for both the blog and the portfolio to view its content.
Regular pages work fine:
site.com/about
site.com/contact
However, if you go to /portfolio or /blog the pages show up blank
As a result, I had to use appearance>menu to make a custom menu that links to:
/category/portfolio/#all
/category/blog
This makes the content now show up, the only problem is when they click on the portfolio or the blog, wordpress thinks that it's not actually viewing that page, so the tab in the main menu doesnt remain highlighted (to show you what page youre currently on)
Does anyone have any idea how to fix this?
http://eastcoastefx.com/ggqq
Thank you :)
I have done this before. It's not pretty, but it works if both items are WordPress pages.
// hack the queried_object_id for wp_list_pages
global $wp_query;
$queried_object_id = $wp_query->queried_object_id;
if ($season_page) {
// ensure season pages have Season highlighed in nav
$wp_query->queried_object_id = 22;
}
wp_list_pages($args);
// set queried_object_id back to the original
$queried_object_id = $queried_object_id;
I'd be interested to know if you found anything better on the WordPress forum per Mike Schinkel's comment as the above is clearly a hack.

Resources