WordPress.org

Ready to get started?Download WordPress

Forums

Editing code to show author (7 posts)

  1. tajasel
    Member
    Posted 2 years ago #

    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?

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    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)

  3. tajasel
    Member
    Posted 2 years ago #

    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.)

  4. alchymyth
    Forum Moderator
    Posted 2 years ago #

    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>'; }
  5. tajasel
    Member
    Posted 2 years ago #

    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>';
                    }
  6. Jose Castaneda
    Member
    Posted 2 years ago #

    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.

  7. tajasel
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags