Skip to content

WordPress用外掛加入特色圖片並調整CSS

歡迎在下方留言區討論

用外掛加入特色圖片並加入調整用的CSS,

雖然我不是很理解為何要這樣大費周章,不過就當練習改寫完順便記錄

<?php
/*
Plugin Name: Add Featured Image Before Content In Any Theme
Plugin URI: http://wpsites.net/web-design/add-featured-image-before-content-in-any-theme/
Description: @copyright 2014 WP Sites
Version: 1.0.9
Author: Brad Dalton / Pathwaysoft
Author Email: stevewei@pathwaysoft.com
*/
//若仅在某些页面加载,利用WordPress的Conditional Tags即可。

//https://codex.wordpress.org/Conditional_Tags
//http://www.solagirl.net/wordpress-ways-to-load-js-css.html
add_filter( ‘the_content’, ‘wpsites_image_before_content’ );

function wpsites_image_before_content( $content ) {

if ( is_singular(‘post’) && has_post_thumbnail()&& in_category( array( 3,4 ) ) ) {

wp_enqueue_style(‘wpsites_image_before_content’, plugin_dir_url( __FILE__ ) . ‘/css/wpsites_image_before_content.css’ );

$img = get_the_post_thumbnail($post_id, ‘full’, array(‘class’ => ‘image_before_content’));

$content = $img . $content;

}

return $content;
}

?>

外掛裡面css資料夾的 wpsites_image_before_content.css內容如下

.image_before_content {
float:left;
padding: 10px;
}

 

參考資料:

http://wpsites.net/web-design/add-featured-image-before-content-in-any-theme/

© 2015, Chaneswin. 如發現留有早期非原創作品可以留言回報喔~感謝您的幫忙 🙂


文章如有幫助,先按讚,再分享,歡迎贊助哦!  

歡迎在下方留言區討論