WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Page links without a list (13 posts)

  1. otherSphere
    Member
    Posted 5 years ago #

    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 :)

  2. MichaelH
    Member
    Posted 5 years ago #

    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;
    ?>
  3. otherSphere
    Member
    Posted 5 years ago #

    It's perfect, thank you very much

  4. otherSphere
    Member
    Posted 5 years ago #

    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);
  5. mores
    Member
    Posted 5 years ago #

    Thanks, it helped me some!

  6. kremerdesign
    Member
    Posted 4 years ago #

    Just what I was looking for

  7. vinword
    Member
    Posted 4 years ago #

    Thanks It Help Me

  8. clockeby
    Member
    Posted 4 years ago #

    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!

  9. philuk
    Member
    Posted 4 years ago #

    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;
    ?>
  10. scottybowl
    Member
    Posted 4 years ago #

    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

  11. weareworkingonit
    Member
    Posted 4 years ago #

    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;
    				  }
    				 ?>
  12. scottybowl
    Member
    Posted 4 years ago #

    Thanks, any ideas on how can I get a list of all pages including the root with that?

  13. scottybowl
    Member
    Posted 4 years ago #

    nevermind - had a look at the function and you can just do get_pages()

Topic Closed

This topic has been closed to new replies.

About this Topic