wordpress更神奇的8段短代码-设计技巧(2)

王朝数码·作者佚名  2010-05-07
宽屏版  字体: |||超大  

五、嵌入RSS阅读器

//This file is needed to be able to use the wp_rss() function.

include_once(ABSPATH.WPINC.'/rss.php');

function readRss($atts) {

extract(shortcode_atts(array(

"feed" = 'http://',

"num" = '1',

), $atts));

return wp_rss($feed, $num);

}

add_shortcode('rss', 'readRss');

使用简码的时候输入:[rss feed=“http://feed.happyet.org” num=“5”]

feed属性(attribute)即是要嵌入的feed URL,num即是要显示的条目数量。

六、使用简码从WordPress数据库中提取文章

function sc_liste($atts, $content = null) {

extract(shortcode_atts(array(

"num" = '5',

"cat" = ''

), $atts));

global $post;

$myposts = get_posts('numberposts='.$num.'&order=DESC&orderby=post_date&category='.$cat);

$retour='';

foreach($myposts as $post) :

setup_postdata($post);

$retour.='.get_permalink().'"'.the_title("","",false).'';

endforeach;

$retour.=' ';

return $retour;

}

add_shortcode("list", "sc_liste");

在WordPress编辑器中使用以下简码:[liste num=“3” cat=“1”],系统将从ID为1的类别中提取3篇文章。

代码注释:系统提取参数并创建全局变量$posts后,sc_liste()函数使用了 get_posts(),numberposts, order, orderby和category参数以从类别Y中获取X篇最新日志。完成后,系统就会以无序的HTML列表形式显示日志。

七、获取日志中的最新图像

function sc_postimage($atts, $content = null) {

extract(shortcode_atts(array(

"size" = 'thumbnail',

"float" = 'none'

), $atts));

$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . get_the_id() );

foreach( $images as $imageID = $imagePost )

$fullimage = wp_get_attachment_image($imageID, $size, false);

$imagedata = wp_get_attachment_image_src($imageID, $size, false);

$width = ($imagedata[1]+2);

$height = ($imagedata[2]+2);

return '.$width.'px; height: '.$height.'px; float: '.$float.';"'.$fullimage.'

第一页    上一页    第2页/共2页    下一页    最后页
第01页 第02页 
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有