Support » Fixing WordPress » Publishing A list of All URLs

Viewing 8 replies - 1 through 8 (of 8 total)
  • I’m guessing this *might* be the right code:

    <?php
    if (have_posts()) :
       while (have_posts()) :
          the_permalink();
       endwhile;
    endif;
    ?>

    But the bigger question, is where do i put this so that I can see a result? If I create a new template file called, say, delete-me.php where in the world does it show up? there doesn’t seem to be any way to find a URL to a template file. All I want is a simple page that spits out that list. Why is it so difficult to create a simple page in WP? I’m obviously missing something here…

    Use a page template?

    Create a file with a .php extension, anything you like, as long as it’s not the same as an existing file in your theme…

    For the sake of an example i’ll call it listposts.php…

    Plonk this in there..

    <?php
    /*
    Template Name: List post links
    */
    query_posts('post_type=post');
    if (have_posts()) :
       while (have_posts()) :
          the_permalink(); ?><br /><?php
       endwhile;
    endif;
    ?>

    Save the file and place it in your theme’s folder.
    Example: wp-content/themes/default/

    Go to Admin > Pages > Create new / Add new (whatever it’s called, lol)

    Select “List posts links” from the page template box to the right..

    Give the page a title, and leave the content emtpy…

    Save, now go view your page..

    Thank you! This is exactly what I was looking for.

    The only problem is that the page will not load, it just churns and churns and eventually times out… (there are about 3500 urls). I suspect this is due to some kind of php memory setting. Do you know how to rig it so this page will load?

    Is there some kind of static way to do this? I can’t believe this is so difficult. I created the same list in Movable Type in *literally* 30 seconds. I’ve spent almost the entire day trying to do it in WordPress…WTF?

    Considering you’re only grabbing the permalink for each entry it might be easier to do it a little differently….

    Try this instead, same procedure, just update the file with this code instead…

    <?php
    /*
    Template Name: List post links
    */
    $postID = $wpdb->get_col("
    	SELECT ID FROM $wpdb->posts
    	WHERE (post_type = 'post')
    	AND (post_status = 'publish')
    	AND (post_password = '')
    ");
    
    foreach($postID as $post_link) {
    	?>
    	<a href="<?php echo get_permalink($post_link); ?>"><?php echo get_the_title($post_link);?></a><br />
    	<?php
    }
    ?>

    Be sure to remember when creating the (“Page” via admin) to select the template from the right.

    You can place the links into a list if you like… slight change to the above…

    <?php
    /*
    Template Name: List post links
    */
    $postID = $wpdb->get_col("
    	SELECT ID FROM $wpdb->posts
    	WHERE (post_type = 'post')
    	AND (post_status = 'publish')
    	AND (post_password = '')
    ");
    echo '<ul id="post_links">';
    foreach($postID as $post_link) {
    	?>
    	<li><a href="<?php echo get_permalink($post_link); ?>"><?php echo get_the_title($post_link);?></a></li>
    	<?php
    }
    echo '</ul>';
    ?>

    You can them style them in your CSS with the following…

    Example:

    #postlinks {
    	width:auto;
    	list-style:inside none;
    }
    #post_links li {
    	margin:0;
    	padding:4px 10px;
    }
    #post_links li a:link,
    #post_links li a:visited {
    	text-decoration:none;
    	color:black;
    	font-weight:bold;
    	font-size:1.0em;
    }
    #post_links li a:hover,
    #post_links li a:active {
    	color:red;
    }

    Dude, you are a hero!!! Thank you, it finally worked, no weird memory problem. A million thanks!

    No problem, you’re welcome….

    🙂

    Thanks, t31os_ This is exactly what I was looking for, too, except I needed a text list of just the URLs, not hyperlinked (gotta manually create a 301 redirect list in my htaccess file to avoid too many double redirects to the new permalink structure on the new site). So I modified your code a bit and it worked perfectly:

    <?php
    /*
    Template Name: List post links
    */
    $postID = $wpdb->get_col("
    	SELECT ID FROM $wpdb->posts
    	WHERE (post_type = 'post')
    	AND (post_status = 'publish')
    	AND (post_password = '')
    ");
    
    foreach($postID as $post_link) {
    	?>
    	<?php echo get_permalink($post_link); ?><br />
    	<?php
    }
    ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Publishing A list of All URLs’ is closed to new replies.