WordPress.org

Ready to get started?Download WordPress

Forums

How to list all links[pages/posts/tags/Category]? (2 posts)

  1. bird0
    Member
    Posted 7 months ago #

    I want to list every link on my wordpress. link to Pages. link to Posts. link to Tags. link to Categories. To everything... to every existed page on my wordpress
    That what i wont:

    http://localhost/wordpress-3.8/wordpress/page1/
    http://localhost/wordpress-3.8/wordpress/page2/
    http://localhost/wordpress-3.8/wordpress/post1/
    http://localhost/wordpress-3.8/wordpress/post2/
    http://localhost/wordpress-3.8/wordpress/tag1/
    http://localhost/wordpress-3.8/wordpress/tag2/
    http://localhost/wordpress-3.8/wordpress/category1/
    http://localhost/wordpress-3.8/wordpress/category2/

    My idia:

    <?php
      $pages = get_pages();
      foreach ( $pages as $page ) {
      	$html = get_page_link( $page->ID );
    	$html .= "<br/>";
    	echo $html;
      }
     ?>

    OR some thing similar

    <?php
      $ID = get_ALL_IDS();
      foreach ( $IDS as $ID ) {
      	$html = get_permalink($ID);
    	$html .= "<br/>";
    	echo $html;
      }
     ?>

    Little spider

  2. bcworkz
    Member
    Posted 7 months ago #

    You're on the right track. You need a different query for posts and pages than for terms for tags and categories, but you can get by with 2 queries by listing the different post_types as an array argument for data in posts table and list different taxonomies as an array argument for data in the terms table.

    For posts and pages use a custom post_type query and run the result through the standard loop. Using the_permalink() within the loop will output the needed links.

    For terms, use get_terms() and run a foreach loop for the returned term objects, using echo get_term_link($term);.

    Just a crazy idea: This is very much what is done to generate a sitemap for search engines. You might consider hacking a sitemap plugin to generate what you want instead of its usual XML file. It's likely easier to write your own code rather than figure out how to hack someone else's code in this case though.

Reply

You must log in to post.

About this Topic