-1, 'post_type' => esc_attr( $post_type ) );
if ( $this->_is_woocommerce_activated() && 'product' == $post_type ) {
$args['meta_query'] = array( array(
'key' => '_visibility',
'value' => array( 'catalog', 'visible' ),
'compare' => 'IN'
) );
}
$data = get_posts( $args );
return $data;
} // End _get_posts_by_type()
/**
* Render the HTML for a list of the posts of a given post type.
* @access public
* @since 1.0.0
* @param string $post_type The post type to render HTML for.
* @return string Rendered HTML unordered list.
*/
public function render_posts_html ( $post_type, $args ) {
global $post;
if ( empty( $post_type ) ) return new WP_Error( 'empty_post_type', __( 'No post type specified. Please specify a post type token.', 'woothemes-archives' ) );
$html = '';
switch ( $post_type ) {
case 'page':
// Retrieve data about the post type.
$post_type_obj = get_post_type_object( $post_type );
$html .= '
' . "\n";
if ( isset( $post_type_obj->labels->name ) ) {
$html .= $args['before_title'] . $post_type_obj->labels->name . $args['after_title'] . "\n";
}
$html .= '
' . "\n";
$html .= wp_list_pages( 'depth=0&sort_column=menu_order&title_li=&echo=0' );
$html .= '
' . "\n" . '
';
break;
default:
$data = $this->_get_posts_by_type( $post_type );
if ( 0 < count( $data ) ) {
// Retrieve data about the post type.
$post_type_obj = get_post_type_object( $post_type );
$html .= '' . "\n";
if ( isset( $post_type_obj->labels->name ) ) {
$html .= $args['before_title'] . $post_type_obj->labels->name . $args['after_title'] . "\n";
}
$html .= '
' . "\n";
foreach ( $data as $i => $post ) {
setup_postdata( $post );
$html .= '- ' . get_the_title() . '
' . "\n";
}
wp_reset_postdata();
$html .= '
' . "\n" . '
';
}
break;
}
return $html;
} // End render_posts_html()
/**
* Render the HTML for a list of the terms of a given taxonomy.
* @access public
* @since 1.0.0
* @param string $taxonomy The taxonomy to render HTML for.
* @param array $args Arguments to adjust output.
* @return string Rendered HTML unordered list.
*/
public function render_terms_html ( $taxonomy, $args ) {
global $post;
if ( empty( $taxonomy ) ) return new WP_Error( 'empty_taxonomy', __( 'No taxonomy specified. Please specify a taxonomy token.', 'woothemes-archives' ) );
$html = '';
// Retrieve data about the taxonomy.
$tax_obj = get_taxonomy( $taxonomy );
$html .= '' . "\n";
$html .= $args['before_title'] . __( 'Recent Posts Per Category', 'woothemes-archives' ) . $args['after_title'] . "\n";
foreach ( $categories as $k => $v ) {
// Retrieve latest posts.
$posts = get_posts( array( 'cat' => intval( $v->cat_ID ), 'posts_per_page' => 10 ) );
$html .= '
' . $v->cat_name . '
' . "\n";
$html .= '
' . "\n";
if ( 0 < count( $posts ) && ! is_wp_error( $posts ) ) {
foreach ( $posts as $i => $post ) {
setup_postdata( $post );
$html .= '- ' . esc_html( get_the_title( get_the_ID() ) ) . ' - ' . __( 'Comments', 'woothemes-archives' ) . ' (' . get_comments_number( get_the_ID() ) . ')
' . "\n";
}
wp_reset_postdata();
}
$html .= '
' . "\n";
}
$html .= '
' . "\n";
return $html;
} // End render_posts_by_category_html()
/**
* Check if WooCommerce is activated.
* @access private
* @since 1.0.0
* @return boolean
*/
private function _is_woocommerce_activated() {
if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; }
} // End _is_woocommerce_activated()
} // End Class
?>