2014-01-16 73 views
0

我已經在我的WordPress網站的PHP文件中的一個下面的代碼:簡單的PHP/WordPress的語法問題

<?php if (count(get_the_category())) : ?> 
     <span class="cat-links"> 
      <?php printf(__('<span class="%1$s">&bull; Posted in</span> %2$s', 'twentyten'), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list(', ')); ?> 
     </span> 
    <?php endif; ?> 

它的作用是輸出所有類別的逗號分隔,鏈表,一個特定的帖子屬於。例如,輸出如下所示:

張貼在組別,類別2,類別3

我想要做的就是修改此行的開頭也包括筆者。據WordPress的文檔中,作者姓名可以使用檢索:

get_the_author() 

但我不熟悉PHP語法不夠好,弄清楚如何將它添加到我的本錢。以下是我想它,而不是閱讀:

張貼在組別,類別2 author_username,類別3

任何幫助將不勝感激!

回答

4

試試這個,

<?php printf(__('<span class="%1$s">&bull; Posted by %2$s in</span> %3$s', 'twentyten'), 'entry-utility-prep entry-utility-prep-cat-links', get_the_author(), get_the_category_list(', ')); ?> 
+0

這完美的作品 - 非常感謝!最後一個問題......它顯示了作者的名字,但並沒有像鏈接類別那樣鏈接它......我如何去做它呢? – Iconoclast

+0

您可以使用'get_the_author_link()'而不是'get_the_author()' –

+0

看起來應該可以工作,但我仍然無法將它鏈接到作者名稱。它與if語句中的內容有什麼關係?這裏是我現在得到的(我用你的建議也將日期添加到帖子行)'<?php printf(__(' •發佈於%2 $ s由(),get_the_date(),get_the_author_link(),get_the_category_list(','));%3 $ s in%4 $ s','twentyten'),'entry-utility-prep entry-utility-prep-cat-links' ?> – Iconoclast

0
<?php printf(__('<span class="%1$s">&bull;Posted By ' . get_the_author() . ' Posted in</span> %2$s', 'twentyten'), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list(', ')); ?> 
+0

會起作用,但會破壞使用'printf'的目標(這是爲了國際化而將語言和變量分開) –