How to get pretty permalink in custom loop
-
I have used the following code to generate a custom loop on an ‘archive’ type page:
<?php $how_many=5; //How many posts do you want to show require_once("wp-config.php"); // Change this for your path to wp-config.php file ?> <ul> <? $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code> FROM $wpdb->posts WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>= \"publish\" ORDER BY post_date DESC LIMIT $how_many"); foreach($news as $np){ printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title); }?> </ul>
I can see where the link is generated:
printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
…but I don’t seem to be able to generate the pretty permalink for the link. After trying a few things I’m starting to pull my hair out!
The site I’m working on is based on a windows box, and the prettiest permalink I can generate is:
https://www.site.com/index.php/whats-new/
…but this bit of php shown above generates links like this:
https://www.site.com/index.php/whats-new/index.php?p=95
which I’m amazed actually works, but it does! What I really want to do is generate a proper pretty permalink – could someone please tell me how to do that?
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘How to get pretty permalink in custom loop’ is closed to new replies.