360 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Has been a member for 4-5 years
  • New Zealand
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
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
  • Indonesia
  • Has been a member for 1-2 years
  • Exclusive Author
YudiArnanda 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 :)

360 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Has been a member for 4-5 years
  • New Zealand
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
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