2013-10-17 141 views
2

我有這樣的代碼:WordPress的WP_LIST_PAGES插入跨度

if($post->post_parent) 
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); 
else 
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); 
if ($children) { ?> 
<ul id="siderbar_menuchild"> 
<?php echo $children; ?> 
</ul> 
<?php } ?> 

結果是:

<ul> 
<li><a href="page_link">page_name</a></li> 
<li><a href="page_link">page_name</a></li> 
etc... 
</ul> 

現在,這是我要顯示什麼:

$text1="text1" 
$text2="text2" 
$text3="text3" 
etc... 

<ul> 
<li><a href="page_link">page_name<span>text1</span></a></li> 
<li><a href="page_link">page_name<span>text2</span></a></li> 
etc... 
</ul> 

任何幫助表示讚賞。 謝謝。

LE:好吧,我把下面一行:

$children = str_replace('</a>', '<span></span></a>', $children); 

而現在的標籤位置是不錯的。

但我仍然必須找到一種方法,如何將不同的文本放在每個跨度上。

LE2:我用jQuery來插入文本,沒有發現任何PHP方法,我用下面的一行:

<script type="text/javascript"> 
$(".page-item-53 span").text("Your text here Your text here Your text here"); 
</script> 

所以,我解決我的問題,但如果你在做任何其他更好的辦法這個,你可以在這裏發佈你的解決方案。

回答

0

使用link_after屬性爲wp_list_pages()來實現此目的。

if($post->post_parent) 
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&link_after=<span>text </span>"); 
else 
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&link_after=<span>text </span>"); 
if ($children) { 
?> 
<ul id="siderbar_menuchild"> 
<?php echo $children; ?> 
</ul> 
<?php } ?> 

而對於數量,我使用的CSS counter-increment

<style> 
body { 
    counter-reset: section;   /* Set the section counter to 0 */ 
} 
#siderbar_menuchild li.page_item 
{ 
    counter-increment: section; 
} 
#siderbar_menuchild li.page_item span:after { 
    content: counter(section); 
} 
</style> 

參考:

http://codex.wordpress.org/Function_Reference/wp_list_pages

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Counters

+0

我不想寫文本1,文本2的跨度內,我想將自定義文本放到每個範圍。 – Speedwheelftw