• Resolved RSimpson

    (@rsimpson)


    Hi folks,

    I’ve got a custom field called is_homepage which I define in the templates using $is_homepage = get_post_meta($post->ID, 'is_homepage', true);

    Within the sidebar I have this code:

    if (is_page()) {
    	if ($is_homepage == TRUE) {
    		if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Homepage Top')) : endif;
    		if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Homepage Bottom')) : endif;
    	} else {
    		if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Pages Top')) : endif;
    		if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Pages Bottom')) : endif;
    	}
    }

    So as you can see I have 2 widgetised sidebars for both regular pages and the homepage itself. The reason there are 2 for each one is just in case I want to add something to the middle of a sidebar and there isn’t actually a widget for it, I can just code it inbetween.

    Now here’s the weird thing. Even with the custom field defined as TRUE on the actual homepage (reading settings dictate that the home page is a static page, not the blog), this code doesn’t recognise the variable. Or to be more precise, the entire sidebar template file doesn’t recognise it, even though I’ve defined it at the top.

    Whenever a page is loaded it shows the standard page sidebars, regardless of the custom field having a value. If I change the code to say if ($is_homepage == FALSE) { it loads the homepage sidebars on all of the standard pages (including home).

    Can anyone see where I’m going wrong?

    Cheers,
    Robert

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Odd custom field behaviour in sidebar’ is closed to new replies.