<?php wp_insert_attachment( $attachment, $filename, $parent_post_id ); ?>Bu kodu inceledim ama pekte faydalanamadım
Wordpress Bot Öne Çıkarılan Görsel Seçme
2
●1.801
- 10-01-2015, 04:22:53Kimlik doğrulama veya yönetimden onay bekliyor.Arkadaşlar bir haber sitesinden içerik çeken bot yazıyorum ancak çekilen haber afişini öne çıkarılan görsel olarak nasıl belirleyeceğim bu konuda bilgisi olan varmı?
- 10-01-2015, 08:56:03öncelikle wp_insert_post fonksiyonunu geriye gönderdiği ID'yi bir değişkende saklamalısın;
$post_id = wp_insert_post( $post_data );
daha sonra şu şekilde, belirttiğin url'deki resimi; sunucuna indirtip, öne çıkan görsel olarak atayabilirsin;
/** ** $image_url uzaktaki resmin url si olmalı **/ $image_url = 'https://www.r10.net/images/logom7.png'; /** ** Öne çıkarılmış görseli ekliyeceğiz **/ $upload_dir = wp_upload_dir(); $image_data = file_get_contents($image_url); $filename = basename($image_url); if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $filename; else $file = $upload_dir['basedir'] . '/' . $filename; file_put_contents($file, $image_data); $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $file, $post_id ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); wp_update_attachment_metadata( $attach_id, $attach_data ); set_post_thumbnail( $post_id, $attach_id ); - 10-01-2015, 12:49:17Hay Allah Razı Olsun Hocam.Sağolun r10+jebias adlı üyeden alıntı: mesajı görüntüle