示例#1
0
/**
 * Loads template for sidebar by $name.
 *
 * @author Justin Tadlock <*****@*****.**>
 * @author Cherry Team <*****@*****.**>
 * @since  4.0.0
 * @param  string $name
 */
function cherry_get_sidebar($name = null)
{
    do_action('get_sidebar', $name);
    // Core WordPress hook.
    $name = (string) $name;
    if (false === cherry_display_sidebar($name)) {
        return;
    }
    $_name = $name . '-' . cherry_template_base();
    $templates = array();
    $templates[] = "{$_name}.php";
    $templates[] = "sidebar/{$_name}.php";
    $templates[] = "{$name}.php";
    $templates[] = "sidebar/{$name}.php";
    $templates[] = 'sidebar.php';
    $templates[] = 'sidebar/sidebar.php';
    $template_path = locate_template($templates);
    if ('' !== $template_path) {
        load_template($template_path);
        return;
    }
    // Backward compat (when template not found).
    do_action('cherry_sidebar_before', $name);
    printf('<div %s>', cherry_get_attr('sidebar', $name));
    if (is_active_sidebar("{$name}")) {
        dynamic_sidebar("{$name}");
    } else {
        do_action('cherry_sidebar_empty', $name);
    }
    echo '</div>';
    do_action('cherry_sidebar_after', $name);
}
示例#2
0
/**
 * Output Entry Wrap.
 *
 * @since 4.0.0
 */
function cherry_entry_wrap_open()
{
    printf('<article %s>', cherry_get_attr('post'));
}
示例#3
0
/**
 * Outputs an HTML element's attributes.
 *
 * @since  4.0.0
 * @param  string $slug    The slug/ID of the element (e.g., 'sidebar').
 * @param  string $context A specific context (e.g., 'primary').
 */
function cherry_attr($slug, $context = '')
{
    echo cherry_get_attr($slug, $context);
}
示例#4
0
/**
 * Retrieve a post's taxonomy.
 *
 * @since  4.0.0
 * @param  array  $args Arguments.
 * @return string       Taxonomy.
 */
function cherry_get_the_post_taxonomy($args)
{
    $post_id = get_the_ID();
    $post_type = get_post_type($post_id);
    /**
     * Filter the arguments used to display a post taxonomy.
     *
     * @since 4.0.0
     * @param array  $args      Array of arguments.
     * @param int    $post_id   The post ID.
     * @param string $post_type The post type of the current post.
     */
    $defaults = apply_filters('cherry_get_the_post_taxonomy_defaults', array('name' => 'category', 'separator' => ', ', 'before' => '', 'after' => '', 'text' => '%s', 'wrap' => '<span %s>%s</span>'), $post_id, $post_type);
    $args = wp_parse_args($args, $defaults);
    /**
     * Returns an HTML string of taxonomy terms associated with a post and given taxonomy.
     *
     * @link https://codex.wordpress.org/Function_Reference/get_the_term_list
     */
    $terms = get_the_term_list($post_id, $args['name'], '', $args['separator'], '');
    if (is_wp_error($terms)) {
        return;
    }
    if (empty($terms)) {
        return;
    }
    $output = $args['before'];
    $output .= sprintf($args['wrap'], cherry_get_attr('entry-terms', $args['name']), sprintf($args['text'], $terms));
    $output .= $args['after'];
    $output = sprintf('<span class="entry-terms_wrap %1$s_wrap">%2$s</span>', sanitize_html_class($args['name']), $output);
    /**
     * Filters a post's taxonomy.
     *
     * @since  4.0.0
     * @return string $output Post's taxonomy.
     * @param  array  $args   Arguments.
     */
    return apply_filters('cherry_get_the_post_taxonomy', $output, $args);
}
示例#5
0
/**
 * Loads template for sidebar by $name.
 *
 * @author Justin Tadlock <*****@*****.**>
 * @author Cherry Team <*****@*****.**>
 * @since 4.0.0
 * @param string $name The name of the specialised sidebar.
 */
function cherry_get_sidebar($name = null)
{
    do_action('get_sidebar', $name);
    // Core WordPress hook.
    $name = (string) $name;
    if (false === cherry_display_sidebar($name)) {
        return;
    }
    $_name = $name . '-' . cherry_template_base();
    $templates = array();
    $templates[] = "{$_name}.php";
    $templates[] = "sidebar/{$_name}.php";
    $templates[] = "{$name}.php";
    $templates[] = "sidebar/{$name}.php";
    $templates[] = 'sidebar.php';
    $templates[] = 'sidebar/sidebar.php';
    $template_path = locate_template($templates);
    if ('' !== $template_path) {
        load_template($template_path);
        return;
    }
    /**
     * Fires before sidebar wrapper are opened.
     *
     * @since 4.0.0
     * @param string $name The name of the specialised sidebar.
     */
    do_action('cherry_sidebar_before', $name);
    printf('<div %s>', cherry_get_attr('sidebar', $name));
    if (is_active_sidebar("{$name}")) {
        dynamic_sidebar("{$name}");
    } else {
        /**
         * Fires if sidebar are empty.
         *
         * @since 4.0.0
         * @param string $name The name of the specialised sidebar.
         */
        do_action('cherry_sidebar_empty', $name);
    }
    echo '</div>';
    /**
     * Fires after sidebar wrapper are closed.
     *
     * @since 4.0.0
     * @param string $name The name of the specialised sidebar.
     */
    do_action('cherry_sidebar_after', $name);
}