Categories Images
https://wordpress.org/plugins/categories-images/
1. ลง plugin “Categories Images”
2. เข้าไปที่ categoty เพื่อ อัพรุปประจำ category ได้เลย
แสดงรูปในหน้า category นั่นๆ โดยใส่ code นี้ ใน achieve.php หรือ category.php
<?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?> to get the url and put it in any img tag or simply use <?php if (function_exists('z_taxonomy_image')) z_taxonomy_image(); ?> in (category or taxonomy) template.
มันจะดึงรูปประจำ categoty ที่เรากำหนดไว้ ออกมาแสดงเมื่อเราเข้าไป category แต่ละอัน
อื่นๆ
Default usage: use the following code in category or taxonomy template,put it in any <img /> tag : <?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?> or simply: <?php if (function_exists('z_taxonomy_image')) z_taxonomy_image(); ?>
Using inside a loop ดึงรุปและชื่อ catrgory
<ul> <?php foreach (get_categories() as $cat) : ?> <li> <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" /> <a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->cat_name; ?></a> </li> <?php endforeach; ?> </ul>
or
<ul> <?php foreach (get_categories() as $cat) : ?> <li> <?php z_taxonomy_image($cat->term_id); ?> <a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->cat_name; ?></a> </li> <?php endforeach; ?> </ul>
If looping for taxonomies
<ul> <?php foreach (get_terms('your_taxonomy') as $cat) : ?> <li> <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" /> <a href="<?php echo get_term_link($cat->slug, 'your_taxonomy'); ?>"><?php echo $cat->name; ?></a> </li> <?php endforeach; ?> </ul>
or
<ul> <?php foreach (get_terms('your_taxonomy') as $cat) : ?> <li> <?php z_taxonomy_image($cat->term_id); ?> <a href="<?php echo get_term_link($cat->slug, 'your_taxonomy'); ?>"><?php echo $cat->name; ?></a> </li> <?php endforeach; ?> </ul>
If your post had more than one category and you want to loop for all post categories use the following example:
<ul> <?php foreach (get_the_category() as $cat) : ?> <li> <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" /> <a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->cat_name; ?></a> </li> <?php endforeach; ?> </ul>
or
<ul> <?php foreach (get_the_category() as $cat) : ?> <li> <?php z_taxonomy_image($cat->term_id); ?> <a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->cat_name; ?></a> </li> <?php endforeach; ?> </ul>
And if your post had more than one taxonomy and you want to loop for all post taxonomies use the following example:
<ul> <?php foreach (get_the_terms(get_the_ID(), 'your_taxonomy') as $cat) : ?> <li> <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" /> <a href="<?php echo get_term_link($cat->term_id, 'your_taxonomy'); ?>"><?php echo $cat->name; ?></a> </li> <?php endforeach; ?> </ul> or <ul> <?php foreach (get_the_terms(get_the_ID(), 'your_taxonomy') as $cat) : ?> <li> <?php z_taxonomy_image($cat->term_id); ?> <a href="<?php echo get_term_link($cat->term_id, 'your_taxonomy'); ?>"><?php echo $cat->name; ?></a> </li> <?php endforeach; ?> </ul>
Using resizing feature:
To resize category image simply add the size as a second parameter, for example:
if in category or taxonomy template:
<img src="<?php echo z_taxonomy_image_url(NULL, 'thumbnail'); ?>" /> or <?php z_taxonomy_image(NULL, 'thumbnail'); ?> or if inside a loop: <ul> <?php foreach (get_the_terms(get_the_ID(), 'your_taxonomy') as $cat) : ?> <li> <img src="<?php echo z_taxonomy_image_url($cat->term_id, 'medium'); ?>" /> <a href="<?php echo get_term_link($cat->term_id, 'your_taxonomy'); ?>"><?php echo $cat->name; ?></a> </li> <?php endforeach; ?> </ul>
you can choose to resize from these (thumbnail, medium, large, full) or any custom sizes, also you can use it as array with dimensions for example:
<img src="<?php echo z_taxonomy_image_url(NULL, array(300, 250)); ?>" /> or <?php z_taxonomy_image(NULL, array(300, 250)); ?>
Please check WordPress codex here for more information about resizing.
To display image with support for alt, class, width and height, you can do as this example:
<?php $attr = array( 'class' => 'category_image', 'alt' => 'image alt', 'height' => 200, 'width' => 300, 'title' => 'category title', ); z_taxonomy_image(NULL, 'full', $attr); ?>
if there were any bugs or you faced any problems please reply to this post, if I had more time I will update this plugin and add more features.
update 26-07-2012: I had noticed that there is some people talking about my plugin, here is a link to the post ?
http://wpshock.com/wordpress-category-images-taxonomy-images-plugin/
another one here also:
http://www.williamsgraphics.co.uk/featured-images-categories-wordpress/
Update 06-10-2012: Finally I got some time to test the plugin in WordPress MU and now I confirm that the plugin works so fine whether you choose to activate the plugin by blog or using network activation from your network control panel
Update 25-01-2013: A great update had been made to this plugin, and hope you liked it, Thank so much to Joe Tse http://tkjune.com
Update 14-06-2013: I had updated the plugin with some new features like using WordPress new media uploader and new sub menu (Categories Images) in Settings menu allowing you to exclude any taxonomies from the plugin, this for fixing and avoiding any conflicts with another plugins like WooCommerce plugin, hope you all like the last update.
Update 20-12-2013: I had updated the plugin with new features like resizing images please check the docs above for more help about using this new feature, and also adding support for Spanish language. Thanks so much to Maria Ramos and to Rahil Wazir for their help.
Update 2.5 28-03-2015: A nice update which introduce a new function to display category or taxonomy image directly with support for size and alt and more attributes, please check the documentation above. Also adding support for Ukrainian language, thanks so much to Michael Yunat.
อื่นๆ
https://premium.wpmudev.org/blog/how-to-add-feature-images-to-your-wordpress-categories/?ptma=b&utm_expid=3606929-109.P6e7JvhjTrWFxwrJZjRkog.1&utm_referrer=https%3A%2F%2Fwww.google.co.th%2F