Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I seem to be having problems when using custom page templates using wp_list_pages.
These pages are always displayed at the bottom of the website in a menu.

The problem is, that they should have a collapsible menu with the children in them, but the children are not showing. These children do not have the same template type as the parents, which is the cause of my problem, I guess.

Below you can find how I call wp_list_pages. It does fetch and display the parents correctly, but not the children.

$brands = wp_list_pages(array('title_li' => '',
    'post_type' => 'page',
    'meta_value' => 'brands.php',
    'lang' => $GLOBALS["pll_language"],
    'showposts' => 20));

Any thoughts on how I can resolve this?

EDIT This is an example of the structure of the pages.

  • Nike
    • Shoes
      • Shoe 1
      • Shoe 2
      • Shoe 3
    • Shirts
    • Sunglasses
  • Brand 2
  • Brand 3
  • etc... until brand 9

But shoe 1 could be removed at any time and shoe 4 can be added at any time. Since I don't want to update the menu all the time, I only want to have to add "Nike", "Brand 2" to the menu and all the other pages would have to load automatically. Any ideas?

share|improve this question
    
Have you tried running this without some of the arguments (especially the redundant meta_value and the non-existent lang)? –  Johannes Pille Jul 27 '13 at 9:28
    
When I leave out the meta_value, he shows all pages and all children. But I only need the "brands"-template. That is: the top-level are "brands", the children of those brands are another template. "Lang" is defined in the polylang-plugin and doesn't change anything when leaving it out. –  Michiel Standaert Jul 27 '13 at 9:30
add comment

1 Answer 1

up vote 1 down vote accepted

Your initial concrete problem

Mkay. I think I understood what it is you are trying to do.
You are attempting to identify the pages (and subpages) you want to list by the page template being used by the parent pages and that by means of checking the value of the _wp_page_template postmeta.

For one, that feels like a rather hacky approach in the first place, and, for another, it is in the nature of how the meta_value parameter works, that it then will exclude all pages, that do not have that custom field value set.

If you must stick to wp_list_pages, the simplest solution might be to create one more (utility) page, make that the uber-parent of all brand-pages and make use of the child_of parameter:

$brands = wp_list_pages(
    array(
        'title_li' => '',
        'child_of' => 123 // page ID of the uber-parent
    )
);

Note that wp_list_pages does neither accept a lang nor a showposts parameter. Those are most certainly meaningless to the function.
Further, 'page' is the default argument for the post_type parameter and hence redundant.

Also note that wp_list_pages is not the most flexible approach to creating a menu. If my admittedly also rather quick and dirty solution offered above does not cut it, you might want to familiarize yourself with wp_nav_menu or custom queries and the WP_Query class instead.

Your general architectural approach

Pertaining to your edit:

Again, it isn't as if one definite correct solution exists, as now we're not talking about a concrete problem anymore but are entering the realm of architecture.

Given the information you have provided, this would be my approach:

I'd create a custom taxonomy for the brands (where the actual brands, such as "Nike", are the terms) and a custom post type for the products.

Either one post type called "product", where the kinds of product ("Shoe", "Shirt", "Sunglasses") are identified by metavalues, or a post type for each type of product (likely cleaner).

The products themselves ("Shoe 1", "Shoe 2") then will be posts of type "product" (or "shoe", respectively).

share|improve this answer
    
I'm going to try with the wp_nav_menu, because it isn't all that hackish, but is there a way to include and sub-menu's automatically? (So I only have to add the top-parent in the menu) Because the structure of the brands will be changing a lot and I don't want to go and change it time after time on the menu page. –  Michiel Standaert Jul 27 '13 at 11:22
    
Well, @Michiel, the range of what other approaches you could go with is quite broad. The cleanest would probably be to abstain from using pages and creating a Custom Post Type (or 2) instead. What exactly would be the best advice depends on how much time you want to spend and how large and long-term this project is... –  Johannes Pille Jul 27 '13 at 11:38
    
I have thought of custom post types already, but there are at least 9 brands which all need to have their own individual menu, so I would have to create 9 post types (unless you have some other advice). I will update my question to show how the structure is. –  Michiel Standaert Jul 27 '13 at 11:47
    
I've updated my question with the structure. Any ideas on what the best approach would be? –  Michiel Standaert Jul 27 '13 at 11:55
    
See updated answer. I am not going to say it's the definite "best approach", but that's how "my approach" would look like. –  Johannes Pille Jul 27 '13 at 12:09
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.