Support » Fixing WordPress » Echo simple field value across pages

  • Hi again, i’ve already asked this question regarding ACF, but now i’ve reverted back to just using normal simple fields, and i was wondering if there was a way to almost duplicate whatever is in one custom field, across all pages in a div.

    So for instance, on the homepage, ive placed a simple field which needs to be editable, but it’s consistant throughout the site, thus needing it to be editable, but it edits it across all the pages if that makes sense?

    Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    What is simple fields? a plugin? Or do you mean custom fields?: http://codex.wordpress.org/Custom_Fields

    Yeah its a plugin, but i meant, custom fields, sorry for the confusion there!

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    So for instance, on the homepage, ive placed a simple field which needs to be editable,

    Sorry for all the questions, but, do you want it editable on the front end of your website?
    Or do you want to use the custom field value from the latest post on your front page on all template files.
    Do you have a static front page? http://codex.wordpress.org/Creating_a_Static_Front_Page

    Sorry I probably didn’t make myself very clear.

    Yes my front page is static (all the pages are ‘static’ pages). Above my actual ‘footer’, I have a place to put images in, which need to be the same across every page, but placing it on every page, and inserting every image to every page is pointlessly time consuming, so I was just wondering if there was a way to have it;

    editable on the homepage, and then the other pages almost copy whatever is in that custom field, and places it there as well. I’m pretty much a novice with WordPress/PHP :/

    Sorry i’m probably over confusing you there!

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Use the Page id of your static home page to show the image:

    <?php
    $home_page_id = 23;
    $home_page_value = get_post_meta($home_page_id, 'home_image', true);
    if($home_page_value != '') : ?>
    <img src="<?php echo $home_page_value; ?>" />
    <?php endif; ?>

    Use this snippet in all your other template files (page.php, category.php, etc, etc).
    Change 23 and home_image (custom field key) to the correct values.

    Okay, i’ll give that a go and let you know how it goes!

    Thanks for the quick responses!

    Hi again, i’ve tried it and it doesn’t seem to display the image…

    My code as it stands is:

    <div class="sponsersretrieve">
    
    <?php $sponsersretrieveID = $post->ID;
    				$sponsersretrieve = simple_fields_get_post_group_values($sponsersretrieveID, "sponsersretrieve", false, 2);
    
    				foreach ($sponsersretrieve as $value) {
    				echo wp_get_attachment_image($value[1], $size='full');
    				}
    				?>
    
    </div>

    as the image to retrieve and on the page(s) to be displayed on it’s:

    <?php
    $home_page_id = 2;
    $home_page_value = get_post_meta($home_page_id, 'sponsersretrieve', true);
    if($home_page_value != '') : ?>
    <img src="<?php echo $home_page_value; ?>" />
    <?php endif; ?>

    Have I done something insanely stupid or …? Sorry to be a pain!

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Sorry i’m probably over confusing you there

    This is indeed very confusing, but we’re getting there. I will download the simple fields plugin. (So you’re using the plugin)

    What do you see when you do this (for testing):

    $sponsersretrieveID = $post->ID;
    $sponsersretrieve = simple_fields_get_post_group_values($sponsersretrieveID, "sponsersretrieve", false, 2);
    echo '<pre>';
    print_r($sponsersretrieve);
    echo '</pre>';

    also do the same but change it to:

    $sponsersretrieveID = 2;
    simple_fields_get_post_group_values($sponsersretrieveID, "sponsersretrieve", false, 2);
    echo '<pre>';
    print_r($sponsersretrieve);
    echo '</pre>';

    When I paste that in, I get the following displayed on the screen:

    Array
    (
        [0] => Array
            (
                [1] => 224
            )
    
    )

    And nothing appears on other pages with that second bit of code you just posted.

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Is 224 the ID of the attachment you want to show?

    Yes, 224 is the ID of the image I want to show 🙂

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    try changing:

    echo wp_get_attachment_image($value[1], $size='full');

    to:

    echo wp_get_attachment_image($value[1], 'full');

    Nope, still doesn’t work on the other pages… :/

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Echo simple field value across pages’ is closed to new replies.