2010-09-04 113 views
1

我有以下代碼來顯示發佈作者的gravatar,但我如何喜歡它到該用戶的作者配置文件?WordPress作者鏈接

<a title="View posts by ###" href="###"><?php echo get_avatar($email, $size = '64'); ?></a> 

編輯這是我的index.php文件

<?PHP 

    get_header(); 

?> 


<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.masonry.js"></script> 
<script type="text/javascript"> 
    jQuery(document).ready(function(){ 
    $('#post-list').masonry({ singleMode: true, itemSelector: 'article', animate: false }); 
    }); 
</script> 

<?php 

    function MyLoopCode() 
    { 
?> 

<article id="post-<?php the_ID(); ?>"> 

    <div class="post-image"></div> 

    <div class="post-text"> 

    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 

    <p class="p-cat">In: <?php the_category('|') ?></p> 

    <p class="p-author"> 
    <span class="name"><?php the_author_posts_link(); ?></span> 
    <span class="avatar"><a title="View posts by <?php the_author(); ?>" href="<?php echo get_author_posts_url($authordata->ID); ?>"><?php echo get_avatar($email, $size = '64'); ?></a> 
    </span> 
    </p> 


    <small class="p-time"> 
    <strong class="day"><?php the_time('j') ?></strong> 
    <strong class="month"><?php the_time('M') ?></strong> 
    <strong class="year"><?php the_time('Y') ?></strong> 
    </small> 

    <section class="content"> 
    <?php the_content('<p>Read the rest of this page &raquo;</p>'); ?> 
    </section> 

    <div class="p-det"> 
    <p class="p-det-com"><?php comments_popup_link('No Comments', '(1) Comment', '(%) Comments'); ?></p> 
    <?php if (function_exists('the_tags')) { ?> <?php the_tags('<p class="p-det-tag">Tags: ', ', ', '</p>'); ?> <?php } ?> 
    </div> 

    </div> 

</article> 

<?php } ?> 



    <div id="maincontent" class="clearfix"> 

    <div class="leftcontent"> 

    <section id="post-list" class="post-list"> 

    <?php //query_posts('orderby=rand'); ?> 

    <?php query_posts('posts_per_page=1&author=2'); if (have_posts()) : while (have_posts()) : the_post(); ?> 

     <?php echo MyLoopCode(); ?> 

    <?php endwhile; endif; ?> 

    <?php rewind_posts(); ?> 

    <?php query_posts('posts_per_page=1&author=3'); if (have_posts()) : while (have_posts()) : the_post(); ?> 

     <?php echo MyLoopCode(); ?> 

    <?php endwhile; endif; ?> 

    <?php rewind_posts(); ?> 

    <?php query_posts('posts_per_page=1&author=4'); if (have_posts()) : while (have_posts()) : the_post(); ?> 

     <?php echo MyLoopCode(); ?> 

    <?php endwhile; endif; ?> 

    <article> 

     <p>ADVERTISEMENT</p> 

    </article> 

    <?php rewind_posts(); ?> 

    <?php query_posts('posts_per_page=1&author=5'); if (have_posts()) : while (have_posts()) : the_post(); ?> 

     <?php echo MyLoopCode(); ?> 

    <?php endwhile; endif; ?> 

    <?php rewind_posts(); ?> 

    <?php query_posts('posts_per_page=1&author=6'); if (have_posts()) : while (have_posts()) : the_post(); ?> 

     <?php echo MyLoopCode(); ?> 

    <?php endwhile; endif; ?> 

    </section> 

    </div> 
    <!-- END div.leftcontent --> 

    <?php get_sidebar(); ?> 

    </div> 
    <!-- END div#maincontent --> 



<?PHP 

    get_footer(); 

?> 

回答

4

使用get_author_posts_url()模板標籤輸出由給定的作者(使用author.php頁面模板)的URL帖子列表。您需要傳遞作者的用戶ID作爲第一個參數; 我假設用戶對象是$authordata

<a title="View posts by <?php the_author(); ?> href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php echo get_avatar($email, $size = '64'); ?></a> 
+0

如何將用戶作者ID傳遞給鏈接? – Cameron 2010-09-04 08:53:27

+0

@Cameron:你現在通過從你的數據庫中檢索一個發佈作者來獲取'$ email'嗎? – BoltClock 2010-09-04 08:58:53

+0

不知道,我只是在循環內的代碼行。 – Cameron 2010-09-04 09:01:30