0

我在使用 Wordpress 生成的链接列表时遇到问题,该列表显示特定页面链接及其所有子页面链接。当您将鼠标悬停在链接上时,我试图让链接突出显示,然后当您单击它们并导航到该页面时,该页面的链接保持突出显示。我找到了一种主要使用以下方法实现此目的的方法:

#sidebar a:hover{
    padding: 7px;
    background-color: #f7f9fe;
    color: #728186;
}
#sidebar ul > li .current_page_item{
    padding: 7px;
    background-color: #f7f9fe;
    color: #728186;
}

但这不允许我突出显示父页面/li。如果我使用:

#sidebar li.current_page_item

子项在其页面上保持突出显示,但在父页面上它也突出显示子项,而不仅仅是其本身。

这是我解析的php:

<ul id="sidebar" class="sidelist">
    <li class="pagenav"><h5>WHAT WE DO</h5>
        <ul>
            <li class="page_item page-item-39 current_page_item"><a href="http://www.autismrecoveryfoundation.org/meet-the-board" title="Meet the Board">Meet the Board</a>
            <ul class='children'>
                <li class="page_item page-item-84"><a href="http://www.autismrecoveryfoundation.org/meet-the-board/being-a-board-member-101" title="Being A Board Member 101">Being A Board Member 101</a></li>
            </ul>
            </li>
        </ul>
    </li>   
</ul>

这是我在关于 wp 列表页面 (http://codex.wordpress.org/Function_Reference/wp_list_pages) 的 Wordpress 页面中使用的模板标签:

<?php 
            // use wp_list_pages to display parent and all child pages all generations (a tree with parent)
            $parent = 39;
            $args=array(
             'title_li' => '',
             'child_of' => $parent
            );
            $pages = get_pages($args);  
            if ($pages) {
              $pageids = array();
              foreach ($pages as $page) {
                $pageids[]= $page->ID;
              }

              $args=array(
                'title_li' => '<h5>WHAT WE DO</h5>',
                'include' =>  $parent . ',' . implode(",", $pageids)
              );
              wp_list_pages($args);
            }
        ?>
4

1 回答 1

1

更新

To display your list of pages in a flat list, set depth to -1:

$args=array(
  'depth' => -1,
  'title_li' => '<h5>WHAT WE DO</h5>',
  'include' =>  $parent . ',' . implode(",", $pageids)
);

That way you won't have to mess around with child selectors, and your subpages won't be contained in your main page's li anymore.


Old answer

The problem lies in this selector:

#sidebar ul > li .current_page_item

The #sidebar ul part is looking for ul which descends from #sidebar, but in your code ul is the #sidebar. Also, li .current_page_item would find any .current_page_item inside the li that contains your heading.

Change your selector to this:

#sidebar > li > ul > .current_page_item

You can also use this, since your pages widget has its own class anyway:

.pagenav > ul > .current_page_item
于 2011-01-23T13:45:14.923 回答