Wrong format of post views count in wordpress - php

I print a line consisted of the post date and the number of views (use the plugin wp-PostViews). However, I get 26 [icon] 2016-01-09 [icon] views, instead of [icon] 2016-01-09 [icon] 26 views (wrong position of the number of views) as shown below:
Here are the source codes:
$time_string_published = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
$time_string_published = sprintf( $time_string_published,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date( 'Y-m-d' ) )
);
printf( '<span class="posted-on">%1$s</span><span class="views-link">%2$s</span>',
sprintf( '%2$s',
esc_url( get_permalink() ),
$time_string_published
),
sprintf('%1$s views', the_views())
);
The related css settings are:
.entry-meta .views-link:before {
display: inline-block;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font: normal 22px/1 'Genericons';
vertical-align: top;
}
.entry-meta .views-link:before { content: '\f403'; }
BTW, the following codes work correctly, displaying as [icon] 26 (the right position).
<span class="views-link">
<?php if(function_exists('the_views')) { echo the_views(); } ?>
</span>
Is it possiable that the plugin wp-PostViews (contains the function the_views()) is loaded after excuting the above codes?

I'm not sure about anyone else - but this seems a bit like overkill on trying to do this. Why not try:
$url = esc_url( get_permalink() );
$time = $time_string_published;
$views = the_views();
$out = <<<EOD
<span class="posted-on"><a href="$url"
rel="bookmark">$time</a></span><span class="views-link">$views</span>
EOD;
printf( "%s", $out );
The above does the same thing but is a bit clearer. Sorry! Thought I had it but I got it wrong originally. I've now corrected the generated code. So NOW I say - have you checked what $time_string_published is giving you?
BTW: If your echo of the_views() is giving you "ico 26 views" why not just do this:
$views = substr( the_views(), 4 );
To get the "26 views" part. It would then automatically have the "views" stuck on the end of it. Just an idea.
Update : 8:57pm
Here is the reworked code. It works for me.
<?php
$time_string_published = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
$time_string_published = sprintf( $time_string_published,
date( 'c', time() ),
date( 'Y-m-d', time() )
);
printf( '<span class="posted-on">%1$s</span><span class="views-link">%2$s</span>',
sprintf( '%2$s',
( get_permalink() ),
$time_string_published
),
sprintf('%1$s views', the_views())
);
$date1 = date('c', time() );
$date2 = date('Y-m-d', time() );
$time_string_published = "<time class='entry-date published' datetime='$date1'>$date2</time>";
$url = get_permalink();
$view = the_views();
$s = "<a href='$url' rel='bookmark'>$time_string_published</a>";
echo "<p><span class='posted-on'>$s</span> <span class='views-link'>$view views</span>";
function get_permalink()
{
return "http://www.google.com";
}
function the_views()
{
return 26;
}
?>
The output is:
2016-01-1226 views
2016-01-12 26 views
And the page source code is:
<span class="posted-on"><time class="entry-date published" datetime="2016-01-12T02:55:41+00:00">2016-01-12</time></span><span class="views-link">26 views</span><p><span class='posted-on'><a href='http://www.google.com' rel='bookmark'><time class='entry-date published' datetime='2016-01-12T02:55:41+00:00'>2016-01-12</time></a></span> <span class='views-link'>26 views</span>
Note that the second line has a space between the first SPAN and the second one. If you don't get the same output then there is something going on with either WordPress or some other part of the overall program. About all the help I can provide. :-)

Finally, I tracked it. The reason is that the function the_views() prints something directly, instead return a variable. Here is the source code:
### Function: Display The Post Views
function the_views($display = true, $prefix = '', $postfix = '', $always = false) {
$post_views = intval( get_post_meta( get_the_ID(), 'views', true ) );
$views_options = get_option('views_options');
if ($always || should_views_be_displayed($views_options)) {
$output = $prefix.str_replace( array( '%VIEW_COUNT%', '%VIEW_COUNT_ROUNDED%' ), array( number_format_i18n( $post_views ), postviews_round_number( $post_views) ), stripslashes( $views_options['template'] ) ).$postfix;
if($display) {
echo apply_filters('the_views', $output);
} else {
return apply_filters('the_views', $output);
}
}
elseif (!$display) {
return '';
}
}
To solve it, pass the parameter false to the_views to return as a variable, i.e., the_views(false).
printf( '<span class="posted-on">%1$s</span><span class="views-link">%2$s</span>',
sprintf( '%2$s',
esc_url( get_permalink() ),
$time_string_published
),
sprintf('%1$s views', the_views(false))
);

Related

Removing Order date from WooCommerce emails

I'm trying to remove the order date from the woocommerce emails, but as I'm not that confident in PHP I'm finding myself a bit stuck.
Below is some code I've found to a similar question (instead removing the order number but leaving the date...I want to do the opposite.
<?php
// Targetting specific email notificatoins
$email_ids = array('new_order', 'customer_on_hold_order');
$date = sprintf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) );
// Displaying order number except for "New Order" and "Customer On Hold Order" notifications
if( ! in_array($email->id, $email_ids) ){
$order_number = sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() );
$date = '('.$date.')';
} else {
$date = __('Order date:', 'woocommerce') . ' ' . $date;
$order_number = '';
}
if ( $sent_to_admin ) {
$before = '<a class="link" href="' . esc_url(
$order->get_edit_order_url() ) . '">';
$after = '</a> ';
} else {
$before = '';
$after = ' ';
}
?>
<h2><?php echo $before . $order_number . $after . $date; ?></h2>
Managed to figure this one out myself...(although not sure it's good practice...but it works!)
Simply added a class to the h2 tag within your-child-theme/woocommerce/emails/email-order-details.php, like below:
<h2 class="fbc-time">
<?php
if ( $sent_to_admin ) {
$before = '<a class="link" href="' . esc_url( $order->get_edit_order_url() ) . '">';
$after = '</a>';
} else {
$before = '';
$after = '';
}
/* translators: %s: Order ID. */
echo wp_kses_post( $before . sprintf( __( 'Order #%s', 'woocommerce' ) . $after . ' <time datetime="%s">%s</time>', $order->get_order_number(), $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ) );
?>
Then selected the class in email-styles.php and used display: none

Get_the_author doesn't return author name

I am trying to show meta contents on single page. But get_the_author() is not showing. The result of the below code is
Written by on July 14, 2015
and it is supposed to show
Written by admin on July 14, 2015
Anyone knows what I am missing? Here is the code:
function mano_posted_on() {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
if (get_the_time('U') !== get_the_modified_time('U')) {
$time_string.= '<time class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf(
$time_string,
esc_attr(get_the_date('c')),
esc_html(get_the_date()),
esc_attr(get_the_modified_date('c')),
esc_html(get_the_modified_date())
);
printf(
__('<span class="byline">Written by %1$s</span><span class="posted-on">on %2$s</span>', 'mano'),
sprintf(
'<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
esc_url(get_author_posts_url(get_the_author_meta('ID'))),
esc_html(get_the_author())
),
sprintf(
'%2$s',
esc_url(get_permalink()),
$time_string
)
);
}
To return to PHP rather than displaying, use get_the_author().
https://codex.wordpress.org/Function_Reference/the_author
So try changing get_the_author() to the_author().
Try this :
echo get_the_author($post->author_id);
Make $post as global.
so it will look like on top of file :
global $post;

Place link in title from "read more" php WP

PHP help needed, so I got a wordpress problem I have function that show title content and continue reading text, and I need to place link from continue reading text in title and hide Continue reading text. Here is code from file that generate following title:
function whisper_entry_title2()
{
if ( !( $title = get_the_title() ) )
return;
// Check on singular pages
$is_single = is_singular() && !is_page_template( 'tpl/blog.php' ) && !is_page_template( 'tpl/blog-boxes.php' );
// Allow to config via global variable
if ( isset( $whisper['is_single'] ) )
$is_single = $whisper['is_single'];
$tag = $is_single ? 'h1' : 'h2';
$title = sprintf( '<b class="black">%4$s</b>', $tag, get_permalink(), the_title_attribute( 'echo=0' ), $title );
echo apply_filters( __FUNCTION__, $title );
}
And here is the part of the code that generate continue reading:
function whisper_content_limitoffer1( $num_words, $more = '...', $echo = true )
{
$content = get_the_content();
// Strip tags and shortcodes so the content truncation count is done correctly
$content = strip_tags( strip_shortcodes( $content ), apply_filters( 'whisper_content_limit_allowed_tags', '<script>,<style>' ) );
// Remove inline styles / scripts
$content = trim( preg_replace( '#<(s(cript|tyle)).*?</\1>#si', '', $content ) );
// Truncate $content to $max_char
$content = wp_trim_words( $content, $num_words );
if ( $more )
{
//$event_id = get_post_meta(get_the_ID(),'event_id', TRUE);
//$link="http://example.com/wp/events-offers/";
$output = sprintf(
'<p class="event2-cf-oe">%s %s</p>',
$content,
get_permalink(),
sprintf( __( 'Continue reading "%s"', 'whisper' ), the_title_attribute( 'echo=0' ) ),
$more
);
}
else
{
$output = sprintf( '<p class="event2-cf-oe">%s</p>', $content );
}
// Still display post formats differently
$output = whisper_post_formats_content( $output );
if ( $echo )
echo $output;
else
return $output;
}
Well your 'Continue reading' text is being outputted by the line that reads
sprintf( __( 'Continue reading "%s"', 'whisper' ), the_title_attribute( 'echo=0' ) ),
so just get rid of that line and that text is gone. Though I suspect you'll probably want to get rid of that entire block of code
$output = sprintf(
'<p class="event2-cf-oe">%s %s</p>',
$content,
get_permalink(),
sprintf( __( 'Continue reading "%s"', 'whisper' ), the_title_attribute( 'echo=0' ) ),
$more
);
And the link to your post is generated by the line just above that one which reads
get_permalink()
so you can relocate that.
You can quite easily output the post title and make it a link to the post with these simple Wordpress functions:
<a href="<?php echo get_permalink(); ?>">
<?php the_title; ?>
</a>

Overriding template with hooks

I am having a little trouble editing a Woocommerce template with hooks. Essentially I would just like to change the product-image template so instead of linking to the uploaded product image, it links to the product post.
The current product-image.php woocommerce template has
global $post, $woocommerce, $product;
?>
<div class="images">
<?php
if ( has_post_thumbnail() ) {
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
'title' => $image_title
) );
$attachment_count = count( $product->get_gallery_attachment_ids() );
if ( $attachment_count > 0 ) {
$gallery = '[product-gallery]';
} else {
$gallery = '';
}
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '%s', $image_link, $image_title, $image ), $post->ID );
} else {
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );
}
?>
<?php do_action( 'woocommerce_product_thumbnails' ); ?>
</div>
I am unsure of how to adapt the echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '%s', $image_link, $image_title, $image ), $post->ID ); to change the %s to a link to the post.
The hook I am using is:
add_action('woocommerce_product_thumbnails', 'custom_links');
function custom_links() {
//code
}
Could someone help me gain some direction with this?
You are calling action not filter. Also you are calling the wrong one.
Change this:
add_action('woocommerce_product_thumbnails', 'custom_links');
to this:
add_filter('woocommerce_single_product_image_html', 'custom_links', 10, 2);
The 2 represents the argument count for the function and your custom_links() should be something like:
function custom_links($link, $post_id) {
$pattern = '/(?<=href=")([^"]*)/';
$replacement = get_permalink($post->ID);
return preg_replace($pattern, $replacement, $link);
}
Process the $link variable as needed and then return it.

How to Sharpen Post Thumbnails in WordPress 3

I am using the default thumbnail feature of Wordpress 3 to add thumbnails of various sizes to my posts. Now the problem I face is that the shrinked thumbnails become very blurry.
In .Net I know how to sharpen images and this works really well for thumbnails, so I am now looking for a way to do this for Wordpress (in php obviously).
I really suck at php, so any help is really appreciated!
I use a modified version of ResizeThumbnails. This way you can re-generate all your blurry images and it also takes care of future uploaded images:
<?php
/*
**************************************************************************
Plugin Name: Regenerate Thumbnails
Plugin URI: http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/
Description: Allows you to regenerate all thumbnails after changing the thumbnail sizes.
Version: 2.2.3
Author: Viper007Bond
Author URI: http://www.viper007bond.com/
**************************************************************************
Copyright (C) 2008-2011 Viper007Bond
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
class RegenerateThumbnails {
var $menu_id;
// Plugin initialization
function RegenerateThumbnails() {
// Load up the localization file if we're using WordPress in a different language
// Place it in this plugin's "localization" folder and name it "regenerate-thumbnails-[value in wp-config].mo"
load_plugin_textdomain( 'regenerate-thumbnails', false, '/regenerate-thumbnails/localization' );
add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) );
add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueues' ) );
add_action( 'wp_ajax_regeneratethumbnail', array( &$this, 'ajax_process_image' ) );
add_filter( 'media_row_actions', array( &$this, 'add_media_row_action' ), 10, 2 );
//add_filter( 'bulk_actions-upload', array( &$this, 'add_bulk_actions' ), 99 ); // A last minute change to 3.1 makes this no longer work
add_action( 'admin_head-upload.php', array( &$this, 'add_bulk_actions_via_javascript' ) );
add_action( 'admin_action_bulk_regenerate_thumbnails', array( &$this, 'bulk_action_handler' ) ); // Top drowndown
add_action( 'admin_action_-1', array( &$this, 'bulk_action_handler' ) ); // Bottom dropdown (assumes top dropdown = default value)
// Allow people to change what capability is required to use this plugin
$this->capability = apply_filters( 'regenerate_thumbs_cap', 'manage_options' );
}
// Register the management page
function add_admin_menu() {
$this->menu_id = add_management_page( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ), __( 'Regen. Thumbnails', 'regenerate-thumbnails' ), $this->capability, 'regenerate-thumbnails', array(&$this, 'regenerate_interface') );
}
// Enqueue the needed Javascript and CSS
function admin_enqueues( $hook_suffix ) {
if ( $hook_suffix != $this->menu_id )
return;
// WordPress 3.1 vs older version compatibility
if ( wp_script_is( 'jquery-ui-widget', 'registered' ) )
wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'jquery-ui/jquery.ui.progressbar.min.js', __FILE__ ), array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.8.6' );
else
wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'jquery-ui/jquery.ui.progressbar.min.1.7.2.js', __FILE__ ), array( 'jquery-ui-core' ), '1.7.2' );
wp_enqueue_style( 'jquery-ui-regenthumbs', plugins_url( 'jquery-ui/redmond/jquery-ui-1.7.2.custom.css', __FILE__ ), array(), '1.7.2' );
}
// Add a "Regenerate Thumbnails" link to the media row actions
function add_media_row_action( $actions, $post ) {
if ( 'image/' != substr( $post->post_mime_type, 0, 6 ) || ! current_user_can( $this->capability ) )
return $actions;
$url = wp_nonce_url( admin_url( 'tools.php?page=regenerate-thumbnails&goback=1&ids=' . $post->ID ), 'regenerate-thumbnails' );
$actions['regenerate_thumbnails'] = '' . __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ) . '';
return $actions;
}
// Add "Regenerate Thumbnails" to the Bulk Actions media dropdown
function add_bulk_actions( $actions ) {
$delete = false;
if ( ! empty( $actions['delete'] ) ) {
$delete = $actions['delete'];
unset( $actions['delete'] );
}
$actions['bulk_regenerate_thumbnails'] = __( 'Regenerate Thumbnails', 'regenerate-thumbnails' );
if ( $delete )
$actions['delete'] = $delete;
return $actions;
}
// Add new items to the Bulk Actions using Javascript
// A last minute change to the "bulk_actions-xxxxx" filter in 3.1 made it not possible to add items using that
function add_bulk_actions_via_javascript() {
if ( ! current_user_can( $this->capability ) )
return;
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('select[name^="action"] option:last-child').before('<option value="bulk_regenerate_thumbnails"><?php echo esc_attr( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ) ); ?></option>');
});
</script>
<?php
}
// Handles the bulk actions POST
function bulk_action_handler() {
if ( empty( $_REQUEST['action'] ) || ( 'bulk_regenerate_thumbnails' != $_REQUEST['action'] && 'bulk_regenerate_thumbnails' != $_REQUEST['action2'] ) )
return;
if ( empty( $_REQUEST['media'] ) || ! is_array( $_REQUEST['media'] ) )
return;
check_admin_referer( 'bulk-media' );
$ids = implode( ',', array_map( 'intval', $_REQUEST['media'] ) );
// Can't use wp_nonce_url() as it escapes HTML entities
wp_redirect( add_query_arg( '_wpnonce', wp_create_nonce( 'regenerate-thumbnails' ), admin_url( 'tools.php?page=regenerate-thumbnails&goback=1&ids=' . $ids ) ) );
exit();
}
// The user interface plus thumbnail regenerator
function regenerate_interface() {
global $wpdb;
?>
<div id="message" class="updated fade" style="display:none"></div>
<div class="wrap regenthumbs">
<h2><?php _e('Regenerate Thumbnails', 'regenerate-thumbnails'); ?></h2>
<?php
// If the button was clicked
if ( ! empty( $_POST['regenerate-thumbnails'] ) || ! empty( $_REQUEST['ids'] ) ) {
// Capability check
if ( ! current_user_can( $this->capability ) )
wp_die( __( 'Cheatin’ uh?' ) );
// Form nonce check
check_admin_referer( 'regenerate-thumbnails' );
// Create the list of image IDs
if ( ! empty( $_REQUEST['ids'] ) ) {
$images = array_map( 'intval', explode( ',', trim( $_REQUEST['ids'], ',' ) ) );
$ids = implode( ',', $images );
} else {
// Directly querying the database is normally frowned upon, but all
// of the API functions will return the full post objects which will
// suck up lots of memory. This is best, just not as future proof.
if ( ! $images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' ORDER BY ID DESC" ) ) {
echo ' <p>' . sprintf( __( "Unable to find any images. Are you sure <a href='%s'>some exist</a>?", 'regenerate-thumbnails' ), admin_url( 'upload.php?post_mime_type=image' ) ) . "</p></div>";
return;
}
// Generate the list of IDs
$ids = array();
foreach ( $images as $image )
$ids[] = $image->ID;
$ids = implode( ',', $ids );
}
echo ' <p>' . __( "Please be patient while the thumbnails are regenerated. This can take a while if your server is slow (inexpensive hosting) or if you have many images. Do not navigate away from this page until this script is done or the thumbnails will not be resized. You will be notified via this page when the regenerating is completed.", 'regenerate-thumbnails' ) . '</p>';
$count = count( $images );
$text_goback = ( ! empty( $_GET['goback'] ) ) ? sprintf( __( 'To go back to the previous page, click here.', 'regenerate-thumbnails' ), 'javascript:history.go(-1)' ) : '';
$text_failures = sprintf( __( 'All done! %1$s image(s) were successfully resized in %2$s seconds and there were %3$s failure(s). To try regenerating the failed images again, click here. %5$s', 'regenerate-thumbnails' ), "' + rt_successes + '", "' + rt_totaltime + '", "' + rt_errors + '", esc_url( wp_nonce_url( admin_url( 'tools.php?page=regenerate-thumbnails&goback=1' ), 'regenerate-thumbnails' ) . '&ids=' ) . "' + rt_failedlist + '", $text_goback );
$text_nofailures = sprintf( __( 'All done! %1$s image(s) were successfully resized in %2$s seconds and there were 0 failures. %3$s', 'regenerate-thumbnails' ), "' + rt_successes + '", "' + rt_totaltime + '", $text_goback );
?>
<noscript><p><em><?php _e( 'You must enable Javascript in order to proceed!', 'regenerate-thumbnails' ) ?></em></p></noscript>
<div id="regenthumbs-bar" style="position:relative;height:25px;">
<div id="regenthumbs-bar-percent" style="position:absolute;left:50%;top:50%;width:300px;margin-left:-150px;height:25px;margin-top:-9px;font-weight:bold;text-align:center;"></div>
</div>
<p><input type="button" class="button hide-if-no-js" name="regenthumbs-stop" id="regenthumbs-stop" value="<?php _e( 'Abort Resizing Images', 'regenerate-thumbnails' ) ?>" /></p>
<h3 class="title"><?php _e( 'Debugging Information', 'regenerate-thumbnails' ) ?></h3>
<p>
<?php printf( __( 'Total Images: %s', 'regenerate-thumbnails' ), $count ); ?><br />
<?php printf( __( 'Images Resized: %s', 'regenerate-thumbnails' ), '<span id="regenthumbs-debug-successcount">0</span>' ); ?><br />
<?php printf( __( 'Resize Failures: %s', 'regenerate-thumbnails' ), '<span id="regenthumbs-debug-failurecount">0</span>' ); ?>
</p>
<ol id="regenthumbs-debuglist">
<li style="display:none"></li>
</ol>
<script type="text/javascript">
// <![CDATA[
jQuery(document).ready(function($){
var i;
var rt_images = [<?php echo $ids; ?>];
var rt_total = rt_images.length;
var rt_count = 1;
var rt_percent = 0;
var rt_successes = 0;
var rt_errors = 0;
var rt_failedlist = '';
var rt_resulttext = '';
var rt_timestart = new Date().getTime();
var rt_timeend = 0;
var rt_totaltime = 0;
var rt_continue = true;
// Create the progress bar
$("#regenthumbs-bar").progressbar();
$("#regenthumbs-bar-percent").html( "0%" );
// Stop button
$("#regenthumbs-stop").click(function() {
rt_continue = false;
$('#regenthumbs-stop').val("<?php echo $this->esc_quotes( __( 'Stopping...', 'regenerate-thumbnails' ) ); ?>");
});
// Clear out the empty list element that's there for HTML validation purposes
$("#regenthumbs-debuglist li").remove();
// Called after each resize. Updates debug information and the progress bar.
function RegenThumbsUpdateStatus( id, success, response ) {
$("#regenthumbs-bar").progressbar( "value", ( rt_count / rt_total ) * 100 );
$("#regenthumbs-bar-percent").html( Math.round( ( rt_count / rt_total ) * 1000 ) / 10 + "%" );
rt_count = rt_count + 1;
if ( success ) {
rt_successes = rt_successes + 1;
$("#regenthumbs-debug-successcount").html(rt_successes);
$("#regenthumbs-debuglist").append("<li>" + response.success + "</li>");
}
else {
rt_errors = rt_errors + 1;
rt_failedlist = rt_failedlist + ',' + id;
$("#regenthumbs-debug-failurecount").html(rt_errors);
$("#regenthumbs-debuglist").append("<li>" + response.error + "</li>");
}
}
// Called when all images have been processed. Shows the results and cleans up.
function RegenThumbsFinishUp() {
rt_timeend = new Date().getTime();
rt_totaltime = Math.round( ( rt_timeend - rt_timestart ) / 1000 );
$('#regenthumbs-stop').hide();
if ( rt_errors > 0 ) {
rt_resulttext = '<?php echo $text_failures; ?>';
} else {
rt_resulttext = '<?php echo $text_nofailures; ?>';
}
$("#message").html("<p><strong>" + rt_resulttext + "</strong></p>");
$("#message").show();
}
// Regenerate a specified image via AJAX
function RegenThumbs( id ) {
$.ajax({
type: 'POST',
url: ajaxurl,
data: { action: "regeneratethumbnail", id: id },
success: function( response ) {
if ( response.success ) {
RegenThumbsUpdateStatus( id, true, response );
}
else {
RegenThumbsUpdateStatus( id, false, response );
}
if ( rt_images.length && rt_continue ) {
RegenThumbs( rt_images.shift() );
}
else {
RegenThumbsFinishUp();
}
},
error: function( response ) {
RegenThumbsUpdateStatus( id, false, response );
if ( rt_images.length && rt_continue ) {
RegenThumbs( rt_images.shift() );
}
else {
RegenThumbsFinishUp();
}
}
});
}
RegenThumbs( rt_images.shift() );
});
// ]]>
</script>
<?php
}
// No button click? Display the form.
else {
?>
<form method="post" action="">
<?php wp_nonce_field('regenerate-thumbnails') ?>
<p><?php printf( __( "Use this tool to regenerate thumbnails for all images that you have uploaded to your blog. This is useful if you've changed any of the thumbnail dimensions on the <a href='%s'>media settings page</a>. Old thumbnails will be kept to avoid any broken images due to hard-coded URLs.", 'regenerate-thumbnails' ), admin_url( 'options-media.php' ) ); ?></p>
<p><?php printf( __( "You can regenerate specific images (rather than all images) from the <a href='%s'>Media</a> page. Hover over an image's row and click the link to resize just that one image or use the checkboxes and the "Bulk Actions" dropdown to resize multiple images (WordPress 3.1+ only).", 'regenerate-thumbnails '), admin_url( 'upload.php' ) ); ?></p>
<p><?php _e( "Thumbnail regeneration is not reversible, but you can just change your thumbnail dimensions back to the old values and click the button again if you don't like the results.", 'regenerate-thumbnails' ); ?></p>
<p><?php _e( 'To begin, just press the button below.', 'regenerate-thumbnails '); ?></p>
<p><input type="submit" class="button hide-if-no-js" name="regenerate-thumbnails" id="regenerate-thumbnails" value="<?php _e( 'Regenerate All Thumbnails', 'regenerate-thumbnails' ) ?>" /></p>
<noscript><p><em><?php _e( 'You must enable Javascript in order to proceed!', 'regenerate-thumbnails' ) ?></em></p></noscript>
</form>
<?php
} // End if button
?>
</div>
<?php
}
// Process a single image ID (this is an AJAX handler)
function ajax_process_image() {
#error_reporting( 0 ); // Don't break the JSON result
header( 'Content-type: application/json' );
$id = (int) $_REQUEST['id'];
$image = get_post( $id );
if ( ! $image || 'attachment' != $image->post_type || 'image/' != substr( $image->post_mime_type, 0, 6 ) )
die( json_encode( array( 'error' => sprintf( __( 'Failed resize: %s is an invalid image ID.', 'regenerate-thumbnails' ), esc_html( $_REQUEST['id'] ) ) ) ) );
if ( ! current_user_can( $this->capability ) )
$this->die_json_error_msg( $image->ID, __( "Your user account doesn't have permission to resize images", 'regenerate-thumbnails' ) );
$fullsizepath = get_attached_file( $image->ID );
if ( false === $fullsizepath || ! file_exists( $fullsizepath ) )
$this->die_json_error_msg( $image->ID, sprintf( __( 'The originally uploaded image file cannot be found at %s', 'regenerate-thumbnails' ), '<code>' . esc_html( $fullsizepath ) . '</code>' ) );
#set_time_limit( 900 ); // 5 minutes per image should be PLENTY
$metadata = wp_generate_attachment_metadata( $image->ID, $fullsizepath );
if ( is_wp_error( $metadata ) )
$this->die_json_error_msg( $image->ID, $metadata->get_error_message() );
if ( empty( $metadata ) )
$this->die_json_error_msg( $image->ID, __( 'Unknown failure reason.', 'regenerate-thumbnails' ) );
// If this fails, then it just means that nothing was changed (old value == new value)
wp_update_attachment_metadata( $image->ID, $metadata );
die( json_encode( array( 'success' => sprintf( __( '"%1$s" (ID %2$s) was successfully resized in %3$s seconds.', 'regenerate-thumbnails' ), esc_html( get_the_title( $image->ID ) ), $image->ID, timer_stop() ) ) ) );
}
// Helper to make a JSON error message
function die_json_error_msg( $id, $message ) {
die( json_encode( array( 'error' => sprintf( __( '"%1$s" (ID %2$s) failed to resize. The error message was: %3$s', 'regenerate-thumbnails' ), esc_html( get_the_title( $id ) ), $id, $message ) ) ) );
}
// Helper function to escape quotes in strings for use in Javascript
function esc_quotes( $string ) {
return str_replace( '"', '\"', $string );
}
}
// Start up this plugin
add_action( 'init', 'RegenerateThumbnails' );
function RegenerateThumbnails() {
global $RegenerateThumbnails;
$RegenerateThumbnails = new RegenerateThumbnails();
}
// sharpen uploaded images
function ajx_sharpen_resized_files( $resized_file ) {
$image = wp_load_image( $resized_file );
if ( !is_resource( $image ) )
return new WP_Error( 'error_loading_image', $image, $file );
$size = #getimagesize( $resized_file );
if ( !$size )
return new WP_Error('invalid_image', __('Could not read image size'), $file);
list($orig_w, $orig_h, $orig_type) = $size;
switch ( $orig_type ) {
case IMAGETYPE_JPEG:
$matrix = array(
array(apply_filters('sharpen_resized_corner',-1.2), apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_corner',-1.2)),
array(apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_center',20), apply_filters('sharpen_resized_side',-1)),
array(apply_filters('sharpen_resized_corner',-1.2), apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_corner',-1.2)),
);
$divisor = array_sum(array_map('array_sum', $matrix));
$offset = 0;
imageconvolution($image, $matrix, $divisor, $offset);
imagejpeg($image, $resized_file,apply_filters( 'jpeg_quality', 100, 'edit_image' ));
break;
case IMAGETYPE_PNG:
return $resized_file;
case IMAGETYPE_GIF:
return $resized_file;
}
// we don't need images in memory anymore
imagedestroy( $image );
return $resized_file;
}
add_filter('image_make_intermediate_size', 'ajx_sharpen_resized_files', 900);
?>
i think this is your answer: http://vikjavev.no/computing/ump.php ,
however you'll need to change the thumbnailer creator script in wp.
Here is the solution if your wordpress post thumbnail blurry, go to your theme CSS , get the code :
.secondary-posts .post-thumbnail
width: 100%;
background-color: #666;
height: 150px;
padding: 0;
box-shadow: 0 0px 5px #888;
background-repeat: no-repeat;
background-position:center;
background-size: 150px auto;
( CHANGE THIS BACKGROUND SIZE TO YOUR THUMBNAIL BOX SIZE( example 150px )
I have used it for our web and its works ,the thumbnail sharp now,here is the result
: http://kresnatourjogja.com/category/jogjakarta-temple/

Categories