Page links without a list
-
Hello there,
simply: is there a way to make WP to display the list of pages without creating an actual list (no
<li>elements)?I’m working on a bilingual website (using WP_Multilingual) and there’s a horizontal menu with links to some pages. Right now, I’m using this:
<?php wp_list_pages('include=1&title_li='); ?>in a table (table… I know, I suck…) for each link because I need both titles and links to change, when a user changes the language – it looks like this: http://i40.tinypic.com/a3ci8z.jpg. My problem is that the code above creates
<li class="page_item page-item-1 current_page_item"><a href="http://localhost/en/example" title="Example">Example</a></li>and I need to somehow remove the
<li>elements. I tried everything I could think about but this is the only way that works (as far as I can say) with my bilingual web.Do you have any ideas?
Thanks very much 🙂
-
Here, play with this code that works in the sidebar.php of the WordPress Default Theme.
<?php $args = array( 'orderby' => 'post_title', 'order' => 'ASC', 'post_type' => 'page', 'showposts' => 1000, 'caller_get_posts' => 1 ); $pages = get_posts($args); foreach($pages as $page) { $out .= '<li>'; $out .= '<a href="'.get_permalink($page->ID).'" title="'.wptexturize($page->post_title).'">'.wptexturize($page->post_title).'</a></li>'; } $out = '<ul class="page_post">' . $out . '</ul>'; echo $out; ?>It’s perfect, thank you very much
just in case anyone would find it useful:
$args = array( 'post_type' => 'page', 'include' => 1, ); $pages = get_posts($args); foreach($pages as $page) { $out .= '<a href="'.get_permalink($page->ID).'" >'.wptexturize($page->post_title).'</a>'; } echo $out; unset($out);Thanks, it helped me some!
Just what I was looking for
Thanks It Help Me
The code above works great for formatting my page links but it’s listing every page on my site. Previously, I had this code:
<?php 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> <?php echo $children; ?> </ul> <?php } ?>It would only show child pages of the parent page you were on, even on other child pages of that parent.
Is there a way to merge the two and get the formatting of your code and the child pages from the code I posted? Everything I try just makes the page list disappear completely.
Thanks in advance for your help on this!
Hi everyone. I’ve got the same problem as clockeby – I’d like to merge the two bits of code so the following code only shows child pages. Is this possible?
<?php $args = array( 'orderby' => 'post_title', 'order' => 'ASC', 'post_type' => 'page', 'showposts' => 1000, 'caller_get_posts' => 1 ); $pages = get_posts($args); foreach($pages as $page) { $out .= '<li>'; $out .= '<a href="'.get_permalink($page->ID).'" title="'.wptexturize($page->post_title).'">'.wptexturize($page->post_title).'</a></li>'; } $out = '<ul class="page_post">' . $out . '</ul>'; echo $out; ?>Does this only work in sidebar.php?
I’m trying to generate an XML sitemap (I don’t want to use bloated plugins) and I can’t seem to find a way to output the pages so I can do my own formatting on them
Nope this should work in any php file.
Here’s another little snippet i use alot on my pages.
<?php $pages = get_pages('child_of='.$post->ID.''); foreach ($pages as $page) { $item = '<li><a href="'.get_permalink($page->ID).'" title="Click here to go to the product details">Show details</a></li>'; echo $item; } ?>Thanks, any ideas on how can I get a list of all pages including the root with that?
nevermind – had a look at the function and you can just do get_pages()
The topic ‘Page links without a list’ is closed to new replies.