我在WordPress的WordPress的PHP函數
function includePosts ($content = '') {
preg_match_all('/(?<=\\[\\[)\\d+?(?=\\]\\])/', $content, $matches, PREG_PATTERN_ORDER);
$numMatches = count($matches[0]);
for ($i = 0; $i < $numMatches; $i++) {
$postId = $matches[0][$i];
$post= get_post($postId);
$linkToPost = '<a href="'.get_permalink($postId).'">';
$postTitle = $post->post_title;
$postTitleText = "<li> $linkToPost$postTitle</a></li>";
$content = str_replace("[[$postId]]", $postTitleText, $content);
}
return $content;
}
// add_action('admin_menu', 'addAdminPage');
add_filter('the_content', 'includePosts', 1);
這個PHP函數這樣做是什麼把從WordPress頁面短碼,至極將是帖子的ID,並顯示<li>..<li>
一切好之間的文章的標題..不完全。 我希望所有的<li> ... </li>
在一個<ul>...</ul>
之內。這個功能有可能嗎?
jeremysawesome,有一件事我忘了提return $content
回報不僅<li>
又哪裏短碼的,但感謝你的時間在網頁的內容。
三星網頁設計,你的解決方案的行爲奇怪,我得到的是這樣的:
<ul>
<li>...</li>
<li>...</li>
<ul>
<li>...</li>
<li>...</li>
</ul>
</ul>
我真的不明白這一點
這不起作用,這將包裹整個內容和列表中的元素在一個UL – 2011-05-17 21:15:44