Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2016-12-22 01:22:23

michilge
Member
From: Sprockhövel, Germany
Registered: 2013-04-15
Posts: 206
Website

Display Author in Blog Post

Is there a way to do that with Backlight Theme for Wordpress?

Thanks in advance
Michael

Offline

#2 2016-12-22 01:49:54

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Display Author in Blog Post

The best way is by creating a child theme.
Then copy the contents.php file from your-theme/template-parts/, modify it, and include it in the child theme folder.

Just playing with the contents.php file on my test site, I changed this section starting on line 52 (or so):

<div class="post-meta">
	<p class="post-date">
	<time class="date updated" datetime="<?php the_time(__('Y-m-dh:i:s T', 'RB-photo-main-nav-below-masthead')); ?>" pubdate="pubdate"><?php the_time(get_option('date_format')); ?></time>
	<?php edit_post_link( __('Edit', 'RB-photo-main-nav-below-masthead'),'',''); ?>
	</p>
</div><!-- .post-meta -->

to this:

<div class="post-meta">
	<p class="post-date">
	Posted by <?php the_author(); ?> on <time class="date updated" datetime="<?php the_time(__('Y-m-dh:i:s T', 'RB-photo-main-nav-below-masthead')); ?>" pubdate="pubdate"><?php the_time(get_option('date_format')); ?></time>
	<?php edit_post_link( __('Edit', 'RB-photo-main-nav-below-masthead'),'',''); ?>
	</p>             
</div><!-- .post-meta -->

But don't just copy and paste what I have here, you'll need your own file that reflects the name of your template.

place your new content.php file in the child theme's folder alongside style.css and functions.php

You can see the result here: http://backlight-rb-test.barbeephoto.co … ing-thing/


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#3 2016-12-23 10:00:01

michilge
Member
From: Sprockhövel, Germany
Registered: 2013-04-15
Posts: 206
Website

Re: Display Author in Blog Post

Hello Rod,

I originally started this post to ask further questions, but describing what I tried so far helped me find my mistake.

What's left is to say Thank You.

Yours
Michael

Offline

#4 2016-12-24 05:09:23

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Display Author in Blog Post

in case anyone else is following this, I just tried creating a child theme and then simply including my modified content.php file in the child theme directory. Frustratingly, this did not work.

According to the WordPress Codex:

If you want to change more than just the stylesheet, your child theme can override any file in the parent theme: simply include a file of the same name in the child theme directory, and it will override the equivalent file in the parent theme directory when your site loads.

They mean this literally it appears.
Since the content.php file is in the template-parts/ folder of the parent theme, it must also be in a folder of the same name in the child theme's folder. I spent a good hour or two trying to see what I did wrong with code before I took what I thought was a long-shot chance at simply creating a "template-parts" folder and moving the content.php file there. But that's what works.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#5 2016-12-24 05:22:44

michilge
Member
From: Sprockhövel, Germany
Registered: 2013-04-15
Posts: 206
Website

Re: Display Author in Blog Post

Exactly.
Plus there are several instances in content.php where the theme name must be changed to the name of the child theme to prevent functions from being void. I will post a writeup with source code to round up this thread as soon as I get on a computer with a keyboard and rename the thread title to something related to child theme creation.

Offline

#6 2016-12-24 06:35:40

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Display Author in Blog Post

ooh. good catch.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#7 2016-12-24 12:11:25

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: Display Author in Blog Post

Since we're on the topic, here's some template code I've worked up for child themes.

functions.php

<?php

	/**
	 * Load stylesheet from parent, then from child.
	 */
	function my_theme_enqueue_styles() {
	
		$parent_style = 'parent-style';
		
		wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'child-style',
			get_stylesheet_directory_uri() . '/style.css',
			array( $parent_style ),
			wp_get_theme()->get('Version')
		);

	}
	add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );


	/**
	 * Custom script
	 */
	function enqueue_custom_script() { 
		if( wp_script_is('jquery','done') ){ ?>

<script>
(function($) {

	//$...

})( jQuery );
</script>

<?php }
	}
	add_action('wp_footer', 'enqueue_custom_script', 22);

?>

style.css

/*
 Theme Name:   Backlight Child Theme
 Theme URI:    
 Description:  
 Author:       
 Author URI:   
 Template:     backlight
 Version:      1.0.0
 License:      
 License URI:  
 Tags:         
 Text Domain:  backlight-child-theme
*/

The functions.php file is the really helpful thing, I guess. ;-)


Matt

The Turning Gate, http://theturninggate.net

Offline

#8 2017-01-08 00:59:30

michilge
Member
From: Sprockhövel, Germany
Registered: 2013-04-15
Posts: 206
Website

Re: Display Author in Blog Post

This is almost exactly what my files look like.

There is one thing still which I am not completely sure about yet:

When I try to edit a post in a browser while wathing the console, I see a 404 error for the GET on

https://fotos.michilge.de/blog/wp-content/themes/BacklightReseda-child/style_admin.css?ver=4.7

I tried to enqueue that in this way:

    wp_enqueue_style( $parent_style,
		get_template_directory_uri() . '/style.css',
		get_template_directory_uri() . '/style_admin.css'
	);

But that didn't do the trick.

For the moment I simply copied the style_admin.css from the Backlight Theme folder to the child theme folder.
But I am quite certain that is not the way it should be done since the file might be changed in the parent theme.

Last edited by michilge (2017-01-08 01:00:24)

Offline

#9 2017-01-08 12:39:17

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: Display Author in Blog Post

I believe you need a separate wp_enqueue_style() for each stylesheet. Check the Wordpress codex on for details on using the function.


Matt

The Turning Gate, http://theturninggate.net

Offline

#10 2017-01-08 20:59:59

michilge
Member
From: Sprockhövel, Germany
Registered: 2013-04-15
Posts: 206
Website

Re: Display Author in Blog Post

Hi Matthew,

thank You for the hint.
I will have to do that codex research part. Confidently trying it out did not eliminate that 404 error ;-)

Offline

#11 2017-01-09 05:21:09

michilge
Member
From: Sprockhövel, Germany
Registered: 2013-04-15
Posts: 206
Website

Re: Display Author in Blog Post

Hmm.

Themeing the admin pages seems to be something completely different.
According to https://codex.wordpress.org/Creating_Admin_Themes it should by done via a plugin (that makes use of "wp_enque_style()" nevertheless ...)

I looked around a little:
Currently, the file "style_admin.css" is enqueued by the Backlight parent theme via the file "inc/theme_posts.php"
There is a passage

function backlight_post_meta_setup() {
	wp_enqueue_style( 'style_admin', get_stylesheet_directory_uri() . '/style_admin.css' );

	add_action( 'add_meta_boxes', 'post_meta_post_options' );

I don't really understand why it is searched in the child theme directory then. Shouldn't "get_stylesheet_directory_uri()" from the scope of the parent theme insert the path to the parent theme?
Seems not ...
Or should perhaps "inc/theme_posts.php" use "if ( is_child_theme() )" to test if "get_template_directory_uri()" should be used instead?
I believe, this could perhaps better be changed in the parent theme to make it child-proof.


If I copy "style_admin.css" to the child theme's directory everything is fine of course.

Offline

#12 2017-01-09 09:17:34

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Display Author in Blog Post

Shouldn't "get_stylesheet_directory_uri()" from the scope of the parent theme insert the path to the parent theme?

That function returns the directory of the current child theme folder (or theme if no child is being used)
https://codex.wordpress.org/Function_Re … ectory_uri


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

Board footer

Powered by FluxBB