0

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.

0

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
2
  • Thanks, have you found any way to add pagination? – EnexoOnoma 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
0

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.

3
  • 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. – EnexoOnoma 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? – EnexoOnoma Sep 16 '11 at 23:53
0

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/

1
  • I call wp-load correctly. It just not showing the posts. Please read again my question – EnexoOnoma Sep 16 '11 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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