付费写一个调用最新文章的代码
我的wp安装的目录blog下,我想在我的网站首页显示blog的2篇最新文章,请论坛的朋友帮忙写段代码,费用50元,请发短消息给我,谢谢 这个不是很简单吗? 好多主题都有这个功能。 我不会阿,版主帮帮忙吧,我是显示在网站首页,不是blog的首页 我给你写,不要钱 <?php query_posts('showposts=10'); ?><?php if (have_posts()) : while (have_posts()) : the_post(); ?><li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>在sidebar 实验一下以上代码。showpost=10 控制的是 显示数目 比如你还可以改成 5 等等 [code]<?php
//调用WP的配置文件,别小看这个文件哦,这里改成你的blog的路径.
require_once('site/wp-config.php');
//这个函数从中文工具箱中copy的
//调用wp-config.php文件的目的主要是使用他的db查询功能,可以自己写连接MYSQL部份,但是觉得没有必要.
//主要应用在$wpdb变量中
function get_recent_comments($no_comments = 5, $before = '
', $after = '', $show_pass_post = false) {
global $wpdb;
$request = "SELECT ID, comment_ID, comment_content, comment_author FROM $wpdb->posts, $wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "AND comment_approved = '1' ORDER BY $wpdb->comments.comment_date DESC LIMIT
$no_comments";
$comments = $wpdb->get_results($request);
$output = '';
foreach ($comments as $comment) {
$comment_author = stripslashes($comment->comment_author);
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
$comment_excerpt =substr($comment_content,0,32);
$comment_excerpt = utf8_trim($comment_excerpt);
$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
$output .= $before . '» ' . $comment_author . ': ' . $comment_excerpt . '...' . $after;
}
echo $output;
}
//中文截断完善函数
function utf8_trim($str) {
$len = strlen($str);
for ($i=strlen($str)-1; $i>=0; $i-=1){
$hex .= ' '.ord($str[$i]);
$ch = ord($str[$i]);
if (($ch & 128)==0) return(substr($str,0,$i));
if (($ch & 192)==192) return(substr($str,0,$i));
}
return($str.$hex);
}
//执行函数,输出结果,这里你可以去掉下面这行,通过包含本文件来调用get_recent_comments();函数。
get_recent_comments();
?>[/code]将以上代码保成一个php文件,放在任意目录,修改wp-config.php的路径就可以了,祝你成功!
我也不知道你具体要怎么使用,所以我也只能猜想你想这样~! 谢谢这么多热心的朋友,
我6楼的版主的代码测试成功,但是只显示标题阿,没有显示内容,如果要显示内容应该怎么弄呢?
测试成功的代码如下:
<?php
//调用WP的配置文件,别小看这个文件哦,这里改成你的blog的路径.
require_once('wordpress/wp-config.php');
//这个函数从中文工具箱中copy的
//调用wp-config.php文件的目的主要是使用他的db查询功能,可以自己写连接MYSQL部份,但是觉得没有必要.
//主要应用在$wpdb变量中
function get_recent_posts($no_posts = 2, $before = '<li>+ ', $after = '</li>', $show_pass_post = false, $skip_posts = 0) {
global $wpdb, $tableposts;
$request = "SELECT ID, post_title, post_date, post_content FROM $tableposts WHERE post_status = 'publish' ";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "ORDER BY post_date DESC LIMIT $skip_posts, $no_posts";
$posts = $wpdb->get_results($request);
$output = '';
foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
// $post_date = mysql2date('j.m.Y', $post->post_date);
$permalink = get_permalink($post->ID);
$output .= $before . '<a href="' . $permalink . '" rel="bookmark" title="Permanent Link: ' . $post_title . '">' . $post_title . '</a>'. $after;
}
echo $output;
}
function mul_excerpt ($excerpt) {
$myexcerpt = substr($excerpt,0,255);
return utf8_trim($myexcerpt) . '... ';
}
//执行函数,输出结果,这里你可以去掉下面这行,通过包含本文件来调用get_recent_comments();函数。
get_recent_posts();
?> 在foreach ($posts as $post) {中加入下面的代码应该可以得到文章的内容~![code]$post_content = strip_tags($post->post_content); [/code]
具体的参考中文工具箱里的写法...
你这个函数是旧版的,找新版的中文工具箱...
[[i] 本帖最后由 fvzone 于 2008-4-29 21:21 编辑 [/i]] 我试了呀,还是不行呢 不知道你为什么不行,好像搞得有点复杂。
你先安装 桑林志的中文插件 什么都不要修改 然后, 在你的主题侧边栏合适地方,加入以下代码
<ul><?php query_posts('showposts=10'); ?><?php if (have_posts()) : while (have_posts()) : the_post(); ?><li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php endwhile; endif; ?>
</ul>
你只需要2篇日志 把 showposts=10 改成2 就可以了。 [quote]原帖由 [i]greatufo[/i] 于 2008-5-6 18:22 发表 [url=http://www.wordpress.org.cn/redirect.php?goto=findpost&pid=65107&ptid=12754][img]http://www.wordpress.org.cn/images/common/back.gif[/img][/url]
不知道你为什么不行,好像搞得有点复杂。
你先安装 桑林志的中文插件 什么都不要修改 然后, 在你的主题侧边栏合适地方,加入以下代码
[/quote]
他想要在别的地方调用WP的日志,不是在模板里面调用... [quote]原帖由 [i]fvzone[/i] 于 2008-5-7 11:03 发表 [url=http://wordpress.org.cn/redirect.php?goto=findpost&pid=65215&ptid=12754][img]http://wordpress.org.cn/images/common/back.gif[/img][/url]
他想要在别的地方调用WP的日志,不是在模板里面调用... [/quote]
是啊,他是这个意思。
看我的页面就是这样的意思:[url]http://bingu.net[/url]
页:
[1]