2013-10-12 30 views
0

一直試圖在Wordpress主題上插入「作者」by <?php the_author() ?>代碼(由8Bit所要求)。請求幫助。需要在帖子/頁面標題之後和日期之前插入。如何在Wordpress中插入「作者」代碼所需主題?

的代碼如下:

<header> 
    <?php if (0 < strlen(get_the_title())) { ?> 
     <h1 class="entry-title"> 
      <a href="<?php the_permalink(); ?>"> 
       <?php the_title(); ?> 
      </a> 
     </h1><!-- /.entry-title --> 
    <?php } // end if ?> 

    <div class="post-meta"> 
     <span class="post-date"> 
      <?php if (0 < strlen(get_the_title())) { ?> 
       <?php the_time(get_option('date_format')); ?> 
      <?php } else { ?> 
       <a href="<?php the_permalink(); ?>"> 
        <?php the_time(get_option('date_format'));?> 
       </a> 
      <?php } // end if/else ?> 
     </span><!-- /.post-date --> 
     <?php _e(' | ', 'required'); ?> 
     <span class="comment-link"> 
      <?php 
       comments_popup_link('Comment', '1 comment', '% comments', 
        'comments-link', ''); 
      ?> 
     </span><!-- /.comment-link --> 
     <?php edit_post_link('- edit ', '<span>', '</span>'); ?> 
    </div><!-- /.post-meta --> 
</header> 

謝謝:)

這是循環代碼:

<?php 
     if (have_posts()) { 

      while (have_posts()) { 


            the_post(); 
       get_template_part('content', get_post_format()); 

      } // end while 
+0

你可以更具體的關於wh在你嘗試過,出了什麼問題?從我的角度來看,它可能就像在標題欄和後期元塊之間插入'<?php the_author()?>一樣簡單,並且添加一些HTML格式化...' –

+0

'通過<?php the_author()?>'在你的代碼中? – codepixlabs

+0

@AlexanderVogt感謝您的回覆。是的,我試過了,但沒有奏效。如果可能,你可以在下次回覆時插入代碼並發表評論。 – Manipur

回答

1

下面是一個例子,標題和日期間:

<header> 
    <?php if (0 < strlen(get_the_title())) { ?> 
     <h1 class="entry-title"> 
      <a href="<?php the_permalink(); ?>"> 
       <?php the_title(); ?> 
      </a> 
     </h1><!-- /.entry-title --> 
    <?php } // end if ?> 

    <div class="post-meta"> 
    <?php the_author(); ?> 
     <span class="post-date"> 
      <?php if (0 < strlen(get_the_title())) { ?> 
       <?php the_time(get_option('date_format')); ?> 
      <?php } else { ?> 
       <a href="<?php the_permalink(); ?>"> 
        <?php the_time(get_option('date_format'));?> 
       </a> 
      <?php } // end if/else ?> 
     </span><!-- /.post-date --> 
     <?php _e(' | ', 'required'); ?> 
     <span class="comment-link"> 
      <?php 
       comments_popup_link('Comment', '1 comment', '% comments', 
        'comments-link', ''); 
      ?> 
     </span><!-- /.comment-link --> 
     <?php edit_post_link('- edit ', '<span>', '</span>'); ?> 
    </div><!-- /.post-meta --> 
</header> 
+0

謝謝@jerdiggity。代碼中有很多if/else語句。我只關注代碼的一部分,這就是爲什麼它沒有提前工作。經過您的確認後,我會逐一在各種條件下進行測試。它工作:) – Manipur

+0

我真的搜索了很多如何在標題中發佈作者姓名,但從來沒有找到一個簡單而有效的解決方案,但你的:<?php the_author(); ?> –

相關問題