Community Forums › Forums › Archived Forums › Design Tips and Tricks › Creating a custom field in a word press post
- This topic has 12 replies, 2 voices, and was last updated 8 years, 7 months ago by benjamin.
-
AuthorPosts
-
August 24, 2015 at 2:25 pm #163343benjaminParticipant
I need to insert a dynamic banner in a post just after the post content.
I've been trying the information on the page below but can't get it right.
From the part about telling wordpress where the field should go.
I'm also not sure that's what I need.
http://wpsites.net/web-design/how-to-create-a-custom-field/I'd inserted this line in the functions file but that either didn't work or prevented the site from loading.
get_post_meta( $post=>ID, 'PBBanner', true );I did this some years ago with my first theme with help from the forum.
But that was lost when the forum platform was changed.What we did last time was to edit the functions file, I don't remember if the style.css was edited also.
Then entered a little bit of code exactly where I wanted the banner to appear. Something like this;
[field name="PBBanner"] where PBBanner is the custom field name.How do I do this?
August 24, 2015 at 4:31 pm #163350Brad DaltonParticipantI assume you added the HTML for the image to the custom fields value field?
Simply pasting the get_post_meta function into the functions file will not work without adding a hook.
You need to add it to a custom function and you'll find a working example in the tutorial you linked to.
August 24, 2015 at 10:04 pm #163383benjaminParticipantThe banner uses javascript code below that allows it to update with the latest text and images.
<div id="_TC_PB_BANNER"></div>
<script type="text/javascript">
_TRIPLECLICKS_PB_BANNER_URL="//www.tripleclicks.com/pbBanner.php?sfiid=&view=W&curr=USD";
</script>
<script type="text/javascript" src="//tc.csidn.com/common/pbBanner.js"></script>Such can easily be placed into a text widget but I want to place it with the post text.
August 25, 2015 at 12:07 am #163392Brad DaltonParticipantHook the widget using the_content filter or genesis_entry_content hook.
August 25, 2015 at 12:31 pm #163461benjaminParticipantFirst I didn't understand the position part of the tutorial and as for hooks I don't remember what those are.
I spent months fidgeting with one hook after another till I felt I'd brought the site up to a point I felt I could live with.
Now starting that all over again is overwhelming,Where can I find those hooks and how do i apply it, I really have no idea.
August 26, 2015 at 2:24 pm #163609benjaminParticipantI went back to the functions file of the previous theme to try and figure out what I did the last time.
I think this was the piece of text added.// Create customer field
function field_func($atts) {
global $post;
$name = $atts['name'];
if (empty($name)) return;
return get_post_meta($post->ID, $name, true);
}add_shortcode('field', 'field_func');
I added it to the functions file and now the [field name=”PBBanner”] that was showing up in the post instead of the banner has disappeared leaving a blank space a little bigger than the banner that is supposed to be there.
What else should be done?I've been looking through the styles sheet but it's much longer,
I've run out of ideas.August 26, 2015 at 5:45 pm #163666Brad DaltonParticipantI think you want to use the custom field within the content of a post right? I mean, in the middle of the content?
Also, please use code tags or Github gists with PHP.
August 26, 2015 at 10:02 pm #163692benjaminParticipantYes within the content even in the middle of it.
August 26, 2015 at 10:56 pm #163693Brad DaltonParticipantYou could use a plugin https://wordpress.org/plugins/custom-fields-shortcodes/
August 27, 2015 at 1:55 pm #163789benjaminParticipantThe plugin hasn't been updated in over 2 years, doesn't looks safe.
I'd rather go with the codes. Just can't make it work this time round.August 27, 2015 at 2:35 pm #163794benjaminParticipantIs it possible that this function or some other function it depends on is not active?
I've been looking & trying out every variation I can find on the search engines but none have worked.August 28, 2015 at 1:08 pm #163923benjaminParticipantI'll go for the plugin after all, I'm not going to manage this one.
August 31, 2015 at 2:22 pm #164161benjaminParticipantI installed Advanced Custom Fields plugin but from the videos I've seen on YouTube, you still have to go edit the theme templates. How sad...
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.