WordPress.org

Support

Support » Themes and Templates » Editing code to show author

Editing code to show author

  • The code for showing the date/time/author for my theme is as follows:

    if(is_home()) {
    	if(pbt_theme_option('dates_index') == 'on') { echo '<div class="date">'; the_time(get_option('date_format')); echo '</div>'; }
    	if(pbt_theme_option('authors_index') == 'on') { _e("By", "magazine-basic"); echo ' '; the_author_posts_link(); }
    }

    This produces the date/time and author on separate lines in different font styles, as you can see here: http://www.onehotcrumpet.co.uk/2012/02/13/bravery/ (link potentially NSFW)

    I would like the date/time and author on the same line, in the same font style, but every edit I’ve made has broken the code in some way. Can any of you help fix this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael

    @alchymyth

    Forum Moderator

    try and change the posted section to:

    if(is_home()) {
      if(pbt_theme_option('dates_index') == 'on' || pbt_theme_option('authors_index') == 'on' ) { echo '<div class="date">';
        if(pbt_theme_option('dates_index') == 'on') { the_time(get_option('date_format'));  }
        if(pbt_theme_option('authors_index') == 'on') { _e(" by", "magazine-basic"); echo ' '; the_author_posts_link(); }
      echo '</div>'; }
    }

    (it might mess with the translation if you ever need one)

    Hmm, that code doesn’t break the theme, but just gets rid of the date/author altogether!

    To clarify, I’m happy with the way the homepage of the site looks.
    This is for single posts, where the following to appear beneath the title:

    February 13, 2012 by tajasel

    Currently, it prints:

    February 13, 2012 by
    By tajasel

    (Where italics indicate a different text style.)

    Michael

    @alchymyth

    Forum Moderator

    the code you posted starts with the conditional statement is_home() and will therefore not show on single posts;

    (I might have missed that you are aiming for single posts)

    try to use the code without the surrounding conditional statement; example below:

    if(pbt_theme_option('dates_index') == 'on' || pbt_theme_option('authors_index') == 'on' ) { echo '<div class="date">';
        if(pbt_theme_option('dates_index') == 'on') { the_time(get_option('date_format'));  }
        if(pbt_theme_option('authors_index') == 'on') { _e(" by", "magazine-basic"); echo ' '; the_author_posts_link(); }
      echo '</div>'; }

    Oh, rubbish, right, yes. Here’s the code I actually meant to post!

    if(is_single()) {
    	                echo '<div class="meta">';
    	                    if(pbt_theme_option('dates_posts')=='on') { echo '<div class="date">'; the_time(get_option('date_format')); echo ' by <?php the_author() ?> </div>'; }
    	                    if(pbt_theme_option('authors_posts')=='on') { _e("By", "magazine-basic"); echo ' '; the_author_posts_link(); }
    	                echo '</div>';
                    }
    Moderator Jose Castaneda

    @jcastaneda

    THEME COFFEE MONKEY

    I want to say part of it may very well be with the styling. Try displaying the div.date inline and see if that may help.

    To be honest, I suspect if I can find a way to shift the </div> from line 3 in the extract to after the author tag, then both bits of text will end up on the same line in the same font style, but I haven’t been able to do that without breaking the code.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Editing code to show author’ is closed to new replies.
Skip to toolbar