?
Solved

Getting urls of all wordpress posts - wp_get_archives?

Posted on 2011-09-21
16
Medium Priority
?
412 Views
Last Modified: 2012-05-12
I need to get a list of all my Wordpress post's urls, ie:

http://www.mysite.com/postnameone
http://www.mysite.com/postnametwo
http://www.mysite.com/postnamethree

I have found I can use this:

<?php wp_get_archives('type=postbypost&limit=2000&format=custom'); ?>

In a template to get a full list of post titles that are linked to each post, but I don't need a link, I just need a list of the plain text (unlinked) permalink urls, one per line.

Can you show me how to do that?

Thanks,  Chris

0
Comment
Question by:St_Aug_Beach_Bum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 4
16 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 36578298
Something like:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <p><?php the_permalink() ?></p>
<?php endwhile; else: ?>
   <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

Open in new window


should do it

0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36578439
You might want to wrap them inside of <ul><li> tags so it's easier to make them into a list. I'm not sure you want them to display, but fi you want the actual title, use this:

<div id="all-posts">
  <?php $debut = 0; while(have_posts()) : the_post(); ?>
    <ul>
    <?php $myposts = get_posts('numberposts=-1&offset=$debut'); foreach($myposts as $post) : ?>
      <li>
        <?php the_title(); ?>
      </li>
    <?php endforeach; ?>
    </ul>
  <?php endwhile; ?>
</div>

Open in new window


If you want the URL of the posts, use Jason's code. It will need a little modification though. I believe it would only output the page/post that you open to display the post titles.
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 36578444
hmm, not getting anything, do I need to be 'in the loop' for that, will have to figure that out...
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 36578459
>> I believe it would only output the page/post that you open to display the post titles.

Gah.  Oops...
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 36578465
ah, ok, it did work for that, I did get a line that had the url of that page on it, but that one was it :)
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 36578471
So you need to combine Jeremy's loop with my interior to get the solution :)

No more late night EE for me...brain hurts

Open in new window

0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 36578473
jeremyjared74 - yep, just need the urls :)
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 1000 total points
ID: 36578481
Placing:

<?php the_permalink() ?>

inside the loop (use li or p tags for structure) should return the list of URLs
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 36578538
I'm confused,

Do you mean in jeremyjared74's loop? Replace 'the_title()' with 'the_permanlink()'?

I don't get any results, just:

-----(page source)----

<div id="all-posts">

      <ul>
------------------------

Here is the code I have on a template page right now:

<?php
/*
Template Name: url-list
*/
?>
<div id="all-posts">
  <?php $debut = 0; while(have_posts()) : the_post(); ?>
    <ul>
    <?php $myposts = get_posts('numberposts=-1&offset=$debut'); foreach($myposts as $post) : ?>
      <li>
        <?php the_permalink(); ?>
      </li>
    <?php endforeach; ?>
    </ul>
  <?php endwhile; ?>
</div>
0
 
LVL 23

Assisted Solution

by:jeremyjared74
jeremyjared74 earned 1000 total points
ID: 36578573
I think you have it. By combining my custom function with Jason's you should get what you're needing. It's a little late or I'd test it. I haven;t really looked at your latest code, but here's a quick change that should work:

<div id="all-posts">
  <?php $debut = 0; while(have_posts()) : the_post(); ?>
    <ul>
    <?php $myposts = get_posts('numberposts=-1&offset=$debut'); foreach($myposts as $post) : ?>
      <li>
        <?php the_permalink() ?>
      </li>
    <?php endforeach; ?>
    </ul>
  <?php endwhile; ?>
</div>

Open in new window


I'm not after the points, Jason would have eventually worked it out, so I don't require any points. I was only making an observation.

Good Night,
JJ
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36578600
I just tested my code, and it's working. I don't know why it's not for you. You don't have the code place in a template with another loop do you?

I just placed the code as is inside of a sidebar I had available. If you don't figure it out, one of us will finish up tomorrow.

Regards,
Jeremy Jared
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 36578637
No, not working. But I'm with you, gotta get some sleep and tackle this again tomorrow.

Thank you for trying to help.
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 36580909
ah, took a look with fresh eyes this morning ;)

I had to adjust the numberposts=-1 to a much higher number. I don't know if it works for you with -1 or if you thought I would know that :)  (I did, come morning!).

jeremyjared74 - do you really not want points, or shall I split them between the two of you?

Thank you very much!
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36581203
It's up to you, I'd give most to Jason though. I didn't want to impose on his answers, I just wanted to add some input. You might select on of my answers as assisted solution so it can be seen by others that might search and find this question.

I had to adjust the numberposts=-1 to a much higher number. I don't know if it works for you with -1 or if you thought I would know that
Yeah I assumed you were copy and pasting the code. Sometimes when I'm in a rush I forget to explain important parts of the code. I'm glad you caught it and were able to solve you problem.

Regards,
JJ
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 36581453
The right thing to do is give jj the solution and me an assist with more poinks to Jeremy.  His loop is correct, I just used the right function to return a URL.  

Good teamwork, though. :)
0
 

Author Closing Comment

by:St_Aug_Beach_Bum
ID: 36581709
Well, thank you both!!!  :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question