• Resolved JCataln

    (@jcataln)


    Hey,

    I’m trying to add the “written by” line to all the posts, so that the reader knows who the specific author is. I successfully introduced the line on the index page, but I don’t know how to add it to each post.

    Any help would be great, thank you.

    – Jon Catalán

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter JCataln

    (@jcataln)

    To specify, the code I have so far is:

    <?php
    get_header(); ?>
    
    <div id="content-wrap">
    	<div id="content">
    
    <?php if ( $paged < 2 ) {  // Do stuff specific to first page  ?>
    
    	<?php if (have_posts()) : ?>
          <?php
    $sticky=get_option('sticky_posts');
    $args=array(
       'caller_get_posts'=>1,
       'post__not_in' => $sticky,
       'posts_per_page'=>1,
       );
          $my_query = new WP_Query($args);
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID;?>
          <div class="xxxpost lastlast" id="post-<?php the_ID(); ?>">
    <div class="lastimage">
    <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><div class="pik" style="background: url(<?php the_post_image_url('medium'); ?>) center top no-repeat; width: 250px; height:200px; border: 1px solid #777;">
    </div></a>
    </div>
    
    <div class="atas-post"><?php the_time('F jS, Y') ?> - <?php the_time() ?> <!-- &sect; <?php _e('by'); ?> <?php the_author() ?>  --> &sect; in  <?php the_category(', ') ?></div>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <br />
    <p><i><b>Written by:</b>
    <?php the_author_posts_link(); ?></i></p>
    <br /><br />
    
    				<div class="entry">
    					<?php
    $content = get_the_content('read more');
    $content = apply_filters('the_content', $content);
    $content = preg_replace('|<img (.+?)>|i', '', $content);
    $content = preg_replace('|<div id="attachment_(.+?)" class="wp-caption(.+?)<\/div>|i', '', $content);
    echo $content;      ?>
    				</div>
    
    				<div class="postmetadata"><span class="lefter"><?php the_tags('Tags: ', ', ', ''); ?></span> <span class="righter"><?php edit_post_link('Edit', '', '  '); ?>  <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span></div>
    </div>
    
          <?php endwhile; ?>
    <br class="clear" />
    <?php
     $counter = 0; $counter2 = 0;
    $args=array(
       'caller_get_posts'=>1,
       'post__not_in' => $sticky,
       'paged'=>$paged,
       'posts_per_page'=>7,
       );
    query_posts($args);
    while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); 
    
     $counter++; $counter2++;
      ?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<div class="<?php if ($counter == 1) { echo 'leftside'; } else { echo 'rightside'; $counter = 0; } ?>">
    <div class="atas-post"><?php the_time('F jS, Y') ?> - <?php the_time() ?> <!-- &sect; <?php _e('by'); ?> <?php the_author() ?>  -->&sect; in  <?php the_category(', ') ?></div>
    
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <div class="theimage">
    <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><div class="pik" style="background: url(<?php the_post_image_url('thumbnail'); ?>) center center no-repeat; width: 150px; height:110px; border: 1px solid #777;">
    </div></a>
    
    </div>
    				<div class="entry">
    					<p><?php
    						$texter = get_the_excerpt();
    						if(strlen($texter ) > 300) {
    						$texter = substr($texter , 0, 300);
    						}
    						echo ''.$texter.'[...]';
    						?>
    						</p>
    				</div>
    
    <br />
    <p><i><b>Written by:</b>
    <?php the_author_posts_link(); ?></i></p>
    <br /><br />
    
    				<div class="postmetadata"><span class="lefter"><?php the_tags('Tags: ', ', ', ''); ?></span> <span class="righter"><?php edit_post_link('Edit', '', '  '); ?>  <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span></div>
    
    			</div>
    
    <br class="clear" />			</div>
    
    		<?php endwhile; ?>
    <br class="clear" />
    
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
          <div class="navigation">
            <div class="alignleft">
              <?php next_posts_link('&larr; Previous Entries') ?>
            </div>
            <div class="alignright">
              <?php previous_posts_link('Next Entries &rarr;') ?>
            </div>
          </div>
          <?php } ?>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    <?php } else { // Do stuff specific to non-first page ?>
    <?php
     $counter = 0; $counter2 = 0;
    $args=array(
       'caller_get_posts'=>1,
       'post__not_in' => $sticky,
       'paged'=>$paged,
       'posts_per_page'=>6,
       );
    query_posts($args);
     while (have_posts()) : the_post();
     $counter++; $counter2++;
    ?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <div class="<?php if ($counter == 1) { echo 'leftside'; } else { echo 'rightside'; $counter = 0; } ?>">
    <div class="atas-post"><?php the_time('F jS, Y') ?> - <?php the_time() ?> <!-- &sect; <?php _e('by'); ?> <?php the_author() ?>  -->&sect; in  <?php the_category(', ') ?></div>
    <div class="theimage">
    <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><div class="pik" style="background: url(<?php the_post_image_url('thumbnail'); ?>) center center no-repeat; width: 150px; height:110px; border: 1px solid #777;">
    </div></a>
    </div>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    				<div class="entry">
    					<p><?php
    						$texter = get_the_excerpt();
    						if(strlen($texter ) > 300) {
    						$texter = substr($texter , 0, 300);
    						}
    						echo ''.$texter.'[...]';
    						?>
    						</p>
    				</div>
    
    				<div class="postmetadata"><span class="lefter"><?php the_tags('Tags: ', ', ', ''); ?></span> <span class="righter"><?php edit_post_link('Edit', '', '  '); ?>  <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span></div>
    			</div>
    			</div>
    
    		<?php endwhile; ?>
    <br class="clear" />
    
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
          <div class="navigation">
            <div class="alignleft">
              <?php next_posts_link('&larr; Previous Entries') ?>
            </div>
            <div class="alignright">
              <?php previous_posts_link('Next Entries &rarr;') ?>
            </div>
          </div>
          <?php } ?>
    
    <?php } ?>
    	</div>
    </div>
    
    <br class="clear" />
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    I don’t know where to add it so that appears in each individual post.

    Thread Starter JCataln

    (@jcataln)

    Just thought I’d bump this for a response. Thanks!

    With the help of the Template Hierarchy article, determine what Template is displaying those posts (could be single.php and archive.php) that don’t show the author.

    Then add the code e.g. <?php the_author_posts_link(); ?>
    to those templates.

    Thread Starter JCataln

    (@jcataln)

    Thanks! Got it; it was single.php

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding author to posts’ is closed to new replies.