WordPress.org

Ready to get started?Download WordPress

Forums

php custom fields not working on home page (2 posts)

  1. wp-krud
    Member
    Posted 1 year ago #

    Hey guys,

    I am trying to add the custom field "market" into the a href"" as links, which is working great on pages, however is not working on my home page.

    Here is the home page where it's not working (the latest releases - as you can see the custom field is not coming through - it directs you to a blank link): http://a.bbtdesigns.com

    And where it is working: http://a.bbtdesigns.com/themes-by-series

    The php is identical for both.

    <a class="ico full" <?php echo $direct_url_new_tab; ?> href="<?php
    						$key = get_post_meta($post->ID, 'blogpost', true);
    						if ($key == '')
    						{ ?><?php $key1="market"; echo get_post_meta($post->ID, $key1, true); ?>
    							<?php } else { ?>
    							<?php $key="blogpost"; echo get_post_meta($post->ID, $key, true); ?><?php } ?>" <?php echo $enable_pretty_photo . ' ' . $pretty_photo_title; ?>></a>

    For the home page, the php is in the functions.php file, and for the theme-by-series page the php is in the page's .php file.

    Any ideas why it's not working?

  2. AJ
    Member
    Posted 1 year ago #

    I am working on a similar issue. It is difficult to get custom fields to work on the blog page.

    I am using a custom field to add a nextgen gallery single image shortcode to each page, and then set it as full page background via css.

    The following function works great inside or outside the loop on every single page in my site except the 'blog' posts page. Added to functions.php:

    //page background from custom field function
    function get_my_page_background() {
    global $wp_query;
    $thePostID = $wp_query->post->ID;
    $page_bg = get_post_meta($thePostID, 'page-background-image', true);
    if ($page_bg) {
    echo  "<span class='page-bg'>"; do_shortcode($pagebg); "</span>";}
    }

    I can call the function in page.php inside or outside the loop, (But it must be inside my main content div for the shortcode to work).

    <!---//individual background from custom fields--->
             <?php if (function_exists('get_my_page_background'))
    		             get_my_page_background();?>

    If I directly paste the shortcode and html that the function generates into the home.php template, it works:

    <span class="page-bg">
    		<?php echo do_shortcode('[singlepic id=382]'); ?>
    </span>
    So the shortcode works fine in the home.php template.

    Can anyone tell me why the function would not work in the posts page template - home.php?

Topic Closed

This topic has been closed to new replies.

About this Topic