\n";
}
}
//
// Pages
//
function get_pages($args = '') {
global $wpdb;
parse_str($args, $r);
if (!isset($r['child_of'])) $r['child_of'] = 0;
if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title';
if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC';
$exclusions = '';
if (!empty($r['exclude'])) {
$expages = preg_split('/[\s,]+/',$r['exclude']);
if (count($expages)) {
foreach ($expages as $expage) {
$exclusions .= ' AND ID <> ' . intval($expage) . ' ';
}
}
}
$dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified";
$dates .= ",UNIX_TIMESTAMP(post_date) AS time_created";
$post_parent = '';
if ($r['child_of']) {
$post_parent = ' AND post_parent=' . $r['child_of'] . ' ';
}
$pages = $wpdb->get_results("SELECT " .
"ID, post_title,post_parent " .
"$dates " .
"FROM $wpdb->posts " .
"WHERE post_status = 'static' " .
"$post_parent" .
"$exclusions " .
"ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
return $pages;
}
function bm_list_pages($args = '') {
parse_str($args, $r);
if (!isset($r['depth'])) $r['depth'] = 0;
if (!isset($r['show_date'])) $r['show_date'] = '';
if (!isset($r['child_of'])) $r['child_of'] = 0;
if ( !isset($r['title_li']) ) $r['title_li'] = __('Pages');
// Query pages.
$pages = get_pages($args);
if ( $pages ) :
if ( $r['title_li'] )
echo '
' . $r['title_li'] . '
';
// Now loop over all pages that were selected
$page_tree = Array();
foreach($pages as $page) {
// set the title for the current page
$page_tree[$page->ID]['title'] = $page->post_title;
// set the selected date for the current page
// depending on the query arguments this is either
// the createtion date or the modification date
// as a unix timestamp. It will also always be in the
// ts field.
if (! empty($r['show_date'])) {
if ('modified' == $r['show_date'])
$page_tree[$page->ID]['ts'] = $page->date_modified;
else
$page_tree[$page->ID]['ts'] = $page->date_created;
}
// The tricky bit!!
// Using the parent ID of the current page as the
// array index we set the curent page as a child of that page.
// We can now start looping over the $page_tree array
// with any ID which will output the page links from that ID downwards.
$page_tree[$page->post_parent]['children'][] = $page->ID;
}
// Output of the pages starting with child_of as the root ID.
// child_of defaults to 0 if not supplied in the query.
_page_level_out($r['child_of'],$page_tree, $r);
if ( $r['title_li'] )
echo '
\n";
}
}
function get_threads($args = '') {
global $wpdb;
parse_str($args, $r);
if (!isset($r['child_of'])) $r['child_of'] = 0;
if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title';
if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC';
$exclusions = '';
if (!empty($r['exclude'])) {
$exthreads = preg_split('/[\s,]+/',$r['exclude']);
if (count($exthreads)) {
foreach ($exthreads as $exthread) {
$exclusions .= ' AND menu_order <> ' . intval($exthread) . ' ';
}
}
}
$dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified";
$dates .= ",UNIX_TIMESTAMP(post_date) AS time_created";
$post_parent = '';
if ($r['child_of']) {
$post_parent = ' AND post_parent=' . $r['child_of'] . ' ';
}
$threads = $wpdb->get_results("SELECT " .
"menu_order, post_title,post_parent " .
"$dates " .
"FROM $wpdb->posts " .
// "WHERE post_status != 'static' " .
"WHERE ID=26845 " .
"$post_parent" .
"$exclusions " .
"ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
print_r($threads);
return $threads;
}
function bm_list_threads($args = '') {
parse_str($args, $r);
if (!isset($r['depth'])) $r['depth'] = 0;
if (!isset($r['show_date'])) $r['show_date'] = '';
if (!isset($r['child_of'])) $r['child_of'] = 0;
if (!isset($r['title_li']) ) $r['title_li'] = __('Threads');
// Query threads.
$threads = get_threads($args);
if ( $threads ) :
if ( $r['title_li'] )
echo '
' . $r['title_li'] . '
';
// Now loop over all threaded postmails that were selected
$thread_tree = Array();
foreach($threads as $thread) {
// set the title for the current page
$thread_tree[$thread->menu_order]['title'] = $thread->post_title;
// set the selected date for the current threaded postmail
// depending on the query arguments this is either
// the createtion date or the modification date
// as a unix timestamp. It will also always be in the
// ts field.
if (! empty($r['show_date'])) {
if ('modified' == $r['show_date'])
$thread_tree[$thread->menuorder]['ts'] = $thread->date_modified;
else
$thread_tree[$thread->menuorder]['ts'] = $thread->date_created;
}
// The tricky bit!!
// Using the menu_order of the current threaded postmail as the
// array index we set the curent threaded postmail as a child of that postmail.
// We can now start looping over the $thread_tree array
// with any menu_order which will output the threaded postmails links from that menu_order downwards.
$thread_tree[$thread->post_parent]['children'][] = $thread->menu_order;
}
// Output of the threads starting with child_of as the root ID.
// child_of defaults to 0 if not supplied in the query.
_thread_level_out($r['child_of'],$thread_tree, $r);
if ( $r['title_li'] )
echo '