[Resolved] add additional fields after the single post author line in the blogs

Home Forums Support [Resolved] 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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #72147
    Anders Kofoed

    Hi!

    I have been using GP on my private homepage for a while – now i have got permission to change our companys old TwentyThirteen theme to something little nicer and easier to work in.

    I have been building up a test site with GP theme and as soon i have every details in the page and it is accepted, we will upgrade to the full version.

    However, i been looking for plugins to do this, but no one applies my needs.

    I want to have a very simple this post is written by line on the posts to add some fields for the author like “title”, “company” and “office”

    however my experience for coding this into the site is not the best and i’m too unsecure where to start – maybe you could help or guide me in the correct direction!

    Like this:
    I wonder if it is possible to change this to add some custom fields for each user to fit the below variables

    %TITLE%, %COMPANY%, %OFFICE%.

    So whenever a user post a new item on our blog, the line:

    “%date%, %year% by: %author%, %title%, %company%, %office location%”

    so above would be printed as below, taken from the user profiles inserted data:

    February 4, 2015 by: Andy Andyson, Senior Consultant, Company, Stockholm Office.

    Example:

    The line below “post header” on this page: http://mbnordic.com/uncategorized/testtester/

    The line: February 4, 2015 by Anders Kofoed

    i would like to have extended with the variables (if inserted)

    so it would be like (my users fields) Name(author) (title) (company) and (office)

    February 4, 2015 by Anders Kofoed, Title, Company, Office.

    hope you can help! thanks!

    //Anders

    #72240
    Tom
    Lead Developer
    Lead Developer

    Hi Anders,

    I see what you mean – this would be quite complicated to code I’m thinking. You would have to somehow filter into the get_the_author() WordPress function and add the new fields in there.

    I’m not sure how exactly you would go about doing that, but you may need to hire a developer to get you started.

    Sorry I can’t be more helpful!

    #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

    #72612
    Tom
    Lead Developer
    Lead Developer

    Very nice, great job! ๐Ÿ™‚ Thanks for posting!

    Make sure you copied the content-single.php file from the parent theme and added it to your child theme before editing, or you’ll lose the changes when you update GP.

    #72661
    Anders Kofoed

    Hi Tom.

    I’m glad that i could share! ๐Ÿ™‚

    I am aware of the child theme!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.