I'm developing a WordPress theme using version 3.5.1, and in every page I want to display a side vertical menu displaying all the pages that belong to the current's page parent.
I've tried with this:
<?php
$args = array(
'sort_column' => 'menu_order',
'child_of' => $post->parent
);
?>
<ul>
<?php wp_list_pages($args); ?>
</ul>
But what I get listed is every parent page, instead of what I pretend to do.
What is the best approach to do this?
Thank you very much in advance!
That's a syntax error.
Try this: 'child_of' => $post->post_parent
That should return the siblings of the page you're in.
Related
I create in my wordpress theme template page named popular.php, where i sort post by popularity. It works fine for every post but I dont know how to do this for category.
I want something like this:
sitename.com/popular-post - works fine
sitename.com/category-name/popular-post - i don't know how to make popular page child for every category?
Popular loop works fine with this args:
<?php $current_category_ID = getCurrentCatID(); ?>
<?php $args = array(
'posts_per_page' => 60,
'cat' => $current_category_ID,
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
); ?>
<?php query_posts($args); ?>
Only I don't know make it child for category?
Check Permalink Settings & update the custom structure like this
/%category%/%postname%/
https://codex.wordpress.org/Category_Templates
See this page in the codex. It explains how to name your template files for category.
For example, if you have a file in your theme named category.php, that template will be used to display a category page.
In my Wordpress website:
I have two pages, one is in Deutsch and one is in English.
I have two menus, same deal.
I would like to display the english menu when browsing the page in English and display the deutsch menu when browsing the page in Deutsch.
I cannot use any multilingual pluging unfortunately.
Is there any way to achieve this with a basic wordpress installation?
Why can't you use a multi-language plugin?
Assuming you're right about the idea of not being able to use such a plugin, two solutions come to mind:
Use custom fields and conditional logic to display one menu or another
Use page templates to display different menus
You can override the layout of a page by creating a file called page-{slug}.php or page-{id}.php, in which {slug} and {id} should be substituted for the slug or id of the page you wish to make a template for. In this page template you could copy the original layout, but alter the wp_nav_menu command to select a different menu.
There are a few other ways to do it, but those two seem like sensible options to me.
Try this one:
Put this code in header.php while calling navigation menu:
<?php if (is_front_page()) { ?>
<div id='frontPageBanner'>
<?php wp_nav_menu( array( 'container_class' => 'menu-header-1', 'theme_location' => 'primary' ) ); ?>
</div>
<?php } elseif (is_archive()) { ?>
<div id='archiveBanner'>
<?php wp_nav_menu( array( 'container_class' => 'menu-header-2', 'theme_location' => 'primary' ) ); ?>
</div>
<?php } elseif ( is_page($pageID)) { ?>
<div id='pageIdBanner'>
<?php wp_nav_menu( array( 'container_class' => 'menu-header-1', 'theme_location' => 'primary' ) ); ?>
</div>
<?php } ?>
Thanks.
I created a couple of custom menus on wordpress using the appearance menu.
I want to display the right menu according to the page that I'm viewing. I wrote the script below in the header.php file in the seems to be working fine. It's pulling the correct menu according to the page that I'm visiting with the exception of the category pages.
When I'm on a category page, the wp_nav_menu function falls back to the fallback function, indicating that the menu doesn't exist?!
I was looking around and the solution that kept coming up was adding the following code but it doesnt seem to work.
<?php
wp_nav_menu('container_class=menu-header&theme_location=primary');
?>
Here is the full code that I added to the header.php file:
<?php
switch( $master_page ) {
case 'about':
wp_nav_menu(array(
'menu' => 'about',
'fallback_cb' => 'get_cat',
));
break;
case 'offer':
wp_nav_menu(array(
'menu' => 'offer',
'fallback_cb' => 'get_cat',
));
break;
}
?>
I'm really frustrated at this point. Any ideas?
I don't see where you are assigning a value to $master_page, so at this point it is just an empty variable.
You need to look into the is_page() and is_category() functions in WordPress and use if statements rather than a switch.
<?php
if( is_page( 'about' ) ) {
wp_nav_menu(array(
'menu' => 'about',
'fallback_cb' => 'get_cat',
));
} else {
...
}
?>
I'm using the Advanced custom field plugin and having trouble showing custom fields of children in a loop. I tried this:
<?php <br /> $pages = get_pages(array('child_of' => $post->ID));
foreach($pages as $page)
{
setup_postdata($page);
$fields = get_fields(); print_r($fields);
}
wp_reset_query();
?>
When I put print_r($page) in it says 1111 so that bit is working (as there's 4 children items).
That code just prints the custom field names of the parent rather than the children, how can I show the children's custom fields?
It should've been post instead of page, doh!
http://support.plugins.elliotcondon.com/discussion/43/show-page-children-or-subpages-with-custom-fields
Have you tried this?
get_pages(array('child_of' => $post->ID, 'parent' => $post->ID, 'hierarchical' => 0))
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. :)