开发者

formatting help with wp_list_pages()

I posted this question on the wordpress forum but got no hits. Perhaps one of you might be able to point me in the right direction.

I am putting together a wp theme for a site I am working on. I want to get the layout to match the rest of the site as closely as possible and am running into trouble using the wp_list_pages/categories/bookmarks/etc() methods. I read through the documentation, but really don't see how to translate that into something that will work for me.

Calling the function with no args I get:

<li class="pagenav">Pages
  <ul>
    <li class="page_item page-item-2"><a href="_site_url_/?page_id=2" title="About">About</a></li>
    <li class="page_item page-item-5"><a href="_site_url_/?page_id=5" title="Parent 1">Parent 1</a>
      <ul>
        <li class="page_item page-item-10"><a href="_site_url_/?page_id=10" title="Child 1">Child 1</a>
          <ul>
            <li class="page_item page-item-26"><a href="_site_url_/?page_id=26" title="Grandchild 1">Grandchild 1</a></li>
          </ul>
        </li>
        <li class="page_item page-item-16"><a href="_site_url_/?page_id=16" title="Child 2">Child 2</a></li>
      </ul>
    </li>
    <li class="page_item page-item-7"><a href="_site_url_/?page_id=7" title="Parent 2">Parent 2</a>
      <ul>
        <li class="page_item page-item-22"><a href="_site_url_/?page_id=22" title="Child 1">Child 3</a></li>
        <li class="page_item page-item-24"><a href="_site_url_/?page_id=24" title="Child 2">Child 4</a></li>
      </ul>
    </li>
    <li class="page_item page-item-14"><a href="_site_url_/?page_id=14" title="Parent 3">Parent 3</a>
      <ul>
        <li class="page_item page-item-18"><a href="_site_url_/?page_id=18" title="Child 1">Child 5</a></li>
        <li class="page_item page-item-20"><a href="_site_url_/?page_id=20" title="Child 2">Child 6</a></li>
      </ul>
    </li>
  </ul>
</li>

Whereas I would like something more like:

<div class="nav-link">Pages
  <div id="Pages_children">
    <div class="nav-link"><a href="_site_url_/?page_id=2" title="About">About</a></div>
    <div class="nav-link"><a href="_site_url_/?page_id=5" title="Parent 1">Parent 1</a>
      <div id="Parent 1_children">
        <div class="nav-link"><a href="_site_url_/?page_id=10" title="Child 1">Child 1</a>
          <div id="Child 1_children">
            <div class="nav-link"><a href="_site_u开发者_如何学Crl_/?page_id=26" title="Grandchild 1">Grandchild 1</a></div>
          </div>
        </div>
        <div class="nav-link"><a href="_site_url_/?page_id=16" title="Child 2">Child 2</a></div>
      </div>
    </div>
    <div class="nav-link"><a href="_site_url_/?page_id=7" title="Parent 2">Parent 2</a>
      <div id="Parent 2_children">
        <div class="nav-link"><a href="_site_url_/?page_id=22" title="Child 1">Child 3</a></div>
        <div class="nav-link"><a href="_site_url_/?page_id=24" title="Child 2">Child 4</a></div>
      </div>
    </div>
    <div class="nav-link"><a href="_site_url_/?page_id=14" title="Parent 3">Parent 3</a>
      <div id="Parent 3_children">
        <div class="nav-link"><a href="_site_url_/?page_id=18" title="Child 1">Child 5</a></div>
        <div class="nav-link"><a href="_site_url_/?page_id=20" title="Child 2">Child 6</a></div>
      </div>
    </div>
  </div>
</div>

Is there a way for me to accomplish that with the args system? If not, is it possible for me to request an array from wp_list_TYPE() with the links and titles?

Is there a better way entirely to go about doing something like this?


Try looking at get_posts, which returns an array instead. Then you can loop through the array and print whatever you want from it.

For example:

            <?php $posts = get_posts("numberposts=5&order=DESC&orderby=date"); ?>

            <h5>Latest posts</h5>

            <?php foreach($posts as $post): ?>

              <?php setup_postdata($post); ?>

              <div class="content">

                <a class="title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

                <span style="float:right" class="date"><?php the_time(__('F jS, Y', 'inove')); ?></span>

              </div>

            <?php endforeach; ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜