예제 #1
0
This "template" is used when you choose not to use a template.

If you want to create a new template, look at templates/template-example.php as an example.
*/
$options = array('before_title' => "{$domainprefix}before_title", 'after_title' => "{$domainprefix}after_title", 'show_excerpt' => "{$domainprefix}show_excerpt", 'excerpt_length' => "{$domainprefix}excerpt_length", 'before_post' => "{$domainprefix}before_post", 'after_post' => "{$domainprefix}after_post", 'before_related' => "{$domainprefix}before_related", 'after_related' => "{$domainprefix}after_related", 'no_results' => "{$domainprefix}no_results");
$optvals = array();
foreach (array_keys($options) as $option) {
    if (isset($args[$option])) {
        $optvals[$option] = stripslashes($args[$option]);
    } else {
        $optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
    }
}
extract($optvals);
if ($related_query->have_posts()) {
    while ($related_query->have_posts()) {
        $related_query->the_post();
        $output .= "{$before_title}<a href='" . get_permalink() . "' rel='bookmark' title='Permanent Link: " . preg_replace('/\\s*<br[ \\/]*>\\s*/i', ' ', get_the_title()) . "'>" . get_the_title() . "";
        if ($userdata->user_level >= 8 and $domain != 'rss') {
            $output .= ' <abbr title="' . sprintf(__('%f is the YARPP match score between the current entry and this related entry. You are seeing this value because you are logged in to WordPress as an administrator. It is not shown to regular visitors.', 'yarpp'), round(get_the_score(), 3)) . '">(' . round(get_the_score(), 3) . ')</abbr>';
        }
        $output .= '</a>';
        if ($show_excerpt) {
            $output .= $before_post . yarpp_excerpt(get_the_excerpt(), $excerpt_length) . $after_post;
        }
        $output .= $after_title . "\n";
    }
    $output = stripslashes(stripslashes($before_related)) . $output . stripslashes(stripslashes($after_related));
} else {
    $output = $no_results;
}
function yarpp_related($type, $args, $echo = true, $domain = 'website')
{
    global $wpdb, $post, $userdata;
    get_currentuserinfo();
    // set the "domain prefix", used for all the preferences.
    if ($domain == 'rss') {
        $domainprefix = 'rss_';
    } else {
        $domainprefix = '';
    }
    // get options
    // note the 2.1 change... the options array changed from what you might call a "list" to a "hash"... this changes the structure of the $args to something which is, in the long term, much more useful
    $options = array('before_related' => "{$domainprefix}before_related", 'after_related' => "{$domainprefix}after_related", 'before_title' => "{$domainprefix}before_title", 'after_title' => "{$domainprefix}after_title", 'show_excerpt' => "{$domainprefix}show_excerpt", 'excerpt_length' => "{$domainprefix}excerpt_length", 'before_post' => "{$domainprefix}before_post", 'after_post' => "{$domainprefix}after_post", 'no_results' => "{$domainprefix}no_results", 'promote_yarpp' => "{$domainprefix}promote_yarpp");
    $optvals = array();
    foreach (array_keys($options) as $option) {
        if (isset($args[$option])) {
            $optvals[$option] = stripslashes($args[$option]);
        } else {
            $optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
        }
    }
    extract($optvals);
    $sql = yarpp_sql($type, $args, true, $domain);
    $results = $wpdb->get_results($sql);
    $output = '';
    if ($results) {
        foreach ($results as $result) {
            $title = stripslashes(apply_filters('the_title', $result->post_title));
            $permalink = get_permalink($result->ID);
            $post_content = strip_tags(apply_filters_if_white('the_content', $result->post_content));
            //$post_content = stripslashes($post_content);
            $post_excerpt = strip_tags($result->post_excerpt);
            if ($post_excerpt == '') {
                $post_excerpt = $post_content;
            }
            //this is okay because it will be clipped later anyway.
            $output .= "{$before_title}<a href='{$permalink}' rel='bookmark' title='Permanent Link: {$title}'>{$title}";
            if ($userdata->user_level >= 8 and $domain != 'rss') {
                $output .= ' <abbr title="' . sprintf(__('%f is the YARPP match score between the current entry and this related entry. You are seeing this value because you are logged in to WordPress as an administrator. It is not shown to regular visitors.', 'yarpp'), round($result->score, 3)) . '">(' . round($result->score, 3) . ')</abbr>';
            }
            $output .= '</a>';
            if ($show_excerpt) {
                $output .= $before_post . yarpp_excerpt($post_excerpt, $excerpt_length) . $after_post;
            }
            $output .= $after_title;
        }
        $output = stripslashes(stripslashes($before_related)) . $output . stripslashes(stripslashes($after_related));
        if ($promote_yarpp) {
            $output .= "\n<p>" . __("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.", 'yarpp') . "</p>";
        }
    } else {
        $output = $no_results;
    }
    if ($echo) {
        echo $output;
    } else {
        return (!empty($output) ? "\n\n" : '') . $output;
    }
}
checkbox('promote_yarpp', __("Help promote Yet Another Related Posts Plugin?", 'yarpp') . " <a href='#' class='info'>" . __('more&gt;', 'yarpp') . "<span>" . sprintf(__("This option will add the code %s. Try turning it on, updating your options, and see the code in the code example to the right. These links and donations are greatly appreciated.", 'yarpp'), "<code>" . htmlspecialchars(__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.", 'yarpp')) . "</code>") . "</span></a>");
?>
		</table>

		<!-- Display options for RSS -->
		<h3><?php 
_e("Display options <small>for RSS</small>", 'yarpp');
?>
 <span style='color:red;'>NEW!</span></h3>
		
		<table class="form-table" style="margin-top: 0">
<?php 
// construct the demo code based on current preferences for RSS
$democode = stripslashes(yarpp_get_option('rss_before_related', true)) . "\n";
for ($i = 1; $i <= yarpp_get_option('rss_limit'); $i++) {
    $democode .= stripslashes(yarpp_get_option('rss_before_title', true)) . stripslashes(htmlspecialchars("<a href='" . __("RELATED TITLE", 'yarpp') . "{$i}'>" . __("RELATED TITLE", 'yarpp') . " {$i}</a>")) . (yarpp_get_option('rss_show_excerpt') ? "\r\t" . stripslashes(yarpp_get_option('rss_before_post', true)) . yarpp_excerpt(LOREMIPSUM, yarpp_get_option('rss_excerpt_length')) . stripslashes(yarpp_get_option('rss_before_post', true)) : '') . stripslashes(yarpp_get_option('rss_after_title', true)) . "\n";
}
$democode .= stripslashes(yarpp_get_option('rss_after_related', true));
if (yarpp_get_option('rss_promote_yarpp')) {
    $democode .= htmlspecialchars("\n<p>" . __("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.", 'yarpp') . "</p>");
}
checkbox('rss_display', __("Display related posts in feeds?", 'yarpp'), "<tr valign='top'><th colspan='3'>", ' onclick="javascript:do_rss_display();"');
checkbox('rss_excerpt_display', __("Display related posts in the descriptions?", 'yarpp') . " <a href='#' class='info'>" . __('more&gt;', 'yarpp') . "<span>" . __("This option displays the related posts in the RSS description fields, not just the content. If your feeds are set up to only display excerpts, however, only the description field is used, so this option is required for any display at all.", 'yarpp') . "</span></a>", "<tr name='rss_displayed' valign='top'>\n\t\t\t<th class='th-full' colspan='2' scope='row'>", '', '<td rowspan="10" style="border-left:8px white solid;"><b>' . __("RSS display code example", 'yarpp') . '</b><br /><small>' . __("(Update options to reload.)", 'yarpp') . '</small><br/>' . "<code><pre style='overflow:auto;width:350px;'>" . $democode . "</pre></code></td>");
?>
	<?php 
textbox('rss_limit', __('Maximum number of related posts:', 'yarpp'), 2, "<tr valign='top' name='rss_displayed'>\n\t\t\t<th scope='row'>");
?>
			<tr name='rss_displayed' valign='top'>
				<th><?php 
_e("Before / after related entries display:", 'yarpp');
?>