2010-11-27 79 views
1

我在WP网站上使用子页面如下;动态链接到子页面WordPress

产品(父页) - 办公(子页面1) --office廊(子页面1的儿童) -School(子页面2) --School廊(子页面2的儿童) .... etc

如何使用我的主题中的一个模板创建每个子页面上的链接到其子页面?我需要能够给这个链接一个CSS类的名称。换句话说,我需要有代码在我的页面模板看起来是这样的:

<a class="gallery-button" href="RETURN LINK TO CHILD PAGE OF CURRENT PAGE"></a>

或类似的东西......

我尝试使用wp_list_pages了从WordPress Codex的子页面,但这返回一个列表,我真的只需要子页面的永久链接。

这很简单吗?不可能?

在此先感谢。

回答

1

您需要查询帖子以获取相关帖子的第一个子帖;

<?php 
    if ($children = get_children('post_type=page&numberposts=1')) { 
     $first_child = $children[0]; 
     $first_child_permalink = get_permalink($first_child->ID); 
     echo '<a class="gallery-button" href="' . $first_child_permalink . '">Link Text</a>'; 
    } 
?> 
+0

干杯。赞赏。 – David 2010-11-29 05:32:33

1

这里是TheDeadMac的代码,我与工作在WP 3.9结束了修订:感谢您的答复

$children = get_pages("child_of=".$post->ID."&sort_column=menu_order"); 
$first_child = $children[0]; 
$first_child_permalink = get_permalink($first_child->ID); 
echo '<a href="' . $first_child_permalink . '">Link Text</a>';