Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created the file latest.php in the public_html so that when I go to www.domain.com/latest.php it will show me the latest articles. Sadly, nothing of the posts came up. Later, I will sort them with other ways (mostly based on custom fields).

This is my latest.php file (I removed any styling for better understanding)

<?php include("wp-load.php"); ?>
<?php get_header(); ?>
<?php wp_head(); ?>

**AND HERE IS WHAT I COPY-PASTED FROM MY INDEX.PHP THAT IS WORKING**

<?php while (have_posts()) : the_post(); ?>

    <a title="" href="<?php echo get_permalink(); ?>" ><?php the_title(); ?></a>

<?php endwhile; // End the loop ?>

<?php posts_nav_link(' &#183; ', 'previous page', 'next page'); ?>

My question is how can I make it possible to show the latest articles with pagination?

Should I use an entire different method for my task? If yes, which one?

UPDATE

header and other functions are working CORRECTLY. It just not shows the posts.

share|improve this question

3 Answers

up vote 0 down vote accepted

This worked for me:

include ('wp-blog-header.php');

and before:

while (have_posts()) : the_post();

you have to create wp_query, so do this for example:

query_posts('cat=1'); // or any other query args you wish
share|improve this answer
Thanks, have you found any way to add pagination? – Punkis Sep 16 '11 at 20:37
another syntax for query_posts (using array of args), with paging: query_posts( array( 'cat' => 1, 'paged' => get_query_var('page') ) ); – Maciej Kuś Sep 16 '11 at 20:48

Your file is completely outside of the Wordpress functionality. In order for this to work, you have to have this inside of a theme under wp-content/themes/your-theme. You will need a stylesheet named style.css (with proper theme definition header) and name this file index.php.

share|improve this answer
I do not agree with your answer because having wp-load and wp_head included correctly, I am in the WP functionality. I have created a lot of pages with this exact method, and they are working correctly. This is the first time I needed to show posts. It does display posts but with other post queries, not this one. – Punkis Sep 16 '11 at 19:54
You're right. I missed the wp-load.php line. :) include ('wp-blog-header.php'); is a better solution. – Brian Fegter Sep 16 '11 at 20:36
What is the difference of those two? – Punkis Sep 16 '11 at 23:53

try this (relative path)

<?php
require( '../my_wordpress_install_root/wp-load.php' );
get_header();
echo 'new content outside WordPress';
get_footer();
?>

or fetch feed for your lastest posts

useful link: http://wpengineer.com/1038/embed-wordpress-functions-outside-wordpress/

share|improve this answer
I call wp-load correctly. It just not showing the posts. Please read again my question – Punkis Sep 16 '11 at 19:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.