ASametYildirim adlı üyeden alıntı

Merhaba hocam.

Eğer kullanmakta olduğunuz tema “öne çıkan görsel” özelliğini destekliyorsa yazılarınıza tek tek öne çıkan görsel seçmeniz gerekebilir. Tabi opsiyonel bir özellik olduğundan kullanmaya da bilirsiniz ancak özellikle pek çok tema slider, archive gibi yapılarda bu görselleri kullanır.

Bu işi otomatik ve zahmetsiz olarak yapmanın basit bir yolu var. Aşağıdaki kod’u yeni bir php dosyası oluşturup içerisine yazmak suretiyle, wordpress sitenizin plugins dizinine yükleyip etkinleştirdiğiniz zaman. Yazılarınızda kullandığınız ilk resim otomatik olarak öne çıkarılacaktır.


/** * Plugin Name: Set featured image * Plugin URI: http://bueltge.de * Description: Set featureed image automaticly on save post/page * Version: 1.0.0 * Author: Frank Bültge * Author URI: http://bueltge.de * License: GPLv3 */
// This file is not called by WordPress. We don't like that.
! defined( 'ABSPATH' ) and exit;
if ( ! function_exists( 'fb_set_featured_image' ) ) { add_action( 'save_post', 'fb_set_featured_image' ); function fb_set_featured_image() { if ( ! isset( $GLOBALS['post']->ID ) ) return NULL; if ( has_post_thumbnail( get_the_ID() ) ) return NULL; $args = array( 'numberposts' => 1, 'order' => 'ASC', // DESC for the last image 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_status' => NULL, 'post_type' => 'attachment' ); $attached_image = get_children( $args ); if ( $attached_image ) { foreach ( $attached_image as $attachment_id => $attachment ) set_post_thumbnail( get_the_ID(), $attachment_id ); } }
}



hocam teşekkür ederim fakat benim istediğim şey ilk resim olmaması gerekiyor yani yazının içerinde sadece yazılar olacak birde öne çıkan görseli fakat bir bunu yapmamışlar sanırım özel alana url girip şu işi bir çözemedim :D istediğim şey sadece şu eğer özel alan bölümü boş ise manuel seçime bakıcak eğer doluysa özel alan bölümündeki urlyi gösterecek :)