Month: September 2013
Get first or last element from PHP array()
$stack = array(“orange”, “banana”, “apple”, “raspberry”); $last_value = array_pop($stack); // return “raspberry” $first_value = array_shift(array_values($stack)); // return “orange”
WordPress 参考函数:get_children
描述 get_children() 返回附件(attachments)、历史版本(revisions)或者根据父页面获取子页面。类似与 get_posts()。 概要 array $children =& get_children( mixed $args = “”, constant $output = OBJECT); 返回值 返回一个文章关联数组(参数 $output 决定输出的变量类型),以文章ID作为数组的Key。如果没有发现任何文章,返回空数组。 在版本2.9之前,如果没有发现任何文章则返回 false。 默认参数(版本2.7) $defaults = array( ‘post_parent’ => 0, ‘post_type’ => ‘any’, ‘numberposts’ => -1, ‘post_status’ => ‘any’ ); 参数 全部参数参考 get_posts()。 版本2.6以后,你必须通过一个非空的文章类型(post_type)参数(或附件(attachment)或页面(page))。 $args (混合型)通过一个数组设置多个参数。通过一个整形的文章ID或者一个文章对象可以获得该文章的子文章。如果是一个空的值,则可以获得当前文章或者页面的子文章或页面。 $args[‘numberposts’] (整形)获取子文章或页面的数量。可选的,默认 -1(无限制) $args[‘post_parent’] (整形)通过文章或页面的ID获取他们的子文章或页面。Pass 0 to get attachments without…
WordPress 参考函数:get_boundary_post
描述 获取发表的第一篇或最后一篇文章。 使用 <?php get_boundary_post( $in_same_cat, $excluded_categories, $start ); ?> 参数 $in_same_cat (布尔型)(可选)是否在同一分类。默认:false $excluded_categories (字符串)(可选)排除分类的ID。默认:’’ $start (布尔型)(可选)是否是第一篇。默认:true。 返回值 如果成功,返回文章对象。 如果全局变量 $post 没有设定,返回空。 如果没有相应的文章存在,返回空字符串。 注释 get_boundary_post() 将文章指向第一篇文章。 变更日志 版本2.8.0起 源码位置 get_boundary_post()在 wp-includes/link-template.php.
WordPress 参考函数:get_adjacent_post
描述 获取毗连的文章。 可以是前一篇或后一篇。 使用 <?php get_adjacent_post( $in_same_cat, $excluded_categories, $previous ) ?> 参数 $in_same_cat (布尔型)(可选的)文章是否在相同的分类。 默认:false。 $excluded_categories (字符串)(可选的)剔除分类的ID。默认:‘’ $previous (布尔型)(可选的)是否返回上一篇文章。默认:true 返回值 如果没有错误,返回文章对象。 如果全局变量 $post 没有设置,返回值是 Null。 如果不存在相匹配的文章,返回空字符串。 注释 使用全局变量:(对象)$post 使用全局变量:(对象)$wpdb Filters $adjacent 是 ‘previous’ 或者 ‘next’ “get_{$adjacent}_post_join”: $join, $in_same_cat, $excluded_categories “get_{$adjacent}_post_where”: $wpdb->prepare(“WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = ‘publish’ $posts_in_ex_cats_sql”, $current_post_date, $post->post_type), $in_same_cat, $excluded_categories…