小编Jim*_*son的帖子

尝试以编程方式生成 WordPress 缩略图

我正在尝试以编程方式添加一堆帖子,然后添加它们的附带图像。我有一个包含所有图像文件名的数组,并且我已经能够将它们添加到数据库中,但我似乎无法创建正确的缩略图。

这些帖子来自位于 wp-content/uploads/dirname/ 的 csv。它们的文件名中包含与 CSV 中的 ID 相对应的数字,这就是我如何知道需要将哪些图像添加到哪个帖子 ID 中。

我已经获得了 wp_insert_attachment() 部分来处理它们自己的小目录中的图像,但我无法生成缩略图。我安装了重新生成缩略图插件,并且它能够生成它们,但我似乎无法让它以编程方式发生。

我认为这可能是因为 wp_generate_attachment 需要照片位于 /uploads/2011/12/ (例如)中,所以我开始沿着移动图像然后尝试添加它们的路径。无论如何,这是有道理的,因为我有点想制作副本,而不是将 5 或 6 个不同的媒体尺寸添加到我的 wp-content/uploads/dirname/ 目录中。

无论如何,这是行不通的。通过 PHP 的副本移动图像不起作用,并且不会生成缩略图。

foreach ($frazerfiles[$stock_num] as $stock_img){
  require_once(ABSPATH . 'wp-admin/includes/image.php');
  echo "... ...Trying to add attachment metadata...";

  // copy the file to the upload dir
  $uploads = wp_upload_dir();
  $file_to_move = ABSPATH."wp-content/uploads/".$stock_img;
  if (copy($file_to_move, $uploads['path']."/")) {
    echo "Moved $file_to_move to ".$uploads['path']."/";
    $my_moved_file = $uploads['path']."/".$stock_img;

    // I think this is failing because the images aren't in the …
Run Code Online (Sandbox Code Playgroud)

php wordpress image

6
推荐指数
1
解决办法
8195
查看次数

Javascript"=="运算符谎言

以下让我很困惑.正如评论中所指出的那样,比较似乎是单独工作的,但是当它们组合在一起时却没有

while应该在同一个月的所有日子里运行,然后将i递增1,然后重新开始.

我已经用console.log完成了整个序列,试图找出它,但它没有任何意义.一切似乎彼此相等,但仍未通过while语句中的"=="测试.

  var i=0;
  var currentdate = 0;
  var currentmonth = 0;
  var opensmonth = 0;
  var opens = [
  { "date":"3/30/2006","zip":"30038","latitude":"33.676358","longitude":"-84.15381"},
  { "date":"4/31/2006","zip":"30519","latitude":"34.089419","longitude":"-83.94701"}
  ];
  intid = setInterval("stepthrough()", 250);
  function stepthrough() {
    //figure out first date.
    if (currentdate == 0) { // we've not been run before
      currentdate = opens[0]["date"];
      currentmonth = currentdate.split("/", 1);
      console.log("Current Month: >" + currentmonth +"<");
    }
    console.log("Current month: " + currentmonth + " And opensdate: " + opens[i]["date"].split("/", 1));

    // 
    // TWILIGHT ZONE ENTERED. …
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
2
解决办法
194
查看次数

标签 统计

image ×1

javascript ×1

php ×1

wordpress ×1