在WordPress安装外部运行循环
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在WordPress安装外部运行循环相关的知识,希望对你有一定的参考价值。
Put the following outside WP
<?php // Include WordPress require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php'); query_posts('showposts=1'); ?> <?php while (have_posts()): the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_excerpt(); ?> <p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p> <?php endwhile; ?> To truncate excerpt, put this inside functions.php, inside WP theme: <?php function limit_words($string, $word_limit) { // creates an array of words from $string (this will be our excerpt) // explode divides the excerpt up by using a space character // this next bit chops the $words array and sticks it back together // starting at the first word '0' and ending at the $word_limit // the $word_limit which is passed in the function will be the number // of words we want to use // implode glues the chopped up array back together using a space character } ?> Then, replace <?php the_excerpt(); ?> with: <?php echo limit_words(get_the_excerpt(), '10'); ?> Alternatively: http://www.webdesigncreare.co.uk/blog/videos/recent-posts-outside-wordpress.html <ul> <?php require($_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php'); query_posts('showposts=3'); if (have_posts()) : while (have_posts()) : the_post(); ?> <li> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <span>Posted on <?php the_time('l jS F, Y') ?></span><br /> <?php the_excerpt(); ?> </li> <?php endwhile; else: echo "no posts"; endif; ?> <?php wp_reset_query(); ?> </ul>
以上是关于在WordPress安装外部运行循环的主要内容,如果未能解决你的问题,请参考以下文章