371 posts
  • Has referred 50+ 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
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Located in Indonesia
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 :)

371 posts
  • Has referred 50+ 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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by