function get_category_children($parent_id) { $cat_list = array($parent_id); $query = tep_db_query('select categories_id from ' . TABLE_CATEGORIES . ' where parent_id = ' . (int) $parent_id); while ($cat = tep_db_fetch_array($query)) { $children = get_category_children($cat['categories_id']); $cat_list = array_merge($cat_list, $children); } return $cat_list; }
function getchild($id) { $result = explode('/', get_category_children($id)); $childs = array(); foreach ($result as $i) { if (!empty($i)) { $childs[] = get_category($i); } } return $childs; }
function get_category_children($id, $before = '/', $after = '') { if (0 == $id) { return ''; } $chain = ''; $cat_ids = get_all_category_ids(); foreach ($cat_ids as $cat_id) { if ($cat_id == $id) { continue; } $category = get_category($cat_id); if ($category->category_parent == $id) { $chain .= $before . $category->cat_ID . $after; $chain .= get_category_children($category->cat_ID, $before, $after); } } return $chain; }
/** * Retrieve category children list separated before and after the term IDs. * * @since 1.2.0 * * @param int $id Category ID to retrieve children. * @param string $before Optional. Prepend before category term ID. * @param string $after Optional, default is empty string. Append after category term ID. * @param array $visited Optional. Category Term IDs that have already been added. * @return string */ function get_category_children( $id, $before = '/', $after = '', $visited = array() ) { if ( 0 == $id ) return ''; $chain = ''; /** TODO: consult hierarchy */ $cat_ids = get_all_category_ids(); foreach ( (array) $cat_ids as $cat_id ) { if ( $cat_id == $id ) continue; $category = get_category( $cat_id ); if ( is_wp_error( $category ) ) return $category; if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) { $visited[] = $category->term_id; $chain .= $before.$category->term_id.$after; $chain .= get_category_children( $category->term_id, $before, $after ); } } return $chain; }
function widget_sub($args) { global $cat, $post; extract($args); $options = get_option('widget_sub'); if (is_category()) { $category = get_category($cat); if (get_category_children($category->cat_ID) != '') { echo $before_widget, $before_title . $options['title_category'] . $after_title, '<ul class="clearfix">', wp_list_categories('child_of='.$category->cat_ID.'&title_li=&depth=1&hide_empty=0'), '</ul>', $after_widget; } } if (is_page()) { $page = wp_list_pages('&child_of='.$post->ID.'&echo=0'); if ($page) { echo $before_widget, $before_title . $options['title_page'] . $after_title, '<ul class="clearfix">', wp_list_pages('child_of='.$post->ID.'&title_li=&depth=1'), '</ul>', $after_widget; } } }
function get_category_children($id, $before = '/', $after = '') { if (0 == $id) { return ''; } $chain = ''; // TODO: consult hierarchy $cat_ids = get_all_category_ids(); foreach ($cat_ids as $cat_id) { if ($cat_id == $id) { continue; } $category = get_category($cat_id); if (is_wp_error($category)) { return $category; } if ($category->parent == $id) { $chain .= $before . $category->term_id . $after; $chain .= get_category_children($category->term_id, $before, $after); } } return $chain; }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); ?> <?php echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $args = array('depth' => '1'); $categories = get_categories($args); foreach ($categories as $cat) { // check if category has child if (get_category_children($cat->term_id) != "") { echo '<span class="parent-category-title">' . $cat->name . '</span><br />'; wp_dropdown_categories(array('id' => $cat->term_id, 'class' => 'child-cat-select', 'child_of' => $cat->term_id, 'show_option_none' => 'Select ' . $cat->name, 'hide_if_empty' => 1)); echo '<br />'; } } echo $after_widget; wp_enqueue_script('jquery'); ?> <script type="text/javascript"><!-- jQuery(".child-cat-select").change(function() { if (jQuery(this).val() > 0) { location.href = "<?php echo get_option('home'); ?> /?cat=" + jQuery(this).val(); } }); --></script> <?php }
function get_posts() { global $wpdb, $pagenow, $request, $user_ID; // Shorthand. $q = $this->query_vars; // First let's clear some variables $whichcat = ''; $whichauthor = ''; $result = ''; $where = ''; $limits = ''; $distinct = ''; $join = ''; if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 ) $q['posts_per_page'] = get_settings('posts_per_page'); if ( !isset($q['what_to_show']) ) $q['what_to_show'] = get_settings('what_to_show'); if ( isset($q['showposts']) && $q['showposts'] ) { $q['showposts'] = (int) $q['showposts']; $q['posts_per_page'] = $q['showposts']; } if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) ) $q['posts_per_page'] = $q['posts_per_archive_page']; if ( !isset($q['nopaging']) ) { if ($q['posts_per_page'] == -1) { $q['nopaging'] = true; } else { $q['nopaging'] = false; } } if ( $this->is_feed ) $q['posts_per_page'] = get_settings('posts_per_rss'); $add_hours = intval(get_settings('gmt_offset')); $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours)); $wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)"; // If a month is specified in the querystring, load that month if ( (int) $q['m'] ) { $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); $where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4); if (strlen($q['m'])>5) $where .= ' AND MONTH(post_date)=' . substr($q['m'], 4, 2); if (strlen($q['m'])>7) $where .= ' AND DAYOFMONTH(post_date)=' . substr($q['m'], 6, 2); if (strlen($q['m'])>9) $where .= ' AND HOUR(post_date)=' . substr($q['m'], 8, 2); if (strlen($q['m'])>11) $where .= ' AND MINUTE(post_date)=' . substr($q['m'], 10, 2); if (strlen($q['m'])>13) $where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2); } if ( (int) $q['hour'] ) { $q['hour'] = '' . intval($q['hour']); $where .= " AND HOUR(post_date)='" . $q['hour'] . "'"; } if ( (int) $q['minute'] ) { $q['minute'] = '' . intval($q['minute']); $where .= " AND MINUTE(post_date)='" . $q['minute'] . "'"; } if ( (int) $q['second'] ) { $q['second'] = '' . intval($q['second']); $where .= " AND SECOND(post_date)='" . $q['second'] . "'"; } if ( (int) $q['year'] ) { $q['year'] = '' . intval($q['year']); $where .= " AND YEAR(post_date)='" . $q['year'] . "'"; } if ( (int) $q['monthnum'] ) { $q['monthnum'] = '' . intval($q['monthnum']); $where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'"; } if ( (int) $q['day'] ) { $q['day'] = '' . intval($q['day']); $where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'"; } if ('' != $q['name']) { $q['name'] = sanitize_title($q['name']); $where .= " AND post_name = '" . $q['name'] . "'"; } else if ('' != $q['pagename']) { $q['pagename'] = sanitize_title(basename(str_replace('%2F', '/', urlencode($q['pagename'])))); $q['name'] = $q['pagename']; $where .= " AND post_name = '" . $q['pagename'] . "'"; } if ( (int) $q['w'] ) { $q['w'] = ''.intval($q['w']); $where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'"; } if ( intval($q['comments_popup']) ) $q['p'] = intval($q['comments_popup']); // If a post number is specified, load that post if (($q['p'] != '') && intval($q['p']) != 0) { $q['p'] = (int) $q['p']; $where = ' AND ID = ' . $q['p']; } if (($q['page_id'] != '') && (intval($q['page_id']) != 0)) { $q['page_id'] = intval($q['page_id']); $q['p'] = $q['page_id']; $where = ' AND ID = '.$q['page_id']; } // If a search pattern is specified, load the posts that match if (!empty($q['s'])) { $q['s'] = addslashes_gpc($q['s']); $search = ' AND ('; $q['s'] = preg_replace('/, +/', ' ', $q['s']); $q['s'] = str_replace(',', ' ', $q['s']); $q['s'] = str_replace('"', ' ', $q['s']); $q['s'] = trim($q['s']); if ($q['exact']) { $n = ''; } else { $n = '%'; } if (!$q['sentence']) { $s_array = explode(' ',$q['s']); $q['search_terms'] = $s_array; $search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))'; for ( $i = 1; $i < count($s_array); $i = $i + 1) { $search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))'; } $search .= ' OR (post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\')'; $search .= ')'; } else { $search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\'))'; } } // Category stuff if ((empty($q['cat'])) || ($q['cat'] == '0') || // Bypass cat checks if fetching specific posts ( $this->is_single || $this->is_page )) { $whichcat=''; } else { $q['cat'] = ''.urldecode($q['cat']).''; $q['cat'] = addslashes_gpc($q['cat']); if (stristr($q['cat'],'-')) { // Note: if we have a negative, we ignore all the positives. It must // always mean 'everything /except/ this one'. We should be able to do // multiple negatives but we don't :-( $eq = '!='; $andor = 'AND'; $q['cat'] = explode('-',$q['cat']); $q['cat'] = intval($q['cat'][1]); } else { $eq = '='; $andor = 'OR'; } $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) "; $cat_array = preg_split('/[,\s]+/', $q['cat']); $whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]); $whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' '); for ($i = 1; $i < (count($cat_array)); $i = $i + 1) { $whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]); $whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' '); } $whichcat .= ')'; if ($eq == '!=') { $q['cat'] = '-'.$q['cat']; // Put back the knowledge that we are excluding a category. } } // Category stuff for nice URIs if ('' != $q['category_name']) { if (stristr($q['category_name'],'/')) { $q['category_name'] = explode('/',$q['category_name']); if ($q['category_name'][count($q['category_name'])-1]) { $q['category_name'] = $q['category_name'][count($q['category_name'])-1]; // no trailing slash } else { $q['category_name'] = $q['category_name'][count($q['category_name'])-2]; // there was a trailling slash } } $q['category_name'] = sanitize_title($q['category_name']); $tables = ", $wpdb->post2cat, $wpdb->categories"; $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) "; $whichcat = " AND (category_nicename = '" . $q['category_name'] . "'"; $q['cat'] = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '" . $q['category_name'] . "'"); $whichcat .= get_category_children($q['cat'], " OR category_id = "); $whichcat .= ")"; } // Author/user stuff if ((empty($q['author'])) || ($q['author'] == '0')) { $whichauthor=''; } else { $q['author'] = ''.urldecode($q['author']).''; $q['author'] = addslashes_gpc($q['author']); if (stristr($q['author'], '-')) { $eq = '!='; $andor = 'AND'; $q['author'] = explode('-', $q['author']); $q['author'] = ''.intval($q['author'][1]); } else { $eq = '='; $andor = 'OR'; } $author_array = preg_split('/[,\s]+/', $q['author']); $whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]); for ($i = 1; $i < (count($author_array)); $i = $i + 1) { $whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]); } $whichauthor .= ')'; } // Author stuff for nice URIs if ('' != $q['author_name']) { if (stristr($q['author_name'],'/')) { $q['author_name'] = explode('/',$q['author_name']); if ($q['author_name'][count($q['author_name'])-1]) { $q['author_name'] = $q['author_name'][count($q['author_name'])-1];#no trailing slash } else { $q['author_name'] = $q['author_name'][count($q['author_name'])-2];#there was a trailling slash } } $q['author_name'] = sanitize_title($q['author_name']); $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'"); $whichauthor .= ' AND (post_author = '.intval($q['author']).')'; } $where .= $search.$whichcat.$whichauthor; if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) { $q['order']='DESC'; } // Order by if (empty($q['orderby'])) { $q['orderby']='date '.$q['order']; } else { // Used to filter values $allowed_keys = array('author','date','category','title'); $q['orderby'] = urldecode($q['orderby']); $q['orderby'] = addslashes_gpc($q['orderby']); $orderby_array = explode(' ',$q['orderby']); if (!in_array($orderby_array[0],$allowed_keys)) { $orderby_array[0] = 'date'; } $q['orderby'] = $orderby_array[0].' '.$q['order']; if (count($orderby_array)>1) { for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) { // Only allow certain values for safety if (in_array($orderby_array[$i],$allowed_keys)) { $q['orderby'] .= ',post_'.$orderby_array[$i].' '.$q['order']; } } } } $now = gmdate('Y-m-d H:i:59'); if ($pagenow != 'post.php' && $pagenow != 'edit.php') { $where .= " AND post_date_gmt <= '$now'"; $distinct = 'DISTINCT'; } if ($this->is_page) { $where .= ' AND (post_status = "static"'; } else { $where .= ' AND (post_status = "publish"'; } // Get private posts if (isset($user_ID) && ('' != intval($user_ID))) $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')"; else $where .= ')'; // Apply filters on where and join prior to paging so that any // manipulations to them are reflected in the paging by day queries. $where = apply_filters('posts_where', $where); $join = apply_filters('posts_join', $join); // Paging if (empty($q['nopaging']) && ! $this->is_single) { $page = $q['paged']; if (empty($page)) { $page = 1; } if (($q['what_to_show'] == 'posts')) { $pgstrt = ''; $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', '; $limits = 'LIMIT '.$pgstrt.$q['posts_per_page']; } elseif ($q['what_to_show'] == 'days') { $startrow = $q['posts_per_page'] * (intval($page)-1); $start_date = $wpdb->get_var("SELECT max(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $startrow,1"); $endrow = $startrow + $q['posts_per_page'] - 1; $end_date = $wpdb->get_var("SELECT min(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $endrow,1"); if ($page > 1) { $where .= " AND post_date >= '$end_date' AND post_date <= '$start_date'"; } else { $where .= " AND post_date >= '$end_date'"; } } } // Apply post-paging filters on where and join. Only plugins that // manipulate paging queries should use these hooks. $where = apply_filters('posts_where_paged', $where); $where .= " GROUP BY $wpdb->posts.ID"; $join = apply_filters('posts_join_paged', $join); $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1".$where." ORDER BY post_" . $q['orderby'] . " $limits"; if ($q['preview']) { $request = 'SELECT 1-1'; // dummy mysql query for the preview // little funky fix for IEwin, rawk on that code $is_winIE = ((preg_match('/MSIE/',$HTTP_USER_AGENT)) && (preg_match('/Win/',$HTTP_USER_AGENT))); if (($is_winIE) && (!isset($IEWin_bookmarklet_fix))) { $preview_content = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $preview_content); } } $this->posts = $wpdb->get_results($request); $this->posts = apply_filters('the_posts', $this->posts); $this->post_count = count($this->posts); if ($this->post_count > 0) { $this->post = $this->posts[0]; } update_post_caches($this->posts); // Save any changes made to the query vars. $this->query_vars = $q; return $this->posts; }
if (isset($params['category'])) { $posts_parent_category = $params['category']; } } if ($posts_parent_category != false) { $add_post_q .= ' parent-category-id="' . intval($posts_parent_category) . '" '; } if (!isset($params['global']) and $posts_parent_page != false and $posts_parent_category != false and intval($posts_parent_category) > 0) { $str0 = 'table=categories&limit=1000&data_type=category&what=categories&' . 'parent_id=0&rel_id=' . $posts_parent_page; $page_categories = db_get($str0); $sub_cats = array(); $page_categories = db_get($str0); if (is_array($page_categories)) { foreach ($page_categories as $item_cat) { $sub_cats[] = $item_cat['id']; $more = get_category_children($item_cat['id']); if ($more != false and is_array($more)) { foreach ($more as $item_more_subcat) { $sub_cats[] = $item_more_subcat; } } } } if (is_array($sub_cats) and in_array($posts_parent_category, $sub_cats)) { $add_post_q .= ' selected-category-id=' . intval($posts_parent_category); } } if (isset($params['is_shop']) and $params['is_shop'] == 'y') { $add_post_q .= ' content_type="product" '; } else { $add_post_q .= ' ';
$GLOBALS['category_name'] = $GLOBALS['category_name'][count($GLOBALS['category_name']) - 1]; // no trailing slash } else { $GLOBALS['category_name'] = $GLOBALS['category_name'][count($GLOBALS['category_name']) - 2]; // there was a trailling slash } } $GLOBALS['category_name'] = preg_replace('|[^a-z0-9-]|', '', $GLOBALS['category_name']); $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id'); $_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID')); $_wCriteria =& new CriteriaCompo(new Criteria('category_nicename', $GLOBALS['category_name'])); $categoryHandler =& wp_handler('Category'); $categoryObject =& $categoryHandler->getByNiceName($GLOBALS['category_name']); if ($categoryObject) { $GLOBALS['cat'] = $categoryObject->getVar('cat_ID'); $_catc = trim(get_category_children($GLOBALS['cat'], '', ' ')); $_catc_array = explode(' ', $_catc); for ($_i = 0; $_i < count($_catc_array); $_i++) { $_wCriteria->add(new Criteria('category_id', intval($_catc_array[$_i])), 'OR'); } $_criteria->add($_wCriteria); unset($_wCriteria); } } // author stuff if (test_param('author') && get_param('author') != 'all') { $GLOBALS['author'] = '' . urldecode(get_param('author')) . ''; $GLOBALS['author'] = addslashes_gpc($GLOBALS['author']); if (stristr($GLOBALS['author'], '-')) { $_eq = '!='; $_andor = 'AND';
<a title="Post Another Confession" class="btn-secondary-cta post-another-confession" href="#">Post Another Confession</a> </div> </div> <div class="mod-filter-confessions-faq clearfix"> <h2>Read the Latest Confessions</h2> <div class="filter-wrap"> <span class="label">Filter by:</span> <div class="dropdown-custom"> <select id='tagDropdown' class="tagDropdown" title="Tags" style="z-index: 10; opacity: 0;" > <option data-alias="<?php echo $url; ?> " value="all">View All</option> <?php $childAJQCategroy = ''; $childAJQCategroy = get_category_children('231'); $arrChildAJQCategroy = explode('/', $childAJQCategroy); sort($arrChildAJQCategroy); foreach ($arrChildAJQCategroy as $intCatId) { if (empty($intCatId)) { continue; } $strCatName = ''; $strCatName = get_the_category_by_ID($intCatId); echo "<option data-alias=\"/confessions/?tags=" . $strCatName . "\" value ='" . $strCatName . "' >#" . strtolower($strCatName) . "</option>"; } ?> </select> <span class="dropdown-custom-select"><?php if (isset($_REQUEST['tags'])) { echo $_REQUEST['tags'];
/** * gets all parents and child categories for the category passed * * @returns array parent and children array merged to return a general array of related categories * * @author Ryan R. Bayne * @package CSV 2 POST * @since 8.1.3 * @version 1.1 */ public function get_related_categories($category_id) { // get the categories parents $parent_array = self::get_category_parents_id($category_id, false, '/', false); // remove empty values as is usually returned by get_category_parents() $parent_array = array_diff($parent_array, array('', ' ')); // get the categories children $child_string = get_category_children($category_id, '/'); // turn string to array for the merge $child_array = explode('/', $child_string); // remove possible empty values (not sure if the child function returns them as the parent one does $child_array = array_diff($child_array, array('', ' ')); // return a merge return array_merge($parent_array, $child_array); }
function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children = FALSE, $child_of = 0, $categoryObjects = null, $recurse = 0, $feed = '', $feed_image = '', $exclude = '', $hierarchical = FALSE, $echo = true) { $list_cats = ''; // Optiondates now works if ('' == $file) { $file = wp_siteurl() . '/index.php'; } $excludeCriteria = null; if (!empty($exclude)) { $excats = preg_split('/[\\s,]+/', $exclude); if (count($excats)) { $excludeCriteria = new CriteriaCompo(); foreach ($excats as $excat) { $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' '; $excludeCriteria->add(new Criteria('cat_ID', $excat, '!=')); $catc = trim(get_category_children($excat, '', ' ')); $catc_array = explode(' ', $catc); for ($i = 0; $i < count($catc_array); $i++) { $excludeCriteria->add(new Criteria('category_id', intval($catc_array[$i]), '!=')); } } } } $categoryHandler =& wp_handler('Category'); if (!$categoryObjects) { $criteria =& new CriteriaCompo(new Criteria('cat_ID', 0, '>')); if ($excludeCriteria) { $criteria->add($excludeCriteria); } $criteria->setSort('cat_' . $sort_column); $criteria->setOrder($sort_order); $categoryObjects =& $categoryHandler->getObjects($criteria, false, 'cat_ID, cat_name, category_nicename, category_description cat_description, category_parent'); } if (empty($GLOBALS['category_posts']) || !count($GLOBALS['category_posts'])) { $criteria =& new CriteriaCompo('post_status', 'publish'); if ($excludeCriteria) { $criteria->add($excludeCriteria); } $criteria->setGroupBy('category_id'); $joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'cat_ID', 'category_id', 'INNER'); $joinCriteria->cascade(new XoopsJoinCriteria(wp_table('posts'), 'post_id', 'ID', 'INNER')); $categoryPostsObjects =& $categoryHandler->getObjects($criteria, false, 'cat_ID, COUNT(' . wp_table('post2cat') . '.post_id) AS cat_count', false, $joinCriteria); if ($categoryPostsObjects) { foreach ($categoryPostsObjects as $categoryObject) { if (intval($hide_empty) != 1 || $categoryObject->getExtraVar('cat_count') > 0) { $GLOBALS['category_posts'][$categoryObject->getVar('cat_ID')] = $categoryObject->getExtraVar('cat_count'); } } } } if (intval($optiondates) == 1) { $criteria =& new CriteriaCompo('post_status', 'publish'); if ($excludeCriteria) { $criteria->add($excludeCriteria); } $criteria->setGroupBy('category_id'); $joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'cat_ID', 'category_id', 'INNER'); $joinCriteria->cascade(new XoopsJoinCriteria(wp_table('posts'), 'post_id', 'ID', 'INNER')); $categoryDateObjects =& $categoryHandler->getObjects($criteria, false, 'cat_ID, DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth', false, $joinCriteria); foreach ($categoryDateObjects as $categoryObject) { $category_lastday["" . $categoryObject->getVar('cat_ID')] = $categoryObject->getExtraVar('lastday'); $category_lastmonth["" . $categoryObject->getVar('cat_ID')] = $categoryObject->getExtraVar('lastmonth'); } } if (intval($optionall) == 1 && !$child_of && $categoryObjects) { $all = apply_filters('list_cats', $all); $link = "<a href=\"" . $file . '?cat=all">' . $all . "</a>"; if ($list) { $list_cats .= "\n\t<li>{$link}</li>"; } else { $list_cats .= "\t{$link}<br />\n"; } } $num_found = 0; $thelist = ""; foreach ($categoryObjects as $categoryObject) { $category = $categoryObject->exportWpObject(); $child_list = ''; if ((!$hierarchical || $category->category_parent == $child_of) && ($children || $category->category_parent == 0)) { if ($hierarchical && $children) { $child_list = list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categoryObjects, 1, $feed, $feed_image, $exclude, $hierarchical); } if (intval($hide_empty) == 0 || isset($GLOBALS['category_posts']["{$category->cat_ID}"]) || $child_list) { $num_found++; $link = '<a href="' . get_category_link(0, $category->cat_ID, $category->category_nicename) . '" '; if ($use_desc_for_title == 0 || empty($category->cat_description)) { $link .= 'title="' . sprintf("View all posts filed under %s", htmlspecialchars($category->cat_name)) . '"'; } else { $link .= 'title="' . htmlspecialchars(strip_tags($category->cat_description)) . '"'; } $link .= '>'; $link .= apply_filters('list_cats', $category->cat_name) . '</a>'; if (!empty($feed_image) || !empty($feed)) { $link .= ' '; if (empty($feed_image)) { $link .= '('; } $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"'; if (!empty($feed)) { $title = ' title="' . $feed . '"'; $alt = ' alt="' . $feed . '"'; $name = $feed; $link .= $title; } $link .= '>'; if (!empty($feed_image)) { $link .= "<img src=\"{$feed_image}\" border=\"0\"{$alt}{$title}" . ' />'; } else { $link .= $name; } $link .= '</a>'; if (empty($feed_image)) { $link .= ')'; } } if (intval($optioncount) == 1) { $link .= ' (' . intval($GLOBALS['category_posts']["{$category->cat_ID}"]) . ')'; } if (intval($optiondates) == 1) { $link .= ' ' . $category_lastday["{$category->cat_ID}"] . '/' . $category_lastmonth["{$category->cat_ID}"]; } if ($list) { $thelist .= "\t<li>{$link}\n"; } else { $thelist .= "\t{$link}<br />\n"; } if ($hierarchical && $children) { $thelist .= $child_list; } if ($list) { $thelist .= "</li>\n"; } } } } if (!$num_found && !$child_of) { if ($list) { $before = '<li>'; $after = '</li>'; } return _echo($before . "No categories" . $after . "\n", $echo); } if ($list && $child_of && $num_found && $recurse) { $pre = "\t\t<ul class='children'>"; $post = "\t\t</ul>\n"; } else { $pre = $post = ''; } $thelist = $pre . $thelist . $post; if ($recurse) { return $thelist; } $list_cats .= apply_filters('list_cats', $thelist); return _echo($list_cats, $echo); }
function index($params, $config) { $current_page = $current_page = 1; $post_params = $params; if (isset($post_params['id'])) { $paging_param = 'current_page' . crc32($post_params['id']); unset($post_params['id']); } $cat_from_url = url_param('category'); $posts_parent_related = false; if (isset($params['current_page'])) { // $params['current_page'] = $params['current_page']; } elseif (isset($params['curent-page'])) { $params['current_page'] = $params['curent-page']; } elseif (isset($params['current-page'])) { $params['current_page'] = $params['current-page']; } elseif (isset($params['curent-page'])) { $params['current_page'] = $params['curent-page']; } if (isset($params['paging_param'])) { if (isset($params[$params['paging_param']])) { $current_page = $current_page = $params['current_page'] = $params[$params['paging_param']]; $paging_param = $params['paging_param']; } } if (isset($params['current_page'])) { $current_page = $params['current_page'] = $params['current_page']; } else { $current_page_from_url = url_param($paging_param); if ($current_page_from_url != false) { $current_page = $current_page_from_url; } } if (isset($post_params['data-page-number'])) { $post_params['current_page'] = $post_params['data-page-number']; unset($post_params['data-page-number']); } if (isset($post_params['data-category-id'])) { $post_params['category'] = $post_params['data-category-id']; unset($post_params['data-category-id']); } if (isset($params['data-paging-param'])) { $paging_param = $params['data-paging-param']; } $show_fields = false; if (isset($post_params['data-show'])) { $show_fields = $post_params['data-show']; } if (isset($post_params['show'])) { $show_fields = $post_params['show']; } $set_content_type_from_opt = get_option('data-content-type', $params['id']); $show_fields1 = get_option('data-show', $params['id']); if ($show_fields1 != false and is_string($show_fields1) and trim($show_fields1) != '') { $show_fields = $show_fields1; } if ($show_fields != false and is_string($show_fields)) { $show_fields = explode(',', $show_fields); } if (isset($post_params['limit'])) { $post_params['limit'] = $post_params['limit']; } if (isset($post_params['data-limit'])) { $post_params['limit'] = $post_params['data-limit']; } if (!isset($post_params['data-limit'])) { $posts_limit = get_option('data-limit', $params['id']); if ($posts_limit != false) { $post_params['limit'] = $posts_limit; } } $posts_parent_category = $posts_parent_category_cfg = get_option('data-category-id', $params['id']); if ($posts_parent_category == '') { $posts_parent_category = false; } $set_category_for_posts = false; $posts_limit = get_option('data-limit', $params['id']); if ($posts_limit != false) { $post_params['data-limit'] = $post_params['limit'] = $posts_limit; } $cfg_page_id = $cfg_page_id_force = get_option('data-page-id', $params['id']); if ($cfg_page_id == false and isset($post_params['data-page-id'])) { $cfg_page_id = intval($post_params['data-page-id']); } else { if ($cfg_page_id == false and isset($post_params['content_id'])) { $cfg_page_id = intval($post_params['content_id']); } else { if ($cfg_page_id == false and isset($post_params['content-id'])) { $cfg_page_id = intval($post_params['content-id']); } elseif ($cfg_page_id == false and isset($post_params['current_page'])) { $cfg_page_id = 'current_page'; } } } if ($posts_parent_category == false and isset($post_params['category_id'])) { $posts_parent_category = $post_params['category_id']; } if ($posts_parent_category == false and isset($post_params['related'])) { if (defined('CATEGORY_ID') and CATEGORY_ID > 0) { $posts_parent_category = $posts_parent_related = CATEGORY_ID; } } if ($posts_parent_category_cfg == 'related') { $posts_parent_related = true; $posts_parent_category = $posts_parent_related = CATEGORY_ID; } if ($posts_parent_category == false and $cfg_page_id == 'current_page') { if (defined('PAGE_ID') and PAGE_ID > 0) { $cfg_page_id = PAGE_ID; } } if ($posts_parent_category_cfg == false) { if (defined('CATEGORY_ID') and CATEGORY_ID > 0) { $posts_parent_category = CATEGORY_ID; } } if ($cfg_page_id == false and isset($post_params['related']) and $post_params['related'] != false and (!isset($post_params['parent']) or $post_params['parent'] == false)) { if (defined('PAGE_ID') and PAGE_ID > 0) { $cfg_page_id = PAGE_ID; $post_params['parent'] = $cfg_page_id; } } if (isset($post_params['most_ordered'])) { // $str0 = 'table=cart&limit=30&rel_type=content&fields=rel_id&order_by=id desc'; $orders = db_get($str0); if (!empty($orders)) { $ids = array(); foreach ($orders as $order) { $ids[] = $order['rel_id']; } $post_params['ids'] = $ids; } } if (isset($post_params['recently_viewed'])) { if (defined("MAIN_PAGE_ID") and defined("CONTENT_ID")) { $str0 = 'table=stats_pageviews&limit=30&main_page_id=' . MAIN_PAGE_ID . '&page_id=[neq]' . CONTENT_ID . '&fields=page_id&order_by=id desc&no_cache=true'; $orders = db_get($str0); if (!empty($orders)) { $ids = array(); foreach ($orders as $order) { $ids[] = $order['page_id']; } $post_params['ids'] = $ids; } } } if ($posts_parent_related == false) { if (intval($cfg_page_id_force) or !isset($params['global'])) { if ($cfg_page_id != false and intval($cfg_page_id) > 0) { $sub_categories = array(); $page_categories = false; if (intval($cfg_page_id) != 0 and $cat_from_url == false) { $str0 = 'table=categories&limit=1000&data_type=category&what=categories&' . 'parent_id=0&rel_id=' . $cfg_page_id; $page_categories = db_get($str0); $str0 = 'table=categories&limit=1000&data_type=category&what=categories&' . 'parent_id=0&rel_id=' . $cfg_page_id; $page_categories = db_get('table=categories&limit=1&data_type=category&' . 'parent_id=0&rel_id=' . $cfg_page_id); if (is_array($page_categories)) { foreach ($page_categories as $item_cat) { $sub_categories[] = $item_cat['id']; $more = get_category_children($item_cat['id']); if ($more != false and is_array($more)) { foreach ($more as $item_more_subcat) { $sub_categories[] = $item_more_subcat; } } } } } if ($posts_parent_category != false and intval($posts_parent_category) > 0 and $cat_from_url == false) { if ($page_categories != false and is_array($page_categories) and !empty($page_categories)) { // $sub_categories = array(); foreach ($page_categories as $item_cat) { if (intval($item_cat['id']) == intval($posts_parent_category)) { $sub_categories[] = $item_cat['id']; } } } elseif ($posts_parent_category_cfg != false) { $post_params['category'] = $posts_parent_category_cfg; } if (is_array($sub_categories) and !empty($sub_categories) and isset($post_params['related']) and $post_params['related'] != false) { $post_params['category'] = $sub_categories; } elseif ($cfg_page_id != false) { $post_params['parent'] = $cfg_page_id; } } else { $post_params['parent'] = $cfg_page_id; if (($cfg_page_id == PAGE_ID or $cfg_page_id == MAIN_PAGE_ID) and (!isset($post_params['category']) or $post_params['category'] == false) and $cat_from_url != false) { $post_params['category'] = $cat_from_url; } } } elseif ($cat_from_url != false) { $post_params['category'] = $cat_from_url; } elseif ($posts_parent_category != false and intval($posts_parent_category) > 0 and $cfg_page_id != false) { $post_params['category'] = $posts_parent_category; } } if ($posts_parent_category_cfg != false and intval($posts_parent_category_cfg) > 0 and $cfg_page_id_force != false and intval($cfg_page_id_force) > 0) { $post_params['category'] = $posts_parent_category_cfg; } } else { $post_params['category'] = $posts_parent_related; } $tn_size = array('150'); $tn = $tn_size; if (isset($post_params['data-thumbnail-size'])) { $temp = explode('x', strtolower($post_params['data-thumbnail-size'])); if (!empty($temp)) { $tn_size = $temp; } } else { $cfg_page_item = get_option('data-thumbnail-size', $params['id']); if ($cfg_page_item != false) { $temp = explode('x', strtolower($cfg_page_item)); if (!empty($temp)) { $tn_size = $temp; } } } if (!isset($tn[0]) or $tn[0] == 150) { $tn[0] = 350; } if (!isset($tn[1])) { $tn[1] = $tn[0]; } $character_limit = 120; $cfg_character_limit = get_option('data-character-limit', $params['id']); if ($cfg_character_limit != false and trim($cfg_character_limit) != '') { $character_limit = intval($cfg_character_limit); } else { if (isset($params['description-length'])) { $character_limit = intval($params['description-length']); } } $title_character_limit = 200; $cfg_character_limit1 = get_option('data-title-limit', $params['id']); if ($cfg_character_limit1 != false and trim($cfg_character_limit1) != '') { $title_character_limit = intval($cfg_character_limit1); } else { if (isset($params['title-length'])) { $title_character_limit = intval($params['title-length']); } } if ($show_fields == false) { //$show_fields = array('thumbnail', 'title', 'description', 'read_more'); } if (is_array($show_fields)) { $show_fields = array_trim($show_fields); } if (isset($current_page) and intval($current_page) > 0) { $post_params['current_page'] = intval($current_page); } if (!isset($post_params['global'])) { if (!isset($post_params['content_type'])) { $post_params['content_type'] = 'post'; } } if (isset($params['is_shop'])) { $post_params['content_type'] = 'product'; unset($post_params['is_shop']); } if (!isset($post_params['content_type']) and !isset($post_params['global'])) { $post_params['content_type'] = 'post'; } if (!isset($params['order_by']) and isset($params['order-by'])) { $params['orderby'] = $post_params['orderby'] = $params['order-by']; } if (isset($params['subtype_value'])) { $post_params['subtype_value'] = $params['subtype_value']; } $schema_org_item_type = false; $schema_org_item_type_tag = false; if (isset($post_params['content_type']) and $post_params['content_type'] == 'page') { $schema_org_item_type = 'WebPage'; } else { if (isset($post_params['content_type']) and $post_params['content_type'] == 'post') { if (isset($post_params['subtype']) and $post_params['subtype'] != $post_params['content_type']) { $schema_org_item_type = $post_params['subtype']; } else { $schema_org_item_type = 'Article'; } } } if ($schema_org_item_type != false) { $schema_org_item_type = ucfirst($schema_org_item_type); $schema_org_item_type_tag = ' itemtype="http://schema.org/' . $schema_org_item_type . '" '; $schema_org_item_type_tag = 'http://schema.org/' . $schema_org_item_type; } $ord_by = get_option('data-order-by', $params['id']); if ($ord_by != false and trim($ord_by) != '') { $post_params['orderby'] = $ord_by; } $date_format = get_option('date_format', 'website'); if ($date_format == false) { $date_format = "Y-m-d H:i:s"; } if (isset($params['title'])) { unset($post_params['title']); } $post_params['is_active'] = 1; $post_params['is_deleted'] = 0; if ((!isset($post_params['parent']) and !isset($post_params['category']) or isset($post_params['category']) and empty($post_params['category'])) and $cat_from_url != false and trim($cat_from_url) != '') { $post_params['category'] = $cat_from_url; } if (isset($params['content_type']) and $params['content_type'] == 'all') { unset($post_params['content_type']); unset($post_params['subtype']); } if (isset($params['search-parent'])) { $sub_content = get_content_children($params['search-parent']); if (!empty($sub_content)) { $post_params['ids'] = $sub_content; unset($post_params['parent']); } } if (isset($params['data-id'])) { unset($post_params['data-id']); } if ($posts_parent_related == false) { if (isset($post_params['category']) and is_string($post_params['category'])) { $sub_categories = array(); $sub_categories[] = $post_params['category']; $more = get_category_children($post_params['category']); if ($more != false and is_array($more)) { foreach ($more as $item_more_subcat) { $sub_categories[] = $item_more_subcat; } } //$post_params['category'] $post_params['category'] = $sub_categories; //$post_params['category'] = $post_params['category']; } else { if (isset($post_params['category']) and is_array($post_params['category']) and empty($post_params['category']) and isset($post_params['related']) and $post_params['related'] != false) { if (defined('CATEGORY_ID') and CATEGORY_ID > 0) { $post_params['category'] = CATEGORY_ID; } } } } if (defined('POST_ID') and isset($posts_parent_category) and $posts_parent_category != false or isset($post_params['related'])) { $post_params['exclude_ids'] = POST_ID; } if (!isset($params['order_by'])) { // if(isset($post_params['content_type']) and $post_params['content_type'] == 'page'){ // $post_params['order_by'] = 'position asc'; // } else { // // } $post_params['order_by'] = 'position desc'; } if (isset($params['search_in_fields']) and $params['search_in_fields'] != false) { $post_params['search_in_fields'] = $params['search_in_fields']; } $content = get_content($post_params); if ($posts_parent_related != false and empty($content) and isset($post_params['category'])) { unset($post_params['category']); $content = get_content($post_params); } $data = array(); if (!empty($content)) { foreach ($content as $item) { $iu = get_picture($item['id'], $for = 'post', $full = false); if ($iu != false) { $item['image'] = $iu; } else { $item['image'] = false; } if ($item['image'] != false) { $item['tn_image'] = thumbnail($item['image'], $tn[0], $tn[1]); } else { $item['tn_image'] = false; } $item['content'] = htmlspecialchars_decode($item['content']); if (isset($item['created_at']) and trim($item['created_at']) != '') { $item['created_at'] = date($date_format, strtotime($item['created_at'])); } if (isset($item['updated_at']) and trim($item['updated_at']) != '') { $item['updated_at'] = date($date_format, strtotime($item['updated_at'])); } $item['link'] = content_link($item['id']); $item['full_description'] = ''; if (!isset($item['description']) or $item['description'] == '') { if (isset($item['content']) and $item['content'] != '') { $item['description'] = character_limiter(strip_tags($item['content']), $character_limit); $item['full_description'] = strip_tags($item['content']); } elseif (isset($item['content_body']) and $item['content_body'] != '') { $item['full_description'] = strip_tags($item['content']); $item['description'] = character_limiter(strip_tags($item['content_body']), $character_limit); } } else { $item['full_description'] = trim($item['description']); $item['description'] = character_limiter(strip_tags($item['description']), $character_limit); } if (isset($item['title']) and $item['title'] != '') { $item['full_title'] = $item['title']; $item['title'] = character_limiter($item['title'], $title_character_limit); } if (isset($post_params['content_type']) and $post_params['content_type'] == 'product') { $item['prices'] = get_custom_fields("field_type=price&for=content&for_id=" . $item['id']); } else { $item['prices'] = false; } if (isset($item['prices']) and is_array($item['prices']) and !empty($item['prices'])) { $vals2 = array_values($item['prices']); $val1 = array_shift($vals2); $item['price'] = $val1; } else { $item['price'] = false; } if (isset($show_fields) and is_array($show_fields) and !empty($show_fields)) { if (!in_array('title', $show_fields)) { $item['title'] = false; } if (!in_array('description', $show_fields)) { $item['description'] = false; } if (!in_array('created_at', $show_fields)) { $item['created_at'] = false; } if (!in_array('read_more', $show_fields)) { $item['read_more'] = false; } if (!in_array('thumbnail', $show_fields)) { $item['thumbnail'] = false; } } $data[] = $item; } } else { if (isset($params['is_shop'])) { print lnotif('Your products module is empty'); } elseif (isset($params['global'])) { print lnotif('Your content module is empty'); } else { print lnotif('Your posts module is empty'); } } $post_params_paging = $post_params; $post_params_paging['page_count'] = true; $cfg_data_hide_paging = get_option('data-hide-paging', $params['id']); if ($cfg_data_hide_paging === false) { if (isset($post_params['hide_paging']) and trim($post_params['hide_paging']) != 'false') { $post_params['hide-paging'] = $post_params['hide_paging']; unset($post_params['hide_paging']); } if (isset($post_params['hide-paging']) and trim($post_params['hide-paging']) != 'false') { $cfg_data_hide_paging = 'y'; unset($post_params['hide-paging']); } } if ($cfg_data_hide_paging != 'y') { $pages_of_posts = get_content($post_params_paging); $pages_count = intval($pages_of_posts); } else { $pages_count = 0; } $paging_links = false; if (intval($pages_count) > 1) { //$paging_links = mw()->content_manager->paging_links(false, $pages_count, $paging_param, $keyword_param = 'keyword'); } $read_more_text = get_option('data-read-more-text', $params['id']); $add_cart_text = get_option('data-add-to-cart-text', $params['id']); if ($add_cart_text == false or $add_cart_text == "Add to cart") { $add_cart_text = _e("Add to cart", true); } if (!isset($params['return'])) { $module_template = get_option('data-template', $params['id']); if ($module_template == false and isset($params['template'])) { $module_template = $params['template']; } if ($module_template != false) { if (strtolower($module_template) == 'none') { if (isset($params['template'])) { $module_template = $params['template']; } } $template_file = module_templates($config['module'], $module_template); } else { $template_file = module_templates($config['module'], 'default'); } if ($template_file == false) { $template_file = module_templates($config['module'], 'default'); } if (isset($template_file) and is_file($template_file) != false) { include $template_file; ?> <?php if (isset($params['ajax_paging']) or isset($params['ajax-paging'])) { ?> <script type="text/javascript"> $(document).ready(function () { mw.$('#<?php print $params['id']; ?> ').find('a[data-page-number]').unbind('click'); mw.$('#<?php print $params['id']; ?> ').find('a[data-page-number]').click(function (e) { var pn = $(this).attr('data-page-number'); mw.$('#<?php print $params['id']; ?> ').attr('paging_param', 'current_page'); mw.$('#<?php print $params['id']; ?> ').attr('current_page', pn) mw.reload_module('#<?php print $params['id']; ?> '); return false; }); }); </script> <?php } ?> <?php if (isset($params['is_shop'])) { ?> <script type="text/javascript"> mw.require("shop.js"); </script> <?php } ?> <?php } else { print lnotif('No default template for ' . $config['module'] . ' is found'); } } }
function widget($args, $instance) { // 输出显示在页面上 extract($args); $id = $instance['id']; $before_content = $instance['before_content']; $after_content = $instance['after_content']; ?> <?php if (is_category()) { ?> <?php $cat2 = get_query_var('cat'); $cat = get_category_root_id($cat2); $category = get_category($cat); ?> <?php if (get_category_children($cat) != "") { ?> <div class="widget_left widget_nav_menu"> <div class="widge_hd"> <span> <b><?php echo $category->name; ?> </b> </span> </div> <ul> <?php if (get_category_children($cat) != "") { wp_list_categories("child_of=" . $cat . "&depth=0&hide_empty=0&title_li="); } ?> </ul> </div> <?php } } ?> <?php if (is_single()) { ?> <?php $cat2 = get_query_var('cat'); $cat = get_category_root_id(the_category_ID(false)); $category = get_category($cat); ?> <?php if (get_category_children($cat) != "") { ?> <div class="widget_left widget_nav_menu"> <div class="widge_hd"> <span> <b><?php echo $category->name; ?> </b><p><?php echo $category->slug; ?> </p> </span> </div> <ul> <?php if (get_category_children($cat) != "") { wp_list_categories("child_of=" . $cat . "&depth=0&hide_empty=0&title_li="); } ?> </ul> </div> <?php } } ?> <?php if (is_page()) { ?> <?php global $wpdb; global $post; $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data['post_name']; $name = $slug; //page别名 $parent_id = get_post($post->post_parent, ARRAY_A); $parent_slug = $parent_id['post_name']; $parent_title = get_the_title($post->post_parent); $parent_link = get_page_link($post->post_parent); $childrensd = wp_list_pages("title_li=&child_of=" . $post->ID . "&echo=0&depth=1"); if ($childrensd != "" || $post->post_parent) { ?> <div class="widget_left widget_nav_menu"> <div class="widge_hd"> <span> <b><?php if ($post->post_parent) { echo $parent_title; } else { echo get_the_title(); } ?> </b><p><?php if ($post->post_parent) { echo $parent_slug; } else { echo $slug; } ?> </p> </span> </div> <?php if ($post->post_parent) { ?> <ul class="nav_left"> <?php $children = wp_list_pages("title_li=&child_of=" . $post->post_parent . "&echo=0&depth=1"); if ($children) { echo $children; } ?> </ul> <?php } else { ?> <ul class="nav_left"> <?php $children = wp_list_pages("title_li=&child_of=" . $post->ID . "&echo=0&depth=1"); if ($children) { echo $children; } ?> </ul> <?php } ?> </div> <?php } } }
</div> <?php } elseif (is_category()) { ?> <div class="page_top_in"> <?php $cat = get_category_root_id(the_category_ID(false)); $cat2 = get_query_var('cat'); $category2 = get_category($cat2); $category = get_category($cat); ?> <h3> <?php if (get_category_children($cat) != "") { echo $category->name . ' <a>' . $category->slug . ' </a>'; } else { echo $category2->name . ' <a>' . $category2->slug . ' </a>'; } ?> </a></h3> </div> <?php } ?> </div> <div id="page_muen_nav"> <b><?php if (get_option('mytheme_word_t11') == "") {
public static function PrintSubCategoryMenu() { if (is_category()) { global $cat; if (get_category_children($cat) != "") { echo "<div class=\"page-children article\"><ul>"; wp_list_categories('orderby=name&show_count=0&title_li=&child_of=' . $cat); echo "</ul>\r\n\t\t\t\t\t</div>"; } } }
function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $optiondates = 0, $optioncount = 0, $hide_empty = 1, $optionnone = FALSE, $selected = 0, $hide = 0) { global $wpdb, $wp_id, $siteurl, $cat; // if (($file == 'blah') || ($file == '')) $file = $siteurl . '/index.php'; if (!$selected) { $selected = $cat; } $sort_column = 'cat_' . $sort_column; $query = "\n SELECT cat_ID, cat_name, category_nicename,category_parent, category_description cat_description,\n COUNT({$wpdb->post2cat[$wp_id]}.post_id) AS cat_count,\n DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth\n FROM {$wpdb->categories[$wp_id]} LEFT JOIN {$wpdb->post2cat[$wp_id]} ON (cat_ID = category_id)\n LEFT JOIN {$wpdb->posts[$wp_id]} ON (ID = post_id)\n WHERE cat_ID > 0\n "; if ($hide) { $query .= " AND cat_ID != {$hide}"; $query .= get_category_children($hide, " AND cat_ID != "); } $query .= " GROUP BY cat_ID"; if (intval($hide_empty) == 1) { $query .= " HAVING cat_count > 0"; } $query .= " ORDER BY {$sort_column} {$sort_order}, post_date DESC"; $categories = $wpdb->get_results($query); echo "<select name='cat' class='postform'>\n"; if (intval($optionall) == 1) { $all = apply_filters('list_cats', $all); echo "\t<option value='all'>{$all}</option>\n"; } if (intval($optionnone) == 1) { echo "\t<option value='0'>None</option>\n"; } if ($categories) { foreach ($categories as $category) { $cat_name = apply_filters('list_cats', $category->cat_name); echo "\t<option value=\"" . $category->cat_ID . "\""; if ($category->cat_ID == $selected) { echo ' selected="selected"'; } echo '>'; echo stripslashes($cat_name); if (intval($optioncount) == 1) { echo ' (' . $category->cat_count . ')'; } if (intval($optiondates) == 1) { echo ' ' . $category->lastday . '/' . $category->lastmonth; } echo "</option>\n"; } } echo "</select>\n"; }
<p class="nocomments">This post is password protected. Enter the password to view comments.</p> <?php return; } } /* This variable is for alternating comment background */ $oddcomment = ''; ?> <!-- You can start editing here. --> <?php $in_subcategory_companies = false; foreach (explode("/", get_category_children(get_cat_id('Companies'))) as $child_category) { if (in_category($child_category)) { $in_subcategory_companies = true; } } ?> <?php if ($comments) { ?> <?php if (in_category(get_cat_id('Companies')) || $in_subcategory_companies) { ?> <h1 class="Smallbox"><?php comments_number('No Testimonials', 'One Testimonial', '% Testimonials');
function gridlock_dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $optiondates = 0, $optioncount = 0, $hide_empty = 1, $optionnone = FALSE, $selected = 0, $hide = 0) { global $wpdb; if ($file == 'blah' || $file == '') { $file = get_settings('home') . '/'; } if (!$selected) { $selected = $cat; } $sort_column = 'cat_' . $sort_column; $query = "\n\t\t\tSELECT cat_ID, cat_name, category_nicename,category_parent,\n\t\t\tCOUNT({$wpdb->post2cat}.post_id) AS cat_count,\n\t\t\tDAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth\n\t\t\tFROM {$wpdb->categories} LEFT JOIN {$wpdb->post2cat} ON (cat_ID = category_id)\n\t\t\tLEFT JOIN {$wpdb->posts} ON (ID = post_id)\n\t\t\tWHERE cat_ID > 0\n\t\t\t"; if ($hide) { $query .= " AND cat_ID != {$hide}"; $query .= get_category_children($hide, " AND cat_ID != "); } $query .= " GROUP BY cat_ID"; if (intval($hide_empty) == 1) { $query .= " HAVING cat_count > 0"; } $query .= " ORDER BY {$sort_column} {$sort_order}, post_date DESC"; $categories = $wpdb->get_results($query); if (intval($optionall) == 1) { $all = apply_filters('list_cats', $all); echo "\t<option value='0'>{$all}</option>\n"; } if (intval($optionnone) == 1) { echo "\t<option value='-1'>" . __('None') . "</option>\n"; } if ($categories) { foreach ($categories as $category) { $cat_name = apply_filters('list_cats', $category->cat_name, $category); echo "\t<option value=\"" . $category->cat_ID . "\""; if ($category->cat_ID == $selected) { echo ' selected="selected"'; } echo '>'; echo $cat_name; if (intval($optioncount) == 1) { echo ' (' . $category->cat_count . ')'; } if (intval($optiondates) == 1) { echo ' ' . $category->lastday . '/' . $category->lastmonth; } echo "</option>\n"; } } }
if ('' != $category_name) { if (stristr($category_name, '/')) { $category_name = explode('/', $category_name); if ($category_name[count($category_name) - 1]) { $category_name = $category_name[count($category_name) - 1]; // no trailing slash } else { $category_name = $category_name[count($category_name) - 2]; // there was a trailling slash } } $category_name = preg_replace('|[^a-z0-9-]|', '', $category_name); $tables = ", {$wpdb->post2cat[$wp_id]}, {$wpdb->categories[$wp_id]}"; $join = " LEFT JOIN {$wpdb->post2cat[$wp_id]} ON ({$wpdb->posts[$wp_id]}.ID = {$wpdb->post2cat[$wp_id]}.post_id) LEFT JOIN {$wpdb->categories[$wp_id]} ON ({$wpdb->post2cat[$wp_id]}.category_id = {$wpdb->categories[$wp_id]}.cat_ID) "; $whichcat = " AND (category_nicename = '{$category_name}') "; $whichcat .= get_category_children($cat, " OR category_id = "); $cat = $wpdb->get_var("SELECT cat_ID FROM {$wpdb->categories[$wp_id]} WHERE category_nicename = '{$category_name}'"); } // author stuff if (empty($author) || $author == 'all' || $author == '0') { $whichauthor = ''; } else { $author = '' . urldecode($author) . ''; $author = addslashes_gpc($author); if (stristr($author, '-')) { $eq = '!='; $andor = 'AND'; $author = explode('-', $author); $author = '' . intval($author[1]); } else { $eq = '=';
/** * Retrieve category children list separated before and after the term IDs. * * @since 1.2.0 * @deprecated 2.8.0 Use get_term_children() * @see get_term_children() * * @param int $id Category ID to retrieve children. * @param string $before Optional. Prepend before category term ID. * @param string $after Optional, default is empty string. Append after category term ID. * @param array $visited Optional. Category Term IDs that have already been added. * @return string */ function get_category_children($id, $before = '/', $after = '', $visited = array()) { _deprecated_function(__FUNCTION__, '2.8.0', 'get_term_children()'); if (0 == $id) { return ''; } $chain = ''; /** TODO: consult hierarchy */ $cat_ids = get_all_category_ids(); foreach ((array) $cat_ids as $cat_id) { if ($cat_id == $id) { continue; } $category = get_category($cat_id); if (is_wp_error($category)) { return $category; } if ($category->parent == $id && !in_array($category->term_id, $visited)) { $visited[] = $category->term_id; $chain .= $before . $category->term_id . $after; $chain .= get_category_children($category->term_id, $before, $after); } } return $chain; }
function &get_posts() { global $wpdb, $pagenow, $user_ID; do_action('pre_get_posts', array(&$this)); // Shorthand. $q = $this->query_vars; // First let's clear some variables $whichcat = ''; $whichauthor = ''; $whichpage = ''; $result = ''; $where = ''; $limits = ''; $distinct = ''; $join = ''; if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 ) $q['posts_per_page'] = get_settings('posts_per_page'); if ( !isset($q['what_to_show']) ) $q['what_to_show'] = get_settings('what_to_show'); if ( isset($q['showposts']) && $q['showposts'] ) { $q['showposts'] = (int) $q['showposts']; $q['posts_per_page'] = $q['showposts']; } if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) ) $q['posts_per_page'] = $q['posts_per_archive_page']; if ( !isset($q['nopaging']) ) { if ($q['posts_per_page'] == -1) { $q['nopaging'] = true; } else { $q['nopaging'] = false; } } if ( $this->is_feed ) { $q['posts_per_page'] = get_settings('posts_per_rss'); $q['what_to_show'] = 'posts'; } if (isset($q['page'])) { $q['page'] = trim($q['page'], '/'); $q['page'] = (int) $q['page']; $q['page'] = abs($q['page']); } $add_hours = intval(get_settings('gmt_offset')); $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours)); $wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)"; // If a month is specified in the querystring, load that month if ( (int) $q['m'] ) { $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); $where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4); if (strlen($q['m'])>5) $where .= ' AND MONTH(post_date)=' . substr($q['m'], 4, 2); if (strlen($q['m'])>7) $where .= ' AND DAYOFMONTH(post_date)=' . substr($q['m'], 6, 2); if (strlen($q['m'])>9) $where .= ' AND HOUR(post_date)=' . substr($q['m'], 8, 2); if (strlen($q['m'])>11) $where .= ' AND MINUTE(post_date)=' . substr($q['m'], 10, 2); if (strlen($q['m'])>13) $where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2); } if ( (int) $q['hour'] ) { $q['hour'] = '' . intval($q['hour']); $where .= " AND HOUR(post_date)='" . $q['hour'] . "'"; } if ( (int) $q['minute'] ) { $q['minute'] = '' . intval($q['minute']); $where .= " AND MINUTE(post_date)='" . $q['minute'] . "'"; } if ( (int) $q['second'] ) { $q['second'] = '' . intval($q['second']); $where .= " AND SECOND(post_date)='" . $q['second'] . "'"; } if ( (int) $q['year'] ) { $q['year'] = '' . intval($q['year']); $where .= " AND YEAR(post_date)='" . $q['year'] . "'"; } if ( (int) $q['monthnum'] ) { $q['monthnum'] = '' . intval($q['monthnum']); $where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'"; } if ( (int) $q['day'] ) { $q['day'] = '' . intval($q['day']); $where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'"; } // Compat. Map subpost to attachment. if ( '' != $q['subpost'] ) $q['attachment'] = $q['subpost']; if ( '' != $q['subpost_id'] ) $q['attachment_id'] = $q['subpost_id']; if ('' != $q['name']) { $q['name'] = sanitize_title($q['name']); $where .= " AND post_name = '" . $q['name'] . "'"; } else if ('' != $q['pagename']) { $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename']))); $page_paths = '/' . trim($q['pagename'], '/'); $q['pagename'] = sanitize_title(basename($page_paths)); $q['name'] = $q['pagename']; $page_paths = explode('/', $page_paths); foreach($page_paths as $pathdir) $page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); $all_page_ids = get_all_page_ids(); $reqpage = 0; if (is_array($all_page_ids)) { foreach ( $all_page_ids as $page_id ) { $page = get_page($page_id); if ( $page->fullpath == $page_path ) { $reqpage = $page_id; break; } } } $where .= " AND (ID = '$reqpage')"; } elseif ('' != $q['attachment']) { $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment']))); $attach_paths = '/' . trim($q['attachment'], '/'); $q['attachment'] = sanitize_title(basename($attach_paths)); $q['name'] = $q['attachment']; $where .= " AND post_name = '" . $q['attachment'] . "'"; } if ( (int) $q['w'] ) { $q['w'] = ''.intval($q['w']); $where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'"; } if ( intval($q['comments_popup']) ) $q['p'] = intval($q['comments_popup']); // If a attachment is requested by number, let it supercede any post number. if ( ($q['attachment_id'] != '') && (intval($q['attachment_id']) != 0) ) $q['p'] = (int) $q['attachment_id']; // If a post number is specified, load that post if (($q['p'] != '') && intval($q['p']) != 0) { $q['p'] = (int) $q['p']; $where = ' AND ID = ' . $q['p']; } if (($q['page_id'] != '') && (intval($q['page_id']) != 0)) { $q['page_id'] = intval($q['page_id']); $q['p'] = $q['page_id']; $where = ' AND ID = '.$q['page_id']; } // If a search pattern is specified, load the posts that match if (!empty($q['s'])) { $q['s'] = addslashes_gpc($q['s']); $search = ' AND ('; $q['s'] = preg_replace('/, +/', ' ', $q['s']); $q['s'] = str_replace(',', ' ', $q['s']); $q['s'] = str_replace('"', ' ', $q['s']); $q['s'] = trim($q['s']); if ($q['exact']) { $n = ''; } else { $n = '%'; } if (!$q['sentence']) { $s_array = explode(' ',$q['s']); $q['search_terms'] = $s_array; $search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))'; for ( $i = 1; $i < count($s_array); $i = $i + 1) { $search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))'; } $search .= ' OR (post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\')'; $search .= ')'; } else { $search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\'))'; } } // Category stuff if ((empty($q['cat'])) || ($q['cat'] == '0') || // Bypass cat checks if fetching specific posts ( $this->is_single || $this->is_page )) { $whichcat=''; } else { $q['cat'] = ''.urldecode($q['cat']).''; $q['cat'] = addslashes_gpc($q['cat']); if (stristr($q['cat'],'-')) { // Note: if we have a negative, we ignore all the positives. It must // always mean 'everything /except/ this one'. We should be able to do // multiple negatives but we don't :-( $eq = '!='; $andor = 'AND'; $q['cat'] = explode('-',$q['cat']); $q['cat'] = intval($q['cat'][1]); } else { $eq = '='; $andor = 'OR'; } $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) "; $cat_array = preg_split('/[,\s]+/', $q['cat']); $whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]); $whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' '); for ($i = 1; $i < (count($cat_array)); $i = $i + 1) { $whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]); $whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' '); } $whichcat .= ')'; if ($eq == '!=') { $q['cat'] = '-'.$q['cat']; // Put back the knowledge that we are excluding a category. } } // Category stuff for nice URIs global $cache_categories; if ('' != $q['category_name']) { $cat_paths = '/' . trim(urldecode($q['category_name']), '/'); $q['category_name'] = sanitize_title(basename($cat_paths)); $cat_paths = explode('/', $cat_paths); foreach($cat_paths as $pathdir) $cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); $all_cat_ids = get_all_category_ids(); $q['cat'] = 0; $partial_match = 0; foreach ( $all_cat_ids as $cat_id ) { $cat = get_category($cat_id); if ( $cat->fullpath == $cat_path ) { $q['cat'] = $cat_id; break; } elseif ( $cat->category_nicename == $q['category_name'] ) { $partial_match = $cat_id; } } //if we don't match the entire hierarchy fallback on just matching the nicename if (!$q['cat'] && $partial_match) { $q['cat'] = $partial_match; } $tables = ", $wpdb->post2cat, $wpdb->categories"; $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) "; $whichcat = " AND (category_id = '" . $q['cat'] . "'"; $whichcat .= get_category_children($q['cat'], " OR category_id = "); $whichcat .= ")"; } // Author/user stuff if ((empty($q['author'])) || ($q['author'] == '0')) { $whichauthor=''; } else { $q['author'] = ''.urldecode($q['author']).''; $q['author'] = addslashes_gpc($q['author']); if (stristr($q['author'], '-')) { $eq = '!='; $andor = 'AND'; $q['author'] = explode('-', $q['author']); $q['author'] = ''.intval($q['author'][1]); } else { $eq = '='; $andor = 'OR'; } $author_array = preg_split('/[,\s]+/', $q['author']); $whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]); for ($i = 1; $i < (count($author_array)); $i = $i + 1) { $whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]); } $whichauthor .= ')'; } // Author stuff for nice URIs if ('' != $q['author_name']) { if (stristr($q['author_name'],'/')) { $q['author_name'] = explode('/',$q['author_name']); if ($q['author_name'][count($q['author_name'])-1]) { $q['author_name'] = $q['author_name'][count($q['author_name'])-1];#no trailing slash } else { $q['author_name'] = $q['author_name'][count($q['author_name'])-2];#there was a trailling slash } } $q['author_name'] = sanitize_title($q['author_name']); $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'"); $whichauthor .= ' AND (post_author = '.intval($q['author']).')'; } $where .= $search.$whichcat.$whichauthor; if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) { $q['order']='DESC'; } // Order by if (empty($q['orderby'])) { $q['orderby']='date '.$q['order']; } else { // Used to filter values $allowed_keys = array('author', 'date', 'category', 'title', 'modified'); $q['orderby'] = urldecode($q['orderby']); $q['orderby'] = addslashes_gpc($q['orderby']); $orderby_array = explode(' ',$q['orderby']); if (!in_array($orderby_array[0],$allowed_keys)) { $orderby_array[0] = 'date'; } $q['orderby'] = $orderby_array[0].' '.$q['order']; if (count($orderby_array)>1) { for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) { // Only allow certain values for safety if (in_array($orderby_array[$i],$allowed_keys)) { $q['orderby'] .= ',post_'.$orderby_array[$i].' '.$q['order']; } } } } $now = gmdate('Y-m-d H:i:59'); //only select past-dated posts, except if a logged in user is viewing a single: then, if they //can edit the post, we let them through if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) { $where .= " AND post_date_gmt <= '$now'"; $distinct = 'DISTINCT'; } if ( $this->is_attachment ) { $where .= " AND (post_status = 'attachment')"; } elseif ($this->is_page) { $where .= " AND (post_status = 'static')"; } elseif ($this->is_single) { $where .= " AND (post_status != 'static')"; } else { $where .= " AND (post_status = 'publish'"; if (isset($user_ID) && ('' != intval($user_ID))) $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')"; else $where .= ')'; } if (! $this->is_attachment ) $where .= " AND post_status != 'attachment'"; // Apply filters on where and join prior to paging so that any // manipulations to them are reflected in the paging by day queries. $where = apply_filters('posts_where', $where); $join = apply_filters('posts_join', $join); // Paging if (empty($q['nopaging']) && ! $this->is_single && ! $this->is_page) { $page = abs(intval($q['paged'])); if (empty($page)) { $page = 1; } if (($q['what_to_show'] == 'posts')) { $q['offset'] = abs(intval($q['offset'])); if ( empty($q['offset']) ) { $pgstrt = ''; $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', '; $limits = 'LIMIT '.$pgstrt.$q['posts_per_page']; } else { // we're ignoring $page and using 'offset' $pgstrt = $q['offset'] . ', '; $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } } elseif ($q['what_to_show'] == 'days') { $startrow = $q['posts_per_page'] * (intval($page)-1); $start_date = $wpdb->get_var("SELECT max(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $startrow,1"); $endrow = $startrow + $q['posts_per_page'] - 1; $end_date = $wpdb->get_var("SELECT min(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $endrow,1"); if ($page > 1) { $where .= " AND post_date >= '$end_date' AND post_date <= '$start_date'"; } else { $where .= " AND post_date >= '$end_date'"; } } } // Apply post-paging filters on where and join. Only plugins that // manipulate paging queries should use these hooks. $where = apply_filters('posts_where_paged', $where); $groupby = " $wpdb->posts.ID "; $groupby = apply_filters('posts_groupby', $groupby); $join = apply_filters('posts_join_paged', $join); $orderby = "post_" . $q['orderby']; $orderby = apply_filters('posts_orderby', $orderby); $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits"; $this->request = apply_filters('posts_request', $request); $this->posts = $wpdb->get_results($this->request); // Check post status to determine if post should be displayed. if ( !empty($this->posts) && $this->is_single ) { $status = get_post_status($this->posts[0]); if ( ('publish' != $status) && ('static' != $status) ) { if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) { // User must be logged in to view unpublished posts. $this->posts = array(); } else { if ('draft' == $status) { // User must have edit permissions on the draft to preview. if (! current_user_can('edit_post', $this->posts[0]->ID)) { $this->posts = array(); } else { $this->is_preview = true; $this->posts[0]->post_date = current_time('mysql'); } } else { if (! current_user_can('read_post', $this->posts[0]->ID)) $this->posts = array(); } } } else { if (mysql2date('U', $this->posts[0]->post_date_gmt) > mysql2date('U', $now)) { //it's future dated $this->is_preview = true; if (!current_user_can('edit_post', $this->posts[0]->ID)) { $this->posts = array ( ); } } } } update_post_caches($this->posts); $this->posts = apply_filters('the_posts', $this->posts); $this->post_count = count($this->posts); if ($this->post_count > 0) { $this->post = $this->posts[0]; } // Save any changes made to the query vars. $this->query_vars = $q; return $this->posts; }
function _b_wp_contents_show($options, $wp_num = "") { $no_posts = empty($options[0]) ? 10 : $options[0]; $tpl_file = empty($options[1]) ? 'wp_contents.html' : $options[1]; $category = empty($options[2]) ? "all" : intval($options[2]); $GLOBALS['dateformat'] = get_settings('date_format'); $GLOBALS['timeformat'] = get_settings('time_format'); $_criteria = new CriteriaCompo(new Criteria('post_status', 'publish')); $_criteria->add(new Criteria('post_date', current_time('mysql'), '<=')); if (empty($category) || $category == 'all' || $category == '0') { $_joinCriteria = null; } else { $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id'); $_wCriteria =& new CriteriaCompo(); $_wCriteria->add(new Criteria('category_id', intCriteriaVal($category)), 'OR'); $_catc = trim(get_category_children($category, '', ' ')); if ($_catc !== "") { $_catc_array = explode(' ', $_catc); for ($_j = 0; $_j < count($_catc_array); $_j++) { $_wCriteria->add(new Criteria('category_id', intCriteriaVal($_catc_array[$_j])), 'OR'); } } $_criteria->add($_wCriteria); } $_criteria->setGroupBy(wp_table('posts') . '.ID'); $_criteria->setSort('post_date'); $_criteria->setOrder('DESC'); $_criteria->setLimit($no_posts); $_criteria->setStart(0); $postHandler =& wp_handler('Post'); $postObjects =& $postHandler->getObjects($_criteria, false, '', 'DISTINCT', $_joinCriteria); // echo $postHandler->getLastSQL(); $lposts = array(); foreach ($postObjects as $postObject) { $lposts[] =& $postObject->exportWpObject(); } if ($lposts) { // Get the categories for all the posts $_post_id_list = array(); foreach ($lposts as $post) { $_post_id_list[] = $post->ID; $GLOBALS['category_cache'][wp_id()][$post->ID] = array(); } $_post_id_list = implode(',', $_post_id_list); $_post_id_criteria =& new Criteria('post_id', '(' . $_post_id_list . ')', 'IN'); $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id'); $_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID')); $postObjects =& $postHandler->getObjects($_post_id_criteria, false, 'ID, category_id, cat_name, category_nicename, category_description, category_parent', true, $_joinCriteria); foreach ($postObjects as $postObject) { $_cat->ID = $postObject->getVar('ID'); $_cat->category_id = $postObject->getExtraVar('category_id'); $_cat->cat_name = $postObject->getExtraVar('cat_name'); $_cat->category_nicename = $postObject->getExtraVar('category_nicename'); $_cat->category_description = $postObject->getExtraVar('category_description'); $_cat->category_parent = $postObject->getExtraVar('category_parent'); $GLOBALS['category_cache'][wp_id()][$postObject->getVar('ID')][] =& $_cat; unset($_cat); } // Do the same for comment numbers $_post_id_criteria =& new Criteria('comment_post_ID', '(' . $_post_id_list . ')', 'IN'); $_criteria =& new CriteriaCompo(new Criteria('post_status', 'publish')); $_criteria->add(new Criteria('comment_approved', '1 ')); $_criteria->add($_post_id_criteria); $_criteria->setGroupBy('ID'); $_joinCriteria =& new XoopsJoinCriteria(wp_table('comments'), 'ID', 'comment_post_ID'); $postObjects =& $postHandler->getObjects($_criteria, false, 'ID, COUNT( comment_ID ) AS ccount', false, $_joinCriteria); foreach ($postObjects as $postObject) { $GLOBALS['comment_count_cache'][wp_id()]['' . $postObject->getVar('ID')] = $postObject->getExtraVar('ccount'); } // Get post-meta info if ($meta_list = $GLOBALS['wpdb']->get_results('SELECT post_id, meta_key, meta_value FROM ' . wp_table('postmeta') . ' WHERE post_id IN(' . $_post_id_list . ') ORDER BY post_id, meta_key', ARRAY_A)) { // Change from flat structure to hierarchical: $GLOBALS['post_meta_cache'][wp_id()] = array(); foreach ($meta_list as $metarow) { $mpid = $metarow['post_id']; $mkey = $metarow['meta_key']; $mval = $metarow['meta_value']; // Force subkeys to be array type: if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid])) { $GLOBALS['post_meta_cache'][wp_id()][$mpid] = array(); } if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"])) { $GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"] = array(); } // Add a value to the current pid/key: $GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"][] = $mval; } } } $blog = 1; $block = array(); $block['use_theme_template'] = get_xoops_option(wp_mod(), 'use_theme_template'); $block['style'] = block_style_get(false); $block['divid'] = 'wpBlockContent' . $wp_num; $block['template_content'] = ""; $i = 0; $GLOBALS['previousday'] = 0; foreach ($lposts as $post) { $GLOBALS['post'] = $post; if ($block['use_theme_template'] == 0) { $content = array(); start_wp(); $content['date'] = the_date($GLOBALS['dateformat'], '', '', false); $content['time'] = the_time('', false); $content['title'] = the_title('', '', false); $content['permlink'] = get_permalink(); $content['author'] = the_author_posts_link('', false); $content['category'] = the_category('', '', false); $content['body'] = the_content(_WP_TPL_MORE, 0, '', false); $content['linkpage'] = link_pages('<br />Pages: ', '<br />', 'number', 'next page', 'previous page', '%', '', false); if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 0) { $content['comments'] = comments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false); } else { $content['comments'] = xcomments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false); $content['comments'] .= " | "; $content['comments'] .= comments_popup_link(_WP_TPL_TRACKBACK0, _WP_TPL_TRACKBACK1, _WP_TPL_TRACKBACKS, '', 'Trackback Off', false); } $content['trackback'] = trackback_rdf(0, false); $block['contents'][] = $content; } else { ob_start(); include get_custom_path('content_block-template.php'); $block['template_content'] .= ob_get_contents(); ob_end_clean(); } } $_wpTpl =& new WordPresTpl('theme'); $_wpTpl->assign('block', $block); if (!$_wpTpl->tpl_exists($tpl_file)) { $tpl_file = 'wp_contents.html'; } $block['content'] = $_wpTpl->fetch($tpl_file); $GLOBALS['previousday'] = 0; $GLOBALS['day'] = 0; $GLOBALS['comment_count_cache'][wp_id()] = array(); return $block; }
<div id="secondary"> <?php if (is_single() || is_category()) { ?> <?php global $cat; $category = get_the_category(); $category_ID = $cat; if (is_single()) { $category_ID = $category[0]->cat_ID; } $cats = get_category(get_category_root_id($category_ID)); if ($category_ID != get_category_root_id($category_ID) || get_category_children($category_ID)) { ?> <aside class="cat"> <?php echo '<h3>' . $cats->name . '</h3>'; ?> <ul> <?php wp_list_categories("child_of=" . get_category_root_id($category_ID) . "&depth=0&hide_empty=0&title_li=&use_desc_for_title=&orderby=id&show_count=0"); ?> </ul> </aside> <?php } ?> <?php } ?>
function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $optiondates = 0, $optioncount = 0, $hide_empty = 1, $optionnone=FALSE, $selected=0, $hide=0) { global $wpdb; if ( ($file == 'blah') || ($file == '') ) $file = get_settings('home') . '/'; if ( !$selected ) $selected=$cat; $sort_column = 'cat_'.$sort_column; $query = " SELECT cat_ID, cat_name, category_nicename,category_parent, COUNT($wpdb->post2cat.post_id) AS cat_count, DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (cat_ID = category_id) LEFT JOIN $wpdb->posts ON (ID = post_id) WHERE cat_ID > 0 "; if ( $hide ) { $query .= " AND cat_ID != $hide"; $query .= get_category_children($hide, " AND cat_ID != "); } $query .=" GROUP BY cat_ID"; if ( intval($hide_empty) == 1 ) $query .= " HAVING cat_count > 0"; $query .= " ORDER BY $sort_column $sort_order, post_date DESC"; $categories = $wpdb->get_results($query); echo "<select name='cat' class='postform'>\n"; if ( intval($optionall) == 1 ) { $all = apply_filters('list_cats', $all); echo "\t<option value='0'>$all</option>\n"; } if ( intval($optionnone) == 1 ) echo "\t<option value='-1'>".__('None')."</option>\n"; if ( $categories ) { foreach ( $categories as $category ) { $cat_name = apply_filters('list_cats', $category->cat_name, $category); echo "\t<option value=\"".$category->cat_ID."\""; if ( $category->cat_ID == $selected ) echo ' selected="selected"'; echo '>'; echo $cat_name; if ( intval($optioncount) == 1 ) echo ' ('.$category->cat_count.')'; if ( intval($optiondates) == 1 ) echo ' '.$category->lastday.'/'.$category->lastmonth; echo "</option>\n"; } } echo "</select>\n"; }
<!-- koalabo-blogbottom --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0513626599276208" data-ad-slot="1496367523" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <?php //親カテゴリID $parentID = 14; //子カテゴリIDを全て取得し、配列に入れる $catChildren = get_category_children($parentID); $catIDs = explode('/', $catChildren); array_shift($catIDs); sort($catIDs); $html = ''; $html .= '<form class="controls" id="Filters">'; $html .= '<fieldset class="fil_cat">'; for ($i = 0; $i < count($catIDs); $i++) { $cats = get_category($catIDs[$i]); $catsslug = $cats->slug; $catsname = $cats->name; $catsparent = $cats->parent; $catscount = $cats->count; if ($catsparent == $parentID) { if ($catscount != 0) { $html .= '<button class="' . $catsslug . 'button filter" data-filter=".' . $catsslug . '">' . $catsname . '</button>';
/** * The Template for displaying all single posts * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ get_header(); ?> <div id="secondary" class="widget-area widget-top" role="complementary"> <ul class="category-list"> <?php $this_category = get_the_category()[0]; if (get_category_children($this_category->cat_ID)) { $parent = $this_category->cat_ID; } else { $parent = $this_category->parent; } $args = array('orderby' => 'id', 'order' => 'asc', 'hide_empty' => 0, 'title_li' => '', 'include' => $parent); $child_args = array('orderby' => 'id', 'order' => 'asc', 'hide_empty' => 0, 'title_li' => '', 'child_of' => $parent); wp_list_categories($args); wp_list_categories($child_args); ?> </ul> </div> <div id="primary" class="site-content content-bottom"> <div id="content" role="main">
function &get_posts() { global $wpdb, $pagenow, $user_ID; do_action_ref_array('pre_get_posts', array(&$this)); // Shorthand. $q =& $this->query_vars; $q = $this->fill_query_vars($q); // First let's clear some variables $distinct = ''; $whichcat = ''; $whichauthor = ''; $whichpage = ''; $result = ''; $where = ''; $limits = ''; $join = ''; $search = ''; $groupby = ''; if (!isset($q['post_type'])) { $q['post_type'] = 'post'; } $post_type = $q['post_type']; if (!isset($q['posts_per_page']) || $q['posts_per_page'] == 0) { $q['posts_per_page'] = get_option('posts_per_page'); } if (isset($q['showposts']) && $q['showposts']) { $q['showposts'] = (int) $q['showposts']; $q['posts_per_page'] = $q['showposts']; } if (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0 && ($this->is_archive || $this->is_search)) { $q['posts_per_page'] = $q['posts_per_archive_page']; } if (!isset($q['nopaging'])) { if ($q['posts_per_page'] == -1) { $q['nopaging'] = true; } else { $q['nopaging'] = false; } } if ($this->is_feed) { $q['posts_per_page'] = get_option('posts_per_rss'); $q['nopaging'] = false; } $q['posts_per_page'] = (int) $q['posts_per_page']; if ($q['posts_per_page'] < -1) { $q['posts_per_page'] = abs($q['posts_per_page']); } else { if ($q['posts_per_page'] == 0) { $q['posts_per_page'] = 1; } } if ($this->is_home && (empty($this->query) || $q['preview'] == 'true') && 'page' == get_option('show_on_front') && get_option('page_on_front')) { $this->is_page = true; $this->is_home = false; $q['page_id'] = get_option('page_on_front'); } if (isset($q['page'])) { $q['page'] = trim($q['page'], '/'); $q['page'] = (int) $q['page']; $q['page'] = abs($q['page']); } $add_hours = intval(get_option('gmt_offset')); $add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours)); $wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)"; // If a month is specified in the querystring, load that month if ((int) $q['m']) { $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); $where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4); if (strlen($q['m']) > 5) { $where .= ' AND MONTH(post_date)=' . substr($q['m'], 4, 2); } if (strlen($q['m']) > 7) { $where .= ' AND DAYOFMONTH(post_date)=' . substr($q['m'], 6, 2); } if (strlen($q['m']) > 9) { $where .= ' AND HOUR(post_date)=' . substr($q['m'], 8, 2); } if (strlen($q['m']) > 11) { $where .= ' AND MINUTE(post_date)=' . substr($q['m'], 10, 2); } if (strlen($q['m']) > 13) { $where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2); } } if ((int) $q['hour']) { $q['hour'] = '' . intval($q['hour']); $where .= " AND HOUR(post_date)='" . $q['hour'] . "'"; } if ((int) $q['minute']) { $q['minute'] = '' . intval($q['minute']); $where .= " AND MINUTE(post_date)='" . $q['minute'] . "'"; } if ((int) $q['second']) { $q['second'] = '' . intval($q['second']); $where .= " AND SECOND(post_date)='" . $q['second'] . "'"; } if ((int) $q['year']) { $q['year'] = '' . intval($q['year']); $where .= " AND YEAR(post_date)='" . $q['year'] . "'"; } if ((int) $q['monthnum']) { $q['monthnum'] = '' . intval($q['monthnum']); $where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'"; } if ((int) $q['day']) { $q['day'] = '' . intval($q['day']); $where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'"; } // Compat. Map subpost to attachment. if ('' != $q['subpost']) { $q['attachment'] = $q['subpost']; } if ('' != $q['subpost_id']) { $q['attachment_id'] = $q['subpost_id']; } if ('' != $q['name']) { $q['name'] = sanitize_title($q['name']); $where .= " AND post_name = '" . $q['name'] . "'"; } else { if ('' != $q['pagename']) { $reqpage = get_page_by_path($q['pagename']); if (!empty($reqpage)) { $reqpage = $reqpage->ID; } else { $reqpage = 0; } if ('page' == get_option('show_on_front') && $reqpage == get_option('page_for_posts')) { $this->is_singular = false; $this->is_page = false; $this->is_home = true; $this->is_posts_page = true; } else { $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename']))); $page_paths = '/' . trim($q['pagename'], '/'); $q['pagename'] = sanitize_title(basename($page_paths)); $q['name'] = $q['pagename']; $where .= " AND (ID = '{$reqpage}')"; } } elseif ('' != $q['attachment']) { $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment']))); $attach_paths = '/' . trim($q['attachment'], '/'); $q['attachment'] = sanitize_title(basename($attach_paths)); $q['name'] = $q['attachment']; $where .= " AND post_name = '" . $q['attachment'] . "'"; } } if ((int) $q['w']) { $q['w'] = '' . intval($q['w']); $where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'"; } if (intval($q['comments_popup'])) { $q['p'] = intval($q['comments_popup']); } // If a attachment is requested by number, let it supercede any post number. if ($q['attachment_id'] != '' && intval($q['attachment_id']) != 0) { $q['p'] = (int) $q['attachment_id']; } // If a post number is specified, load that post if ($q['p'] != '' && intval($q['p']) != 0) { $q['p'] = (int) $q['p']; $where = ' AND ID = ' . $q['p']; } if ($q['page_id'] != '' && intval($q['page_id']) != 0) { $q['page_id'] = intval($q['page_id']); if ('page' == get_option('show_on_front') && $q['page_id'] == get_option('page_for_posts')) { $this->is_singular = false; $this->is_page = false; $this->is_home = true; $this->is_posts_page = true; } else { $q['p'] = $q['page_id']; $where = ' AND ID = ' . $q['page_id']; } } // If a search pattern is specified, load the posts that match if (!empty($q['s'])) { // added slashes screw with quote grouping when done early, so done later $q['s'] = stripslashes($q['s']); if ($q['sentence']) { $q['search_terms'] = array($q['s']); } else { preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q[s], $matches); $q['search_terms'] = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]); } $n = $q['exact'] ? '' : '%'; $searchand = ''; foreach ((array) $q['search_terms'] as $term) { $term = addslashes_gpc($term); $search .= "{$searchand}((post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}'))"; $searchand = ' AND '; } $term = addslashes_gpc($q['s']); if (!$q['sentence'] && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s']) { $search .= " OR (post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}')"; } if (!empty($search)) { $search = " AND ({$search}) "; } } // Category stuff if (empty($q['cat']) || $q['cat'] == '0' || ($this->is_single || $this->is_page)) { $whichcat = ''; } else { $q['cat'] = '' . urldecode($q['cat']) . ''; $q['cat'] = addslashes_gpc($q['cat']); $join = " LEFT JOIN {$wpdb->post2cat} ON ({$wpdb->posts}.ID = {$wpdb->post2cat}.post_id) "; $cat_array = preg_split('/[,\\s]+/', $q['cat']); $in_cats = $out_cats = $out_posts = ''; foreach ($cat_array as $cat) { $cat = intval($cat); $in = strstr($cat, '-') ? false : true; $cat = trim($cat, '-'); if ($in) { $in_cats .= "{$cat}, " . get_category_children($cat, '', ', '); } else { $out_cats .= "{$cat}, " . get_category_children($cat, '', ', '); } } $in_cats = substr($in_cats, 0, -2); $out_cats = substr($out_cats, 0, -2); if (strlen($in_cats) > 0) { $in_cats = " AND {$wpdb->post2cat}.category_id IN ({$in_cats})"; } if (strlen($out_cats) > 0) { $ids = $wpdb->get_col("SELECT post_id FROM {$wpdb->post2cat} WHERE {$wpdb->post2cat}.category_id IN ({$out_cats})"); if (is_array($ids) && count($ids > 0)) { foreach ($ids as $id) { $out_posts .= "{$id}, "; } $out_posts = substr($out_posts, 0, -2); } if (strlen($out_posts) > 0) { $out_cats = " AND {$wpdb->posts}.ID NOT IN ({$out_posts})"; } else { $out_cats = ''; } } $whichcat = $in_cats . $out_cats; $groupby = "{$wpdb->posts}.ID"; } // Category stuff for nice URLs if ('' != $q['category_name']) { $reqcat = get_category_by_path($q['category_name']); $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name']))); $cat_paths = '/' . trim($q['category_name'], '/'); $q['category_name'] = sanitize_title(basename($cat_paths)); $cat_paths = '/' . trim(urldecode($q['category_name']), '/'); $q['category_name'] = sanitize_title(basename($cat_paths)); $cat_paths = explode('/', $cat_paths); $cat_path = ''; foreach ((array) $cat_paths as $pathdir) { $cat_path .= ($pathdir != '' ? '/' : '') . sanitize_title($pathdir); } //if we don't match the entire hierarchy fallback on just matching the nicename if (empty($reqcat)) { $reqcat = get_category_by_path($q['category_name'], false); } if (!empty($reqcat)) { $reqcat = $reqcat->cat_ID; } else { $reqcat = 0; } $q['cat'] = $reqcat; $tables = ", {$wpdb->post2cat}, {$wpdb->categories}"; $join = " LEFT JOIN {$wpdb->post2cat} ON ({$wpdb->posts}.ID = {$wpdb->post2cat}.post_id) LEFT JOIN {$wpdb->categories} ON ({$wpdb->post2cat}.category_id = {$wpdb->categories}.cat_ID) "; $whichcat = " AND category_id IN ({$q['cat']}, "; $whichcat .= get_category_children($q['cat'], '', ', '); $whichcat = substr($whichcat, 0, -2); $whichcat .= ")"; $groupby = "{$wpdb->posts}.ID"; } // Author/user stuff if (empty($q['author']) || $q['author'] == '0') { $whichauthor = ''; } else { $q['author'] = '' . urldecode($q['author']) . ''; $q['author'] = addslashes_gpc($q['author']); if (stristr($q['author'], '-')) { $eq = '!='; $andor = 'AND'; $q['author'] = explode('-', $q['author']); $q['author'] = '' . intval($q['author'][1]); } else { $eq = '='; $andor = 'OR'; } $author_array = preg_split('/[,\\s]+/', $q['author']); $whichauthor .= ' AND (post_author ' . $eq . ' ' . intval($author_array[0]); for ($i = 1; $i < count($author_array); $i = $i + 1) { $whichauthor .= ' ' . $andor . ' post_author ' . $eq . ' ' . intval($author_array[$i]); } $whichauthor .= ')'; } // Author stuff for nice URLs if ('' != $q['author_name']) { if (stristr($q['author_name'], '/')) { $q['author_name'] = explode('/', $q['author_name']); if ($q['author_name'][count($q['author_name']) - 1]) { $q['author_name'] = $q['author_name'][count($q['author_name']) - 1]; #no trailing slash } else { $q['author_name'] = $q['author_name'][count($q['author_name']) - 2]; #there was a trailling slash } } $q['author_name'] = sanitize_title($q['author_name']); $q['author'] = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE user_nicename='" . $q['author_name'] . "'"); $whichauthor .= ' AND (post_author = ' . intval($q['author']) . ')'; } $where .= $search . $whichcat . $whichauthor; if (empty($q['order']) || strtoupper($q['order']) != 'ASC' && strtoupper($q['order']) != 'DESC') { $q['order'] = 'DESC'; } // Order by if (empty($q['orderby'])) { $q['orderby'] = 'post_date ' . $q['order']; } else { // Used to filter values $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order'); $q['orderby'] = urldecode($q['orderby']); $q['orderby'] = addslashes_gpc($q['orderby']); $orderby_array = explode(' ', $q['orderby']); if (empty($orderby_array)) { $orderby_array[] = $q['orderby']; } $q['orderby'] = ''; for ($i = 0; $i < count($orderby_array); $i++) { // Only allow certain values for safety $orderby = $orderby_array[$i]; if ('menu_order' != $orderby) { $orderby = 'post_' . $orderby; } if (in_array($orderby_array[$i], $allowed_keys)) { $q['orderby'] .= ($i == 0 ? '' : ',') . "{$orderby} {$q['order']}"; } } if (empty($q['orderby'])) { $q['orderby'] = 'post_date ' . $q['order']; } } if ($this->is_attachment) { $where .= " AND (post_type = 'attachment')"; } elseif ($this->is_page) { $where .= " AND (post_type = 'page')"; } elseif ($this->is_single) { $where .= " AND (post_type = 'post')"; } else { $where .= " AND (post_type = '{$post_type}' AND (post_status = 'publish'"; if (is_admin()) { $where .= " OR post_status = 'future' OR post_status = 'draft'"; } if (is_user_logged_in()) { if ('post' == $post_type) { $cap = 'read_private_posts'; } else { $cap = 'read_private_pages'; } if (current_user_can($cap)) { $where .= " OR post_status = 'private'"; } else { $where .= " OR post_author = {$user_ID} AND post_status = 'private'"; } } $where .= '))'; } // Apply filters on where and join prior to paging so that any // manipulations to them are reflected in the paging by day queries. $where = apply_filters('posts_where', $where); $join = apply_filters('posts_join', $join); // Paging if (empty($q['nopaging']) && !$this->is_singular) { $page = abs(intval($q['paged'])); if (empty($page)) { $page = 1; } if (empty($q['offset'])) { $pgstrt = ''; $pgstrt = (intval($page) - 1) * $q['posts_per_page'] . ', '; $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } else { // we're ignoring $page and using 'offset' $q['offset'] = abs(intval($q['offset'])); $pgstrt = $q['offset'] . ', '; $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } } // Apply post-paging filters on where and join. Only plugins that // manipulate paging queries should use these hooks. $where = apply_filters('posts_where_paged', $where); $groupby = apply_filters('posts_groupby', $groupby); if (!empty($groupby)) { $groupby = 'GROUP BY ' . $groupby; } $join = apply_filters('posts_join_paged', $join); $orderby = apply_filters('posts_orderby', $q['orderby']); $distinct = apply_filters('posts_distinct', $distinct); $fields = apply_filters('posts_fields', "{$wpdb->posts}.*"); $limits = apply_filters('post_limits', $limits); $found_rows = ''; if (!empty($limits)) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $request = " SELECT {$found_rows} {$distinct} {$fields} FROM {$wpdb->posts} {$join} WHERE 1=1 {$where} {$groupby} ORDER BY {$orderby} {$limits}"; $this->request = apply_filters('posts_request', $request); $this->posts = $wpdb->get_results($this->request); if (!empty($limits)) { $found_posts_query = apply_filters('found_posts_query', 'SELECT FOUND_ROWS()'); $this->found_posts = $wpdb->get_var($found_posts_query); $this->found_posts = apply_filters('found_posts', $this->found_posts); $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); } // Check post status to determine if post should be displayed. if (!empty($this->posts) && ($this->is_single || $this->is_page)) { $status = get_post_status($this->posts[0]); //$type = get_post_type($this->posts[0]); if ('publish' != $status) { if (!is_user_logged_in()) { // User must be logged in to view unpublished posts. $this->posts = array(); } else { if ('draft' == $status) { // User must have edit permissions on the draft to preview. if (!current_user_can('edit_post', $this->posts[0]->ID)) { $this->posts = array(); } else { $this->is_preview = true; $this->posts[0]->post_date = current_time('mysql'); } } else { if ('future' == $status) { $this->is_preview = true; if (!current_user_can('edit_post', $this->posts[0]->ID)) { $this->posts = array(); } } else { if (!current_user_can('read_post', $this->posts[0]->ID)) { $this->posts = array(); } } } } } } $this->posts = apply_filters('the_posts', $this->posts); update_post_caches($this->posts); $this->post_count = count($this->posts); if ($this->post_count > 0) { $this->post = $this->posts[0]; } return $this->posts; }
function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $optiondates = 0, $optioncount = 0, $hide_empty = 0, $optionnone = false, $selected = 0, $hide = 0, $hierarchical = true, $child_of = 0, $link = false, $level = 0) { global $wpdb, $wp_id, $siteurl, $cat; if (!$selected) { $selected = $cat; } $query = "\n SELECT cat_ID, cat_name, category_nicename,category_parent, category_description cat_description,\n COUNT({$wpdb->post2cat[$wp_id]}.post_id) AS cat_count,\n DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth\n FROM {$wpdb->categories[$wp_id]} LEFT JOIN {$wpdb->post2cat[$wp_id]} ON (cat_ID = category_id)\n LEFT JOIN {$wpdb->posts[$wp_id]} ON (ID = post_id)\n WHERE cat_ID > 0\n "; if ($hide) { $query .= " AND cat_ID != {$hide}"; $query .= get_category_children($hide, " AND cat_ID != "); } $query .= " GROUP BY cat_ID"; $query .= " ORDER BY cat_{$sort_column} {$sort_order}, post_date DESC"; $categories = $wpdb->get_results($query); if ($level == 0) { echo "<select name='cat' class='postform'>\n"; } if (intval($optionall) == 1) { $all = apply_filters('list_cats', $all); echo "\t<option value='all'>{$all}</option>\n"; } if (intval($optionnone) == 1) { echo "\t<option value='0'>None</option>\n"; } if ($categories) { foreach ($categories as $category) { if (!$hierarchical || $child_of == $category->category_parent) { if (intval($hide_empty) != 1 || $category->cat_count > 0) { $pad = str_repeat('– ', $level); $cat_name = apply_filters('list_cats', $pad . $category->cat_name); if ($link) { echo "\t<option value=\"" . get_category_link(false, $category->cat_ID, $category->category_nicename) . "\""; } else { echo "\t<option value=\"" . $category->cat_ID . "\""; } if ($category->cat_ID == $selected) { echo ' selected="selected"'; } echo '>'; echo $cat_name; if (intval($optioncount) == 1) { echo ' (' . $category->cat_count . ')'; } if (intval($optiondates) == 1) { echo ' ' . $category->lastday . '/' . $category->lastmonth; } echo "</option>\n"; } dropdown_cats(0, '', $sort_column, $sort_order, $optiondates, $optioncount, $hide_empty, $optionnone, $selected, $hide, $hierarchical = true, $category->cat_ID, $link, $level + 1); } } } if ($level == 0) { echo "</select>\n"; } }