/**
     * Displays the output
     *
     * @param array $args
     * @param array $instance
     * @since Achievements (3.3)
     */
    public function widget($args, $instance)
    {
        $settings = $this->parse_settings($instance);
        $settings['post_id'] = absint(apply_filters('dpa_featured_achievement_post_id', $settings['post_id'], $instance, $this->id_base));
        // Get the specified achievement
        $achievement = get_posts(array('no_found_rows' => true, 'numberposts' => 1, 'p' => $settings['post_id'], 'post_status' => 'publish', 'post_type' => dpa_get_achievement_post_type(), 'suppress_filters' => false));
        // Bail if it doesn't exist
        if (empty($achievement)) {
            return;
        }
        $achievement = array_shift($achievement);
        $title = dpa_get_achievement_title($achievement->ID);
        echo $args['before_widget'];
        echo $args['before_title'] . $title . $args['after_title'];
        if (has_post_thumbnail($achievement->ID)) {
            ?>
			<a href="<?php 
            dpa_achievement_permalink($achievement->ID);
            ?>
"><?php 
            echo get_the_post_thumbnail($achievement->ID, 'thumbnail', array('alt' => $title));
            ?>
</a>
		<?php 
        }
        dpa_achievement_excerpt($settings['post_id']);
        echo $args['after_widget'];
    }
    /**
     * Displays the output
     *
     * @param array $args
     * @param array $instance
     * @since Achievements (2.0)
     */
    public function widget($args, $instance)
    {
        $settings = $this->parse_settings($instance);
        // Use these filters
        $settings['limit'] = absint(apply_filters('dpa_available_achievements_limit', $settings['limit'], $instance, $this->id_base));
        $settings['title'] = apply_filters('dpa_available_achievements_title', $settings['title'], $instance, $this->id_base);
        // WordPress filters widget_title through esc_html.
        $settings['title'] = apply_filters('widget_title', $settings['title'], $instance, $this->id_base);
        echo $args['before_widget'];
        if (!empty($settings['title'])) {
            echo $args['before_title'] . $settings['title'] . $args['after_title'];
        }
        // Get the posts
        $achievements = get_posts(array('ignore_sticky_posts' => true, 'no_found_rows' => true, 'numberposts' => $settings['limit'], 'post_status' => 'publish', 'post_type' => dpa_get_achievement_post_type(), 'suppress_filters' => false));
        // Bail if no posts
        if (empty($achievements)) {
            return;
        }
        echo '<ul>';
        foreach ($achievements as $post) {
            if (has_post_thumbnail($post->ID)) {
                ?>

				<li>
					<a href="<?php 
                dpa_achievement_permalink($post->ID);
                ?>
"><?php 
                echo get_the_post_thumbnail($post->ID, 'dpa-thumb', array('alt' => dpa_get_achievement_title($post->ID)));
                ?>
</a>
				</li>

			<?php 
            }
        }
        echo '</ul>';
        echo $args['after_widget'];
    }

	<a href="<?php 
dpa_achievement_permalink();
?>
">
		<?php 
if (has_post_thumbnail(dpa_get_the_achievement_id())) {
    ?>

			<?php 
    do_action('dpa_template_before_achievement_image');
    ?>

			<?php 
    echo the_post_thumbnail('post-thumbnail', array('class' => 'dpa-archive-achievements-image', 'alt' => dpa_get_achievement_title()));
    ?>

			<?php 
    do_action('dpa_template_after_achievement_image');
    ?>

		<?php 
}
?>


		<?php 
do_action('dpa_template_before_achievement_name');
?>
Beispiel #4
0
/**
 * Output the title of the achievement
 *
 * @param int $achievement_id Optional. Achievement ID
 * @see dpa_get_achievement_title()
 * @since Achievements (3.0)
 */
function dpa_achievement_title($achievement_id = 0)
{
    echo esc_html(dpa_get_achievement_title($achievement_id));
}
Beispiel #5
0
/**
 * Custom page title for Achievements pages
 *
 * @param string $title Optional. The title (not used).
 * @param string $sep Optional, default is '&raquo;'. How to separate each part within the page title.
 * @param string $seplocation Optional. Direction to display title, 'right'.
 * @return string The title
 * @since Achievements (3.0)
 */
function dpa_title($title = '', $sep = '&raquo;', $seplocation = '')
{
    $new_title = array();
    // Achievement archive
    if (dpa_is_achievement_archive()) {
        $new_title['text'] = dpa_get_achievement_archive_title();
        // Single achievement page
    } elseif (dpa_is_single_achievement()) {
        $new_title['text'] = dpa_get_achievement_title();
        $new_title['format'] = esc_attr__('Achievement: %s', 'achievements');
    }
    $new_title = apply_filters('dpa_raw_title_array', $new_title);
    $new_title = dpa_parse_args($new_title, array('format' => '%s', 'text' => $title), 'title');
    // Get the formatted raw title
    $new_title = sprintf($new_title['format'], $new_title['text']);
    $new_title = apply_filters('dpa_raw_title', $new_title, $sep, $seplocation);
    // Compare new title with original title
    if ($new_title === $title) {
        return $title;
    }
    // Temporary separator for accurate flipping, if necessary
    $t_sep = '%WP_TITILE_SEP%';
    $prefix = '';
    if (!empty($new_title)) {
        $prefix = " {$sep} ";
    }
    // Separate on right, so reverse the order
    if ('right' === $seplocation) {
        $new_title_array = explode($t_sep, $new_title);
        $new_title_array = array_reverse($new_title_array);
        $new_title = implode(" {$sep} ", $new_title_array) . $prefix;
        // Separate on left, do not reverse
    } else {
        $new_title_array = explode($t_sep, $new_title);
        $new_title = $prefix . implode(" {$sep} ", $new_title_array);
    }
    // Filter and return
    return apply_filters('dpa_title', $new_title, $sep, $seplocation);
}
/**
 * Reset main query vars and filter 'the_content' to output an Achievements template part as needed.
 *
 * @param string $template Optional
 * @since Achievements (3.0)
 */
function dpa_template_include_theme_compat($template = '')
{
    // Bail if a root template was already found. This prevents unintended recursive filtering of 'the_content'.
    if (dpa_is_template_included()) {
        return $template;
    }
    // Bail if shortcodes are unset somehow
    if (!is_a(achievements()->shortcodes, 'DPA_Shortcodes')) {
        return $template;
    }
    // Achievements archive
    if (dpa_is_achievement_archive()) {
        // Page exists where this archive should be
        $page = dpa_get_page_by_path(dpa_get_root_slug());
        // Should we replace the content...
        if (empty($page->post_content)) {
            $new_content = achievements()->shortcodes->display_achievements_index();
            // ...or use the existing page content?
        } else {
            $new_content = apply_filters('the_content', $page->post_content);
        }
        // Should we replace the title...
        if (empty($page->post_title)) {
            $new_title = dpa_get_achievement_archive_title();
            // ...or use the existing page title?
        } else {
            $new_title = apply_filters('the_title', $page->post_title);
        }
        dpa_theme_compat_reset_post(array('comment_status' => 'closed', 'ID' => !empty($page->ID) ? $page->ID : 0, 'is_archive' => true, 'post_author' => 0, 'post_content' => $new_content, 'post_date' => 0, 'post_status' => 'publish', 'post_title' => $new_title, 'post_type' => dpa_get_achievement_post_type()));
        // Single Achievement
    } elseif (dpa_is_single_achievement()) {
        dpa_theme_compat_reset_post(array('comment_status' => 'closed', 'ID' => dpa_get_achievement_id(), 'is_single' => true, 'post_author' => dpa_get_achievement_author_id(), 'post_content' => achievements()->shortcodes->display_achievement(array('id' => dpa_get_achievement_id())), 'post_date' => 0, 'post_status' => 'publish', 'post_title' => dpa_get_achievement_title(), 'post_type' => dpa_get_achievement_post_type()));
        // Single user's achievements template
    } elseif (dpa_is_single_user_achievements()) {
        dpa_theme_compat_reset_post(array('comment_status' => 'closed', 'ID' => 0, 'is_archive' => true, 'post_author' => 0, 'post_content' => achievements()->shortcodes->display_user_achievements(), 'post_date' => 0, 'post_status' => 'publish', 'post_title' => sprintf(_x("%s's achievements", 'possesive noun', 'achievements'), get_the_author_meta('display_name', dpa_get_displayed_user_id())), 'post_type' => dpa_get_achievement_post_type()));
    }
    /**
     * Bail if the template already matches an Achievements template. This includes
     * archive-* and single-* WordPress post_type matches (allowing themes to use the
     * expected format) as well as all other Achievements-specific template files.
     */
    if (dpa_is_template_included()) {
        return $template;
        /**
         * If we are relying on Achievements' built-in theme compatibility to load
         * the proper content, we need to intercept the_content, replace the
         * output, and display ours instead.
         *
         * To do this, we first remove all filters from 'the_content' and hook
         * our own function into it, which runs a series of checks to determine
         * the context, and then uses the built in shortcodes to output the
         * correct results from inside an output buffer.
         *
         * Uses dpa_get_theme_compat_templates() to provide fall-backs that
         * should be coded without superfluous mark-up and logic (prev/next
         * navigation, comments, date/time, etc...)
         * 
         * Hook into the 'dpa_get_achievements_template' to override the array of
         * possible templates, or 'dpa_achievements_template' to override the result.
         */
    } elseif (dpa_is_theme_compat_active()) {
        dpa_remove_all_filters('the_content');
        $template = dpa_get_theme_compat_templates();
    }
    return apply_filters('dpa_template_include_theme_compat', $template);
}