366 posts
    Has referred 10+ members Has sold $125,000+ on Envato Market Has collected 10+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+5 more
PixelStores says

For one of my projects what i did was to use the get_template_part function and and a number of if statements to show the right header the user has chosen in the custom field for that page.

So for example, if your using the WPAlchemy_MetaBox class and have a select box for one of your custom fields you could use this code or similar to determine what the user has chosen for the header.

function get_header_template() {
    global $post, $your_mb;
    $meta = get_post_meta(get_the_ID(), $your_mb->get_the_id(), TRUE);        
    switch ($meta[header_choice]) {
        case 'header_one': 
            get_template_part( 'templates/header', 'one' );        
        break;
        case 'header_two': 
            get_template_part( 'templates/header', 'two' );                
        break;
        case 'header_three': 
            get_template_part( 'templates/header', 'three' );        
        break;
        case 'header_four':
            get_template_part( 'templates/header', 'four' );        
        break;
        default:        
    }
}

The following files would have the different template design/structure code,

/templates/header-one.php
/templates/header-two.php
/templates/header-three.php
/templates/header-four.php

You could also use your theme options api that could set the default header template.

Hope this helps..

Matt

13 posts
    Has collected 1+ items on Envato Market Has been part of the Envato Community for over 1 year Sells items exclusively on Envato Market
themelines says

Hy PixelStores (Matt) .. thanks for reply.

If i change the header of the theme option is successful. I am still very confused how to get into the menu. Whether the header should be made like this.

<? php
/*
  Template Name: Header 1
*/
  ?>

Sorry if I am asking a lot, I just started in wordpress :)

366 posts
    Has referred 10+ members Has sold $125,000+ on Envato Market Has collected 10+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+5 more
PixelStores says

Hy PixelStores (Matt) .. thanks for reply.

If i change the header of the theme option is successful. I am still very confused how to get into the menu. Whether the header should be made like this.

<? php
/*
  Template Name: Header 1
*/
  ?>
Sorry if I am asking a lot, I just started in wordpress :)

The method your mentioning with the template names is for creating page templates, you won’t have to do this if you have some options the user selects in the theme options…

You would create a select box in the theme options with some values like “Header 1” that are saved based on the users choice… You would write a similar function to the one i wrote earlier but you would use the switch method for the theme options instead of the custom fields.

Cheers

by
by
by
by
by
by