关于非WP目录下的.php文件显示文章摘要或者别的WP信息的方法

最近有个博友问我:

如果我想在BLOG之外的页面调用呢?

比如wp安装在 /blog/里。
现在想用 /default.php来调用blog的摘要….

有什么好办法么?

想了一下,发现实现的方法不会很难,就是吧WP load进来就OK了,本身WP就有一个初始化的wp()方法;具体是这么实现的。
遇见的问题:WP安装在./blog目录下,现在需要./default.php显示所有日志摘要
解决方法:在./目录下建立default.php文件,内容分如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!--页首自己按照自己要求写-->
 
<?php
        $loca="/blog";//这里定义你的WP目录
        require_once( dirname(__FILE__) . $loca.'/wp-load.php' );//注意这里是wp目录下的wp-load.php
	wp();//这样wp的加载就完成了,我们不需要加载模板。
?>
<?php while (have_posts()) : the_post(); ?>
<div class="entry">
<?php the_excerpt();?> 
</div>
<?php endwhile; ?>
<!--导航开始-->
<p align="center">
<?php 
global $paged, $wp_query;
if($paged>1)
echo '<a href='.str_replace($loca,'',get_previous_posts_page_link()).'>&laquo; Previous Entry</a> ';
if($paged<$wp_query->max_num_pages)
echo ' <a href='.str_replace($loca,'',get_next_posts_page_link()).'>Next Entry &raquo;</a>';
?>
</p>
<!--导航结束-->
<!--页尾自己按照自己要求写-->

导航需要自己重写(分页也一样)。
PS.原创内容,转载请注明,作者:小JOE 地址:http://xiebiji.com/?p=491

20 Responses to 关于非WP目录下的.php文件显示文章... »

  1. nwgale 评论 2008-08-24 22:16

    :mrgreen: JOE兄,非常感谢!
    等我测试一下,呵呵~~

    回复

    joe 回复 八月 24th, 2008 at 22:21

    刷新!我刚没有把完整代码贴上,现在好了!

    回复

  2. nwgale 评论 2008-08-26 22:10

    好像这个 wp-load.php 文件不存在啊?
    调不到这个文件,然后我去本地目录搜索了一下,也没发现这个文件? 我是WP 2.51 version.

    回复

    joe 回复 八月 26th, 2008 at 22:18

    有的,在WP的根目录下,你或者查找一下function wp()

    回复

    nwgale 回复 八月 26th, 2008 at 22:27

    收一下你的Email :)

    回复

    joe 回复 八月 26th, 2008 at 22:28

    :cool: 23456325@qq.com

  3. 在blog之外的页面读取文章摘要 - 不周风·design Pingback 2008-08-27 00:26

    [...] 我对PHP完全不了解,更是难以理解wordpress的index.php和themes里的index.php之间的关系。热心的JOE同学写了一个小教程,帮助我实现了这个功能。 请看JOE的教程: 关于非WP目录下的.php文件显示文章摘要或者别的WP信息的方法 [...]

  4. Kerri 评论 2008-12-05 19:27

    You write very well.

    回复

    joe 回复 十二月 5th, 2008 at 22:20

    :razz: thank you!

    回复

  5. amao 评论 2008-12-10 10:07

    能否提供一下其他的怎么调用么
    比如wp的页面和单独分类的调用

    回复

    joe 回复 十二月 10th, 2008 at 19:31

    可以在输出日志前用query_posts()过滤
    这里有教程:http://codex.wordpress.org/Template_Tags/query_posts

    回复

  6. eric 评论 2009-02-14 12:32

    :o hh: 太好了,非常感谢!

    回复

  7. WordPress以外调用文章列表或摘要方法(解决永久链接问题) | Modern Fun - 摩登坊 | Steve Luo's Blog Pingback 2009-08-03 16:09

    [...] 很高兴在关于非WP目录下的.php文件显示文章摘要或者别的WP信息的方法一文中找到了实现方法,也很容易上手,放在一个空白的测试页中运行成功。 [...]

  8. 小石头.WEB » 在别的页面调用WP摘要 Pingback 2009-08-24 05:10

    [...] 导航需要自己重写(分页也一样)。 PS.原创内容,转载请注明,作者:小JOE 地址:http://xiebiji.com/?p=491 [...]

  9. bendung 评论 2009-10-28 11:02

    拜读了

    回复

  10. 在WP(WordPress)首页和目录页显示摘要 | 完美时光 Pingback 2010-12-06 02:58

    [...] 关于非WP目录下的.php文件显示文章摘要或者别的WP信息的方法 [...]

  11. CorelDraw插件 评论 2011-05-11 11:12

    有没办法实现跨站指定文章的调取摘要

    回复

  12. XtsklgxnoJ 评论 2012-03-19 00:07

    beats headphones
    and she was carsick .sister to work ,Man :Qi a lady riding a tricycle to send her daughter to school a girl next door Sun Jing ,Liu Laiyi could only be borrowed money from .is really adorable !not letter? 26 found the old man’s son — Weifang city Hanting District Hanting street in Zhang Zhuangcun Yang Bujun. he would soon have a look into Taiwan’s father. or else she would freeze to death in the dustbin .I told myself I want to be her mother .He smiles and says to the reporter , I am by the knife , previous climbing area car experience .The woman in the bright Street six years ,In June 9,but will not endanger the personal safety ,green because of the congenital disability ,carrying a child around to see a doctor to see a doctor .which is a lot of angel Mom on the small party Hui evaluation ,in the angel was established two years later , then to Humen City boutique escape direction. he and fellow workers at the store entrance to rest. the man up ,His daughter to eat feces to never have such a father yesterday afternoon,commissioned him to couple to the station .Let her helpless and circulate erroneous reports world said ,Chen Ping is overwhelmed .we spend money to avoid disaster ,On November 25th,This video is about 2 minutes long.
    Beats by Dr.Dre HeartBeats

    回复

  13. test limit | Vainner Pingback 2012-03-30 19:51

    [...] 关于非WP目录下的.php文件显示文章摘要或者别的WP信息的方法 [...]

  14. 关于非WP目录下的.Php文件显示文章摘要或者别的WP信息的方法 | 伟伟道来 Pingback 2012-04-15 20:32

    [...] 导航需要自己重写(分页也一样)。 PS.原创内容,转载请注明,作者:小JOE 地址:http://xiebiji.com/?p=491 [...]

Leave a Reply

Email address is not published

You should say a Chinese word to pass spam check. If you can not input Chinese, just copy 你好 and paste them into comment text box.