Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add Meta Box/Subtitle
- This topic has 2 replies, 2 voices, and was last updated 6 years, 11 months ago by Rachel Lynn.
-
AuthorPosts
-
October 11, 2017 at 12:36 pm #212424Rachel LynnParticipant
I would like to be able to give credit to photographers,contributors, etc. in the same way as the meta box shows the author's name. However; I don't want to use another plugin. Is there a way to add a subtitle below the post title or below the current meta box on select posts, I have tried using wordpress's hook get_post_meta, but I must be doing something wrong. FYI I am using the Lifestyle-Pro. My blog is Queen Bee of honey Dos
http://www.queenbeeofhoneydos.comOctober 11, 2017 at 1:04 pm #212426Victor FontModeratorHow are you storing this extra data? Photographer and contributors are not standard fields, but can be added as custom fields. You can display these custom fields anywhere you'd like on a page, but you have to write your own custom PHP function to do so.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?October 11, 2017 at 1:20 pm #212429Rachel LynnParticipantYes, I understand that they are not standard. I guess I didn't express myself clearly. I would like to be able to enter text (on a case by case basis) into a subtitle box. Something that can be entered manually just below the title (i.e subtitle). I tried adding this code to my functions.php
function your_sub_title() { add_meta_box('your_sub_title_metabox', 'Edit Sub Title', 'your_sub_title_metabox', 'post', 'normal', 'default'); ## Adds a meta box to post type } function your_sub_title_metabox() { global $post; ## global post object wp_nonce_field( plugin_basename( __FILE__ ), 'your_sub_title_nonce' ); ## Create nonce $subtitle = get_post_meta($post->ID, 'sub_title', true); ## Get the subtitle ?> <p> <label for="sub_title">Sub Title</label> <input type="text" name="sub_title" id="sub_title" class="widefat" value="<?php if(isset($subtitle)) { echo $subtitle; } ?>" /> </p> <?php } function sub_title_save_meta($post_id, $post) { global $post; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false; ## Block if doing autosave if ( !current_user_can( 'edit_post', $post->ID )) { return $post->ID; ## Block if user doesn't have priv } if ( !wp_verify_nonce( $_POST['your_sub_title_nonce'], plugin_basename(__FILE__) )) { } else { if($_POST['sub_title']) { update_post_meta($post->ID, 'sub_title', $_POST['sub_title']); } else { update_post_meta($post->ID, 'sub_title', ''); } } return false; } add_action('save_post', 'sub_title_save_meta', 1, 2);
and this code to the post.php
$subtitle = get_post_meta(get_the_ID(), 'sub_title', true); if(isset($subtitle)) { echo $subtitle; }
It does nothing. But, I noticed that there is already this last bit of code written in the post.php. Not sure exactly where to go from here. Probably should scratch all this and start over. I am new to Genesis and my abilities are less than top-of-the-line (to say the least). I had a few courses and understand code when I read it, and can stumble my way through most things that I want, but don't get all the nuances. Changing themes has made it harder on me. 🙁
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.