child-pages.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
class CPAC_Column_Post_Child_Pages extends CPAC_Column {
public function init() {
parent::init();
// Properties
$this->properties['type'] = 'column-child-pages';
$this->properties['label'] = __( 'Child Pages', 'codepress-admin-columns' );
}
public function get_value( $post_id ) {
$titles = array();
// display title with link
if ( $ids = $this->get_raw_value( $post_id ) ) {
foreach ( $ids as $id ) {
$link = get_edit_post_link( $id );
if ( $title = get_the_title( $id ) ){
$title = $link ? "<a href='{$link}'>{$title}</a>" : $title;
$titles[] = $title . "<br/>";
}
}
}
return implode( $titles );
}
public function get_raw_value( $post_id ) {
$ids = get_posts( array(
'post_type' => $this->storage_model->post_type,
'post_parent' => $post_id,
'fields' => 'ids' ,
'posts_per_page' => -1
) );
return $ids;
}
public function apply_conditional() {
return is_post_type_hierarchical( $this->storage_model->post_type ) || post_type_supports( $this->storage_model->post_type, 'page-attributes' );
}
}