Пример #1
0
/**
 * The grid loop - a specific implementation of a custom loop.
 *
 * Outputs markup compatible with a Feature + Grid style layout.
 * All normal loop hooks present, except for `genesis_post_content`.
 *
 * The arguments can be filtered by the `genesis_grid_loop_args` filter.
 *
 * @since 1.5.0
 *
 * @uses genesis_custom_loop()   Do custom loop.
 * @uses genesis_standard_loop() Do standard loop.
 * @uses genesis_reset_loop()    Restores all default post loop output by rehooking all default functions.
 *
 * @global array $_genesis_loop_args Associative array for grid loop configuration.
 *
 * @param array $args Associative array for grid loop configuration.
 */
function genesis_grid_loop($args = array())
{
    //* Global vars
    global $_genesis_loop_args;
    //* Parse args
    $args = apply_filters('genesis_grid_loop_args', wp_parse_args($args, array('features' => 2, 'features_on_all' => false, 'feature_image_size' => 0, 'feature_image_class' => 'alignleft', 'feature_content_limit' => 0, 'grid_image_size' => 'thumbnail', 'grid_image_class' => 'alignleft', 'grid_content_limit' => 0, 'more' => __('Read more', 'genesis') . '…')));
    //* If user chose more features than posts per page, adjust features
    if (get_option('posts_per_page') < $args['features']) {
        $args['features'] = get_option('posts_per_page');
    }
    //* What page are we on?
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    //* Potentially remove features on page 2+
    if (!$args['features_on_all'] && $paged > 1) {
        $args['features'] = 0;
    }
    //* Set global loop args
    $_genesis_loop_args = $args;
    //* Remove some unnecessary stuff from the grid loop
    remove_action('genesis_before_post_title', 'genesis_do_post_format_image');
    remove_action('genesis_post_content', 'genesis_do_post_image');
    remove_action('genesis_post_content', 'genesis_do_post_content');
    remove_action('genesis_post_content', 'genesis_do_post_content_nav');
    remove_action('genesis_entry_header', 'genesis_do_post_format_image', 4);
    remove_action('genesis_entry_content', 'genesis_do_post_image', 8);
    remove_action('genesis_entry_content', 'genesis_do_post_content');
    remove_action('genesis_entry_content', 'genesis_do_post_content_nav', 12);
    remove_action('genesis_entry_content', 'genesis_do_post_permalink', 14);
    //* Custom loop output
    add_filter('post_class', 'genesis_grid_loop_post_class');
    add_action('genesis_post_content', 'genesis_grid_loop_content');
    add_action('genesis_entry_content', 'genesis_grid_loop_content');
    //* The loop
    genesis_standard_loop();
    //* Reset loops
    genesis_reset_loops();
    remove_filter('post_class', 'genesis_grid_loop_post_class');
    remove_action('genesis_post_content', 'genesis_grid_loop_content');
    remove_action('genesis_entry_content', 'genesis_grid_loop_content');
}
Пример #2
0
/**
 * The grid loop - a specific implementation of a custom loop.
 *
 * Outputs markup compatible with a Feature + Grid style layout.
 * All normal loop hooks present, except for genesis_post_content.
 *
 * The arguments can be filtered by the genesis_grid_loop_args filter.
 *
 * @since 1.5.0
 *
 * @uses g_ent() Pass entities through filter
 * @uses genesis_custom_loop() Do custom loop
 * @uses genesis_standard_loop() Do standard loop
 * @uses genesis_reset_loop() Restores all default post loop output by rehooking all default functions
 *
 * @global array $_genesis_loop_args Associative array for grid loop configuration
 * @global string $query_string Query string
 * @param array $args Associative array for grid loop configuration
 * @return null Returns early if posts_per_page is fewer than features
 */
function genesis_grid_loop($args = array())
{
    /** Global vars */
    global $_genesis_loop_args, $query_string;
    /** Parse args */
    $args = apply_filters('genesis_grid_loop_args', wp_parse_args($args, array('loop' => 'standard', 'features' => 2, 'features_on_all' => false, 'feature_image_size' => 0, 'feature_image_class' => 'alignleft post-image', 'feature_content_limit' => 0, 'grid_image_size' => 'thumbnail', 'grid_image_class' => 'alignleft post-image', 'grid_content_limit' => 0, 'more' => g_ent(__('Read more&hellip;', 'genesis')), 'posts_per_page' => get_option('posts_per_page'), 'paged' => get_query_var('paged') ? get_query_var('paged') : 1)));
    /** Error handler */
    if ($args['posts_per_page'] < $args['features']) {
        trigger_error(sprintf(__('You are using invalid arguments with the %s function.', 'genesis'), __FUNCTION__));
        return;
    }
    /** Potentially remove features on page 2+ */
    if (!$args['features_on_all'] && $args['paged'] > 1) {
        $args['features'] = 0;
    }
    /** Set global loop args */
    $_genesis_loop_args = wp_parse_args($args, $query_string);
    /** Remove some unnecessary stuff from the grid loop */
    remove_action('genesis_before_post_title', 'genesis_do_post_format_image');
    remove_action('genesis_post_content', 'genesis_do_post_image');
    remove_action('genesis_post_content', 'genesis_do_post_content');
    /** Custom loop output */
    add_filter('post_class', 'genesis_grid_loop_post_class');
    add_action('genesis_post_content', 'genesis_grid_loop_content');
    /** Set query args */
    $args = $_genesis_loop_args;
    if (isset($args['features']) && is_numeric($args['features'])) {
        unset($args['features']);
    }
    /** The loop */
    if ('custom' == $_genesis_loop_args['loop']) {
        genesis_custom_loop($args);
    } else {
        query_posts($args);
        genesis_standard_loop();
    }
    /** Reset loops */
    genesis_reset_loops();
    remove_filter('post_class', 'genesis_grid_loop_post_class');
    remove_action('genesis_post_content', 'genesis_grid_loop_content');
}
/**
 * Yet another custom loop function.
 * Outputs markup compatible with a Feature + Grid style layout.
 * All normal loop hooks present, except for genesis_post_content.
 *
 * @since 1.5
 */
function genesis_grid_loop($args = array())
{
    /** Global vars **/
    global $_genesis_loop_args;
    /** Parse args **/
    $args = apply_filters('genesis_grid_loop_args', wp_parse_args($args, array('loop' => 'standard', 'features' => 2, 'feature_image_size' => 0, 'feature_image_class' => 'alignleft post-image', 'feature_content_limit' => 0, 'grid_image_size' => 'thumbnail', 'grid_image_class' => 'alignleft post-image', 'grid_content_limit' => 0, 'more' => __('[Read more...]', 'genesis'), 'posts_per_page' => get_option('posts_per_page'), 'paged' => get_query_var('paged') ? get_query_var('paged') : 1)));
    /** Error handler **/
    if ($args['posts_per_page'] < $args['features']) {
        trigger_error(sprintf(__('You are using invalid arguments with the %s function.', 'genesis'), __FUNCTION__));
        return;
    }
    /** Don't show features on page 2+ **/
    if ($args['paged'] > 1) {
        $args['features'] = 0;
    }
    /** Set global loop args **/
    $_genesis_loop_args = $args;
    /** Remove some unnecessary stuff from the grid loop **/
    remove_action('genesis_before_post_title', 'genesis_do_post_format_image');
    remove_action('genesis_post_content', 'genesis_do_post_image');
    remove_action('genesis_post_content', 'genesis_do_post_content');
    /** Custom loop output **/
    add_filter('post_class', 'genesis_grid_loop_post_class');
    add_action('genesis_post_content', 'genesis_grid_loop_content');
    /** The loop **/
    if ($args['loop'] == 'custom') {
        genesis_custom_loop($args);
    } else {
        query_posts($args);
        genesis_standard_loop();
    }
    /** Reset loops **/
    genesis_reset_loops();
    remove_filter('post_class', 'genesis_grid_loop_post_class');
    remove_action('genesis_post_content', 'genesis_grid_loop_content');
}