本文整理汇总了PHP中Essential_Grid_Base::getPostsByCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP Essential_Grid_Base::getPostsByCategory方法的具体用法?PHP Essential_Grid_Base::getPostsByCategory怎么用?PHP Essential_Grid_Base::getPostsByCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Essential_Grid_Base
的用法示例。
在下文中一共展示了Essential_Grid_Base::getPostsByCategory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: output_search_result_ids
/**
* return search result ID's
* @since: 2.0
*/
public static function output_search_result_ids($search, $grid_id = 0)
{
$grid_id = intval($grid_id);
if ($search == '' || $grid_id === 0) {
return __('Not found', EG_TEXTDOMAIN);
}
$grid = new Essential_Grid();
if ($grid->init_by_id($grid_id) === false) {
return __('Not found', EG_TEXTDOMAIN);
}
$base = new Essential_Grid_Base();
$post_category = $grid->get_postparam_by_handle('post_category');
$post_types = $grid->get_postparam_by_handle('post_types');
$page_ids = explode(',', $grid->get_postparam_by_handle('selected_pages', '-1'));
$start_sortby = $grid->get_param_by_handle('sorting-order-by-start', 'none');
$start_sortby_type = $grid->get_param_by_handle('sorting-order-type', 'ASC');
$max_entries = $grid->get_maximum_entries($grid);
$cat_tax = Essential_Grid_Base::getCatAndTaxData($post_category);
$additional_query = $grid->get_postparam_by_handle('additional-query', '');
if ($additional_query !== '') {
$additional_query .= '&s=' . $search;
} else {
$additional_query .= 's=' . $search;
}
$additional_query = wp_parse_args($additional_query);
ob_start();
$posts = Essential_Grid_Base::getPostsByCategory($grid_id, $cat_tax['cats'], $post_types, $cat_tax['tax'], $page_ids, $start_sortby, $start_sortby_type, $max_entries, $additional_query, false);
ob_clean();
ob_end_clean();
if (empty($posts) || count($posts) === 0) {
return __('Not found', EG_TEXTDOMAIN);
}
$ids = array();
foreach ($posts as $post) {
$ids[] = $post['ID'];
}
return $ids;
}
示例2: output_filter_by_posts
/**
* Output Filter from post based
* @since 1.0.6
*/
public function output_filter_by_posts()
{
$base = new Essential_Grid_Base();
$nav = new Essential_Grid_Navigation();
$filter_allow = $base->getVar($this->grid_params, 'filter-arrows', 'single');
$filter_start = $grid->getVar($this->grid_params, 'filter-start', '');
$filter_all_text = $base->getVar($this->grid_params, 'filter-all-text', __('Filter - All', EG_TEXTDOMAIN));
$filter_dropdown_text = $base->getVar($this->grid_params, 'filter-dropdown-text', __('Filter Categories', EG_TEXTDOMAIN));
$show_count = $base->getVar($this->grid_params, 'filter-counter', 'off');
$nav->set_filter_text($filter_all_text);
$nav->set_dropdown_text($filter_dropdown_text);
$nav->set_show_count($show_count);
$start_sortby = $base->getVar($this->grid_params, 'sorting-order-by-start', 'none');
$start_sortby_type = $base->getVar($this->grid_params, 'sorting-order-type', 'ASC');
$post_category = $base->getVar($this->grid_postparams, 'post_category');
$post_types = $base->getVar($this->grid_postparams, 'post_types');
$page_ids = explode(',', $base->getVar($this->grid_postparams, 'selected_pages', '-1'));
$cat_relation = $base->getVar($this->grid_postparams, 'category-relation', 'OR');
$additional_query = $base->getVar($this->grid_postparams, 'additional-query', '');
if ($additional_query !== '') {
$additional_query = wp_parse_args($additional_query);
}
$cat_tax = Essential_Grid_Base::getCatAndTaxData($post_category);
$posts = Essential_Grid_Base::getPostsByCategory($this->grid_id, $cat_tax['cats'], $post_types, $cat_tax['tax'], $page_ids, $start_sortby, $start_sortby_type, -1, $additional_query, true, $cat_relation);
$nav_filters = array();
$taxes = array('post_tag');
if (!empty($cat_tax['tax'])) {
$taxes = explode(',', $cat_tax['tax']);
}
if (!empty($cat_tax['cats'])) {
$cats = explode(',', $cat_tax['cats']);
foreach ($cats as $key => $id) {
$cat = get_category($id);
if (is_object($cat)) {
$nav_filters[$id] = array('name' => $cat->cat_name, 'slug' => sanitize_key($cat->slug));
}
foreach ($taxes as $custom_tax) {
$term = get_term_by('id', $id, $custom_tax);
if (is_object($term)) {
$nav_filters[$id] = array('name' => $term->name, 'slug' => sanitize_key($term->slug));
}
}
}
asort($nav_filters);
}
$found_filter = array();
if (!empty($posts) && count($posts) > 0) {
foreach ($posts as $key => $post) {
//check if post should be visible or if its invisible on current grid settings
$is_visible = $this->check_if_visible($post['ID'], $this->grid_id);
if ($is_visible == false) {
continue;
}
// continue if invisible
$filters = array();
//$categories = get_the_category($post['ID']);
$categories = $base->get_custom_taxonomies_by_post_id($post['ID']);
//$tags = wp_get_post_terms($post['ID']);
$tags = get_the_tags($post['ID']);
if (!empty($categories)) {
foreach ($categories as $key => $category) {
$filters[$category->term_id] = array('name' => $category->name, 'slug' => sanitize_key($category->slug));
}
}
if (!empty($tags)) {
foreach ($tags as $key => $taxonomie) {
$filters[$taxonomie->term_id] = array('name' => $taxonomie->name, 'slug' => sanitize_key($taxonomie->slug));
}
}
$found_filter = $found_filter + $filters;
//these are the found filters, only show filter that the posts have
}
}
$remove_filter = array_diff_key($nav_filters, $found_filter);
//check if we have filter that no post has (comes through multilanguage)
if (!empty($remove_filter)) {
foreach ($remove_filter as $key => $rem) {
//we have, so remove them from the filter list before setting the filter list
unset($nav_filters[$key]);
}
}
$nav->set_filter($nav_filters);
//set filters $nav_filters $found_filter
$nav->set_filter_type($filter_allow);
$nav->set_filter_start_select($filter_start);
$nav->output_filter();
}