Reply To: add additional fields after the single post author line in the blogs

Home Forums Support add additional fields after the single post author line in the blogs Reply To: add additional fields after the single post author line in the blogs

Home Forums Support add additional fields after the single post author line in the blogs Reply To: add additional fields after the single post author line in the blogs

#72488
Anders Kofoed

Hi Tom, Thanks for your reply.

To be kind to any other people, and to inform you the solution i found out!

In the functions.php i added this code to add (3) three custom fields (more fields can be added in the code) and then in the

/**
	 * Add AUTHOR extra details - custom author details 
	 */
	add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
	add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

	function my_show_extra_profile_fields( $user ) { ?>	

	<h3>Author Post Details</h3>

	<table class="form-table">

		<tr>
			<th><label for="AuthorDetails">Title</label></th>

			<td>
				<input type="text" name="AuthorTitle" id="AuthorTitle" value="<?php echo esc_attr( get_the_author_meta( 'AuthorTitle', $user->ID ) ); ?>" class="regular-text" /><br />
				<span class="description">Your Job title.</span>
			</td>
		</tr>
		<tr>
			<th><label for="AuthorDetails">Company</label></th>

			<td>
				<input type="text" name="AuthorCompany" id="AuthorCompany" value="<?php echo esc_attr( get_the_author_meta( 'AuthorCompany', $user->ID ) ); ?>" class="regular-text" /><br />
				<span class="description">Millward Brown Nordic</span>
			</td>
		</tr>
		<tr>
			<th><label for="AuthorDetails">Office</label></th>

			<td>
				<input type="text" name="AuthorOffice" id="AuthorOffice" value="<?php echo esc_attr( get_the_author_meta( 'AuthorOffice', $user->ID ) ); ?>" class="regular-text" /><br />
				<span class="description">Enter your office; E.g. "Copenhagen Office" or "Stockholm Office"</span>
			</td>
		</tr>

	</table>
	<?php }
	/**
	 * SAVE AUTHOR extra details - custom author details
	 */
	add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
	add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

	function my_save_extra_profile_fields( $user_id ) {

	if ( !current_user_can( 'edit_user', $user_id ) )
		return false;

	update_usermeta( $user_id, 'AuthorTitle', $_POST['AuthorTitle'] );
	update_usermeta( $user_id, 'AuthorCompany', $_POST['AuthorCompany'] );
	update_usermeta( $user_id, 'AuthorOffice', $_POST['AuthorOffice'] );
}

and in the content-single.php i added the following 3 above variables to be printed on the same line:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> itemprop="blogPost" itemtype="http://schema.org/BlogPosting" itemscope="itemscope">
	<div class="inside-article">
		<?php do_action( 'generate_before_content'); ?>
		<header class="entry-header">
			<h1 class="entry-title" itemprop="headline"><?php the_title(); ?></h1>
			<div class="entry-meta">
				<?php generate_posted_on($AuthorCompany); ?>
				<?php the_author_meta( 'AuthorTitle' ); ?>, 
				<?php the_author_meta( 'AuthorCompany' ); ?>, 
				<?php the_author_meta( 'AuthorOffice' ); ?>.
			</div><!-- .entry-meta -->

This allowed me when you click on the blog post page into the single post to get showed the custom details as asked.

Now it automatically adds title, company and office to the posted by line on the single-post page.

//Anders