简体   繁体   中英

WP in subdirectory: how to show items on non-wp in root

Wordpress is installed in the subdirectory «/blog», and is accessible there. I'm trying to find out how to place the last blog-item as the main article in the non-wp root «index.php».

All I can find is about WP in subdirectory, and acting if it is in the root, but that's not what I want. The blog must stay in the subdirectory, because the rest of the site is non-WP. I know it is possible; I read about it years ago, but I can't find that source anymore.

In root-index add: require('blog/wp-blog-header.php');

And then where you want to post your post:

<article>
<?php
    $posts = get_posts('numberposts=1&order=ASC&orderby=post_title');

    foreach ($posts as $post) : setup_postdata( $post ); ?>
    <?php the_date(); echo "<br />"; ?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <? 
    php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>    
    <?php the_excerpt(); ?> 

    <?php endforeach;?>

</article>

That's all... Source: https://codex.wordpress.org/Integrating_WordPress_with_Your_Website

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM