Get image from one page and showadd it on another page

admin2025-01-08  4

We have one custom requirement that when we add an image (suppose a car image) in the homepage, after that when I'm creating a new page, I always want that car image to appear on the right hand side by default. So whenever I'm changing the homepage car image to some other image, it should reflect on other pages also.

I'm just unable implement this requirement, how to go about it?

We have one custom requirement that when we add an image (suppose a car image) in the homepage, after that when I'm creating a new page, I always want that car image to appear on the right hand side by default. So whenever I'm changing the homepage car image to some other image, it should reflect on other pages also.

I'm just unable implement this requirement, how to go about it?

Share Improve this question edited Apr 26, 2015 at 16:24 Gabriel 2,24810 gold badges22 silver badges24 bronze badges asked Apr 26, 2015 at 16:10 AtiqAtiq 13 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 0

You require Advanced Custom Fields. Install the plugin in your site.

Advanced Custom Fields

Read the above documentation. Create a image upload field and use the field in both front-page.php and content-page.php

I suppose you are talking about featured image functionality?

In technical terms the featured image is attachment and post “knows” about it by its ID being stored in post meta. There is a pretty straightforward function get_post_thumbnail_id() to retrieve that ID for specific post.

It is slightly trickier to have it attached to new posts by default. There is a get_default_post_to_edit() function that handles defaults, but it mostly deals with text of the post. Personally I have used default_content filter in it to assign custom fields, using second $post argument passed to it. It's not too technically “correct” I suppose, but it makes semantic sense to me and I am not aware of better suited hook.

the easiest way would be to use the plugin advanced custom fields. with this you could create an options page where you can register a buld field.

otherwise you could create your own option pages with your own meta fields e.g. like here

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736268900a1311.html

最新回复(0)