Questions tagged «get-children»

3
检查当前类别是否有子级
我需要告诉我正在查看的当前自定义分类存档页面是否具有子类别。我遇到的情况是,有很多带有孩子的自定义类别,并且该站点仅在行尾显示帖子。否则,它应该显示指向下一步的类别的链接。我已经找到了此代码段,但它似乎不适用于自定义分类法。 function category_has_children() { global $wpdb; $term = get_queried_object(); $category_children_check = $wpdb->get_results(" SELECT * FROM wp_term_taxonomy WHERE parent = '$term->term_id' "); if ($category_children_check) { return true; } else { return false; } } <?php if (!category_has_children()) { //use whatever loop or template part here to show the posts at the …

5
从帖子内容中获取第一张图片(例如:热链接图片)
我直接从Codex使用此代码。 function echo_first_image ($postID) { $args = array( 'numberposts' => 1, 'order'=> 'ASC', 'post_mime_type' => 'image', 'post_parent' => $postID, 'post_status' => null, 'post_type' => 'attachment' ); $attachments = get_children( $args ); //print_r($attachments); if ($attachments) { foreach($attachments as $attachment) { $image_attributes = wp_get_attachment_image_src( $attachment->ID, 'thumbnail' ) ? wp_get_attachment_image_src( $attachment->ID, 'thumbnail' ) …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.