Hi
I'm trying to display info from the last 2 posts in my blog on a page outside of wordpress.
This is the code:
At the head of the page:
define('WP_USE_THEMES', false);
require('/var/www/aletalking/wp-load.php');
query_posts('showposts=2');
& where i want to display the info:
<?php while (have_posts()): the_post(); ?>
<?php the_title(); ?>
<?php the_date(); ?> by <?php the_author(); ?><?php the_excerpt(); ?>
<?php endwhile; ?>
Everything displays as it should except the_author() - which is missing - is there something simple i'm missing? The author is set up correctly as it displays on the actual blog as it should
Any help would be greatly appreciated
Cheers
lee@digitalacorn
Member
Posted 1 year ago #
You could try and add 'global $post' at the top of the file
if that does nothing by itself try and add this in the first line of the while
setup_postdata($post);
Lee.
You could try and add 'global $post' at the top of the file
if that does nothing by itself try and add this in the first line of the while
setup_postdata($post);
Lee.
Hi Lee
Thanks for the reply. I've tried both options but the_author() is still missing.
It seems strange to me that everything else should display ok apart from this field...
Cheers
lee@digitalacorn
Member
Posted 1 year ago #
Did you try them at the same time?
sorry then I'm not sure, someone else might know.
As a stab in the dark you could try 'echo get_the_author()'
or as a total stab try calling wp_footer() << sometimes seems to work magic :)
Sorry I couldn't be of any more help.
Lee.
Nope, still no luck
Thanks anyway Lee
Can't quite get my head round why everything else displays ok, there must be something specific to the_author() i'm missing...
lee@digitalacorn
Member
Posted 1 year ago #
must be to do with the loop or lack of it.
investigate the function below - you might be able to get it from what that returns instead.
get_userdata()
chrisob120
Member
Posted 1 year ago #
Is there any updates on this? I'm having the same error. The author shows on the page outside of wordpress when I change
"define('WP_USE_THEMES', false);"
to
"define('WP_USE_THEMES', true);"
however.
chrisob120
Member
Posted 1 year ago #
For anyone out there that still has problems with the_author(); on external (or maybe in on WordPress) sites, I've figured out why it didn't work for me.
I was calling another database after the call to WordPress blog-header. I don't understand why the other fields worked even with the call to the other database, but when I took that out it worked fine for the_author();.
This pissed me off for so long so I hope this helps someone else.