SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Location
    Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress Dillema

    I am trying to find a way to generate a list from a wordpress blog of all posts with their correlating urls. I know this must be simple but I just cant figure it out.

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work:

    Code PHP:
    <ul>
        <?php $myposts = get_posts('numberposts=10&offset=0'); ?>
        <?php foreach($myposts as $post): ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title();?></a></li>
        <?php endforeach; ?>
    </ul>

    The above code will make a list of the 10 most recent posts.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Member
    Join Date
    Sep 2008
    Location
    Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I dont think I am explaining what I am looking to do clearly. What I need i s to run some code that will list all the posts in my blogs letting me know what their respective urls are. This is something that I do not wish to see within the blog but instead need for administrative purposes. I hope I have been able to express this properly.

  4. #4
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The following script should (I haven't tested it) display the last million post titles with their respective URL's beside.

    Code PHP:
    <?php $myposts = get_posts('numberposts=1000000&offset=0'); ?>
    <?php foreach($myposts as $post): ?>
    <?php the_title();?> = <?php the_permalink(); ?>
    <?php endforeach; ?>

  5. #5
    SitePoint Member
    Join Date
    Sep 2008
    Location
    Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i tried running it from a php file and that did not work. Am I doing something wrong?

  6. #6
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you will need to hook into the WordPress database first. If you place the following script before the 'posts script' it should work. Make sure the reference to wp-blog-header.php is correct though.

    Code PHP:
    <?php
    require('wp-blog-header.php');
    header('Content-type: text/css');
    ?>


    Or you could put the original script I posted into a theme or plugin.

  7. #7
    SitePoint Addict
    Join Date
    Mar 2006
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ryanhellyer View Post
    The following script should (I haven't tested it) display the last million post titles with their respective URL's beside.

    Code PHP:
    <?php $myposts = get_posts('numberposts=1000000&offset=0'); ?>
    <?php foreach($myposts as $post): ?>
    <?php the_title();?> = <?php the_permalink(); ?>
    <?php endforeach; ?>
    this also works (just incase there are more than a million posts )
    PHP Code:
    <?php $myposts get_posts('numberposts=-1'); ?>

  8. #8
    SitePoint Member
    Join Date
    Sep 2008
    Location
    Florida
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works for me now. I could not get it to work as a plugin but thats fine. But I do get this.
    Warning: Cannot modify header information - headers already sent by (output started at /home/nat/public_html/tvshowhub.com/postsnurls.php:3) in /home/nat/public_html/tvshowhub.com/postsnurls.php on line 5

    Now I am trying to get the output to have a comma after the post url or even better to have one post per line. Thanks for all your help

  9. #9
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like you have rendered some sort of text (possibly white space) before you added the second lot of code I posted. The header code needs to come before anything else, as it decides what sort of file to output.

    Also, it seems I made a mistake and posted the code to make a CSS file. It should still work though. Perhaps change 'CSS' to 'HTML' if you want to behave like a regular page.

    Code PHP:
    <?php
       require('wp-blog-header.php');
       header('Content-type: text/html');
    ?>


    Now I am trying to get the output to have a comma after the post url or even better to have one post per line. Thanks for all your help
    Just add a <br /> after the permalink script like so:
    Code php:
    <?php $myposts = get_posts('numberposts=-1'); ?>  
    <?php foreach($myposts as $post): ?>
    <?php the_title();?> = <?php the_permalink(); ?><br />
    <?php endforeach; ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •