WordPress.org

Ready to get started?Download WordPress

Forums

Echo simple field value across pages (14 posts)

  1. RForster92
    Member
    Posted 2 years ago #

    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!

  2. keesiemeijer
    moderator
    Posted 2 years ago #

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

  3. RForster92
    Member
    Posted 2 years ago #

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

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    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

  5. RForster92
    Member
    Posted 2 years ago #

    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!

  6. keesiemeijer
    moderator
    Posted 2 years ago #

    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.

  7. RForster92
    Member
    Posted 2 years ago #

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

    Thanks for the quick responses!

  8. RForster92
    Member
    Posted 2 years ago #

    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!

  9. keesiemeijer
    moderator
    Posted 2 years ago #

    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>';
  10. RForster92
    Member
    Posted 2 years ago #

    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.

  11. keesiemeijer
    moderator
    Posted 2 years ago #

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

  12. RForster92
    Member
    Posted 2 years ago #

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

  13. keesiemeijer
    moderator
    Posted 2 years ago #

    try changing:

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

    to:

    echo wp_get_attachment_image($value[1], 'full');
  14. RForster92
    Member
    Posted 2 years ago #

    Nope, still doesn't work on the other pages... :/

Topic Closed

This topic has been closed to new replies.

About this Topic