如何在此代码中集成无图像图片

时间:2013-07-18 作者:Batman

如果没有附加图像,如何集成图像?

我使用这段代码成功地集成了没有图片的图片,如果没有图片附在帖子上。

<?php
if ( ! $img = get_field(\'img_actor\', $post_object->ID ) )
    $img = \'/wp-content/uploads/noimage1.jpg\';
?>
<img class="actor_img" src="/scripts/timthumb.php?src=<?php echo urlencode($img); ?>&h=70&w=50&zc=1"
好吧,但我如何才能将此代码集成到我的GD星级代码中。Gd Star Rating是一个插件,用于对帖子进行评级-GD Star Rating

foreach ($all_rows as $row) {
    if ($widget["image_from"] == "content") {

$row->image = gdFunctionsGDSR::get_image_from_text($row->post_content);
    } 
else if ($widget["image_from"] == "custom") {

$post_custom_id = get_post_meta($row->post_id, $widget["image_custom"], true);
$row->image = get_bloginfo(\'url\')."/scripts/timthumb.php?src=".get_bloginfo(\'url\')."/wp-content/uploads/".get_post_meta($post_custom_id,"_wp_attached_file",true)."&amp;h=70&amp;w=55&amp;zc=1";

    }
                            }
完整代码的链接https://github.com/MaineLearning/MaineLearning/blob/master/wp-content/plugins/gd-star-rating/code/t2/render.php

如何添加页面以显示帖子数量。

<?php 
wp_gdsr_render_rating_results(array(\'template_id\' => 48, \'rows\' => 1, \'select\' => \'persoane\', \'min_votes\' => 0, \'min_count\' => 0, \'excerpt_words\' => 0, \'image_from\' => \'custom\', \'image_custom\' => \'img_actor\', \'image_resize_x\' => 55, \'image_resize_y\' => 70, \'publish_days\' => 1, \'rating_size\' => \'12\', \'review_size\' => \'12\', \'rating_thumb_size\' => \'12\'));
?> 

2 个回复
最合适的回答,由SO网友:Charles Clarkson 整理而成

更改此项:

else if ($widget["image_from"] == "custom") {

    $post_custom_id = get_post_meta($row->post_id, $widget["image_custom"], true);
    $row->image = get_bloginfo(\'url\')."/scripts/timthumb.php?src=".get_bloginfo(\'url\')."/wp-content/uploads/".get_post_meta($post_custom_id,"_wp_attached_file",true)."&amp;h=70&amp;w=55&amp;zc=1";

}
对此:

} else if ( \'custom\' == $widget[\'image_from\'] ) {

    $post_custom_id = get_post_meta( $row->post_id, $widget[\'image_custom\'], true );

    if ( get_post_meta( $post_custom_id, \'_wp_attached_file\', true ) )
        $row->image = get_bloginfo(\'url\') . \'/scripts/timthumb.php?src=\' . get_bloginfo(\'url\') . \'/wp-content/uploads/\' . get_post_meta( $post_custom_id, \'_wp_attached_file\', true ) . \'&amp;h=70&amp;w=55&amp;zc=1\';
    else
        $row->image = get_bloginfo(\'url\') . \'/scripts/timthumb.php?src=\' . get_bloginfo(\'url\') . \'/wp-content/uploads/noimage1.jpg&amp;h=70&amp;w=55&amp;zc=1\';
}

SO网友:s_ha_dum

非常粗糙,但如果您想在以下情况下添加图像--get_post_meta($row->post_id, $widget["image_custom"], true);-- 是空的,下面应该这样做。你需要改变test_meta 不管怎样$widget["image_custom"]

function alter_meta_wpse_106998($a, $object_id, $meta_key, $single) {
  if (\'test_meta\' === $meta_key) {

    $meta_type = \'post\';

    $meta_cache = wp_cache_get($object_id, $meta_type . \'_meta\');

    if ( !$meta_cache ) {
      $meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
      $meta_cache = $meta_cache[$object_id];
    }

    if ( empty($meta_cache[$meta_key]) ) {
      $meta_cache[$meta_key][] = site_url(\'/wp-content/uploads/noimage1.jpg\');
    }

    if ( !$meta_key ) {
      return $meta_cache;
    }

    if ( isset($meta_cache[$meta_key]) ) {
      if ( $single ) {
        return maybe_unserialize( $meta_cache[$meta_key][0] );
      } else {
        return array_map(\'maybe_unserialize\', $meta_cache[$meta_key]);
      }
    }

    if ($single) {
      return \'\';
    } else {
      return array();
    }
  }
  return null;
}
add_filter(\'get_post_metadata\',\'alter_meta_wpse_106998\',1,4);
如果您查看该代码,它在很大程度上是对get_metadata 并大量借用了该功能。

结束

相关推荐

如何重命名运行在IIS6上的WordPress wp-login.php?

我的Windows 2003 VPS最近挂起,因为机器人程序连续几个小时不停地敲打我的WordPress登录php(根据IIS6日志确定)。这导致MySQL耗尽了所有分配的1G RAM。重置VM后,我迅速重命名了wp登录名。php来防止我的服务器再次崩溃。按照重命名新安装的web应用程序的管理员用户名和管理员登录文件夹/路径的标准做法,在6月份第一次安装WP之后,我尝试重命名WP admin文件夹,但失败了。我向wp admin添加了Windows身份验证,希望这将有助于提高安全性,但事实证明,这并不能阻

如何在此代码中集成无图像图片 - 小码农CODE - 行之有效找到问题解决它

如何在此代码中集成无图像图片

时间:2013-07-18 作者:Batman

如果没有附加图像,如何集成图像?

我使用这段代码成功地集成了没有图片的图片,如果没有图片附在帖子上。

<?php
if ( ! $img = get_field(\'img_actor\', $post_object->ID ) )
    $img = \'/wp-content/uploads/noimage1.jpg\';
?>
<img class="actor_img" src="/scripts/timthumb.php?src=<?php echo urlencode($img); ?>&h=70&w=50&zc=1"
好吧,但我如何才能将此代码集成到我的GD星级代码中。Gd Star Rating是一个插件,用于对帖子进行评级-GD Star Rating

foreach ($all_rows as $row) {
    if ($widget["image_from"] == "content") {

$row->image = gdFunctionsGDSR::get_image_from_text($row->post_content);
    } 
else if ($widget["image_from"] == "custom") {

$post_custom_id = get_post_meta($row->post_id, $widget["image_custom"], true);
$row->image = get_bloginfo(\'url\')."/scripts/timthumb.php?src=".get_bloginfo(\'url\')."/wp-content/uploads/".get_post_meta($post_custom_id,"_wp_attached_file",true)."&amp;h=70&amp;w=55&amp;zc=1";

    }
                            }
完整代码的链接https://github.com/MaineLearning/MaineLearning/blob/master/wp-content/plugins/gd-star-rating/code/t2/render.php

如何添加页面以显示帖子数量。

<?php 
wp_gdsr_render_rating_results(array(\'template_id\' => 48, \'rows\' => 1, \'select\' => \'persoane\', \'min_votes\' => 0, \'min_count\' => 0, \'excerpt_words\' => 0, \'image_from\' => \'custom\', \'image_custom\' => \'img_actor\', \'image_resize_x\' => 55, \'image_resize_y\' => 70, \'publish_days\' => 1, \'rating_size\' => \'12\', \'review_size\' => \'12\', \'rating_thumb_size\' => \'12\'));
?> 

2 个回复
最合适的回答,由SO网友:Charles Clarkson 整理而成

更改此项:

else if ($widget["image_from"] == "custom") {

    $post_custom_id = get_post_meta($row->post_id, $widget["image_custom"], true);
    $row->image = get_bloginfo(\'url\')."/scripts/timthumb.php?src=".get_bloginfo(\'url\')."/wp-content/uploads/".get_post_meta($post_custom_id,"_wp_attached_file",true)."&amp;h=70&amp;w=55&amp;zc=1";

}
对此:

} else if ( \'custom\' == $widget[\'image_from\'] ) {

    $post_custom_id = get_post_meta( $row->post_id, $widget[\'image_custom\'], true );

    if ( get_post_meta( $post_custom_id, \'_wp_attached_file\', true ) )
        $row->image = get_bloginfo(\'url\') . \'/scripts/timthumb.php?src=\' . get_bloginfo(\'url\') . \'/wp-content/uploads/\' . get_post_meta( $post_custom_id, \'_wp_attached_file\', true ) . \'&amp;h=70&amp;w=55&amp;zc=1\';
    else
        $row->image = get_bloginfo(\'url\') . \'/scripts/timthumb.php?src=\' . get_bloginfo(\'url\') . \'/wp-content/uploads/noimage1.jpg&amp;h=70&amp;w=55&amp;zc=1\';
}

SO网友:s_ha_dum

非常粗糙,但如果您想在以下情况下添加图像--get_post_meta($row->post_id, $widget["image_custom"], true);-- 是空的,下面应该这样做。你需要改变test_meta 不管怎样$widget["image_custom"]

function alter_meta_wpse_106998($a, $object_id, $meta_key, $single) {
  if (\'test_meta\' === $meta_key) {

    $meta_type = \'post\';

    $meta_cache = wp_cache_get($object_id, $meta_type . \'_meta\');

    if ( !$meta_cache ) {
      $meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
      $meta_cache = $meta_cache[$object_id];
    }

    if ( empty($meta_cache[$meta_key]) ) {
      $meta_cache[$meta_key][] = site_url(\'/wp-content/uploads/noimage1.jpg\');
    }

    if ( !$meta_key ) {
      return $meta_cache;
    }

    if ( isset($meta_cache[$meta_key]) ) {
      if ( $single ) {
        return maybe_unserialize( $meta_cache[$meta_key][0] );
      } else {
        return array_map(\'maybe_unserialize\', $meta_cache[$meta_key]);
      }
    }

    if ($single) {
      return \'\';
    } else {
      return array();
    }
  }
  return null;
}
add_filter(\'get_post_metadata\',\'alter_meta_wpse_106998\',1,4);
如果您查看该代码,它在很大程度上是对get_metadata 并大量借用了该功能。

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请