function set_column_value($column_name, $post_ID) {
if ($column_name == 'featured_image') {
$post_featured_image = get_featured_image($post_ID);
if ($post_featured_image) {
echo 'YesOrNO';
}
}
}
function get_featured_image($post_ID) {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'featured_preview');
return $post_thumbnail_img[0];
}
}
add_action('manage_posts_custom_column', 'set_column_value', 10, 2);
Yes , I get the column name and value (i.e. YesOrNo) as I expected. In wordpress frontend, I want to show the featured images of posts with a condition. The condition is : I need a click handler on the column value (i.e. YesOrNo) so that I can toggle it as chosen or unchosen and I like to show featured images from the chosen ones only.
I'd suggest creating a new meta value called `_show_featured_image` which will be used to determine if the image should be shown on the frontend or not. Then, in addition to displaying this value within the admin columns, you will need to create an ajax handler to allow users to toggle the value. [Here is a great looking post which deals with something similar](https://wordpress.stackexchange.com/questions/33442/custom-column-for-changing-post-status-via-ajax) (toggling post status) which should help to to accomplish that.
@DaveRomsey, trying to understand the solution you referred to. Can you shed a bit more light i.e. attaching the click handler and making or freeing `YesOrNo` from a focused state (i.e bold) wrt to toggling it ?
Sorry, but I don't have enough time. I'd suggest doing your best and adding all of your code representing your best effort to the answer. Right now, the question is pretty broad so I think narrowing things down will bring more eyes to your question. Implement the solution from the answer I linked to and try and understand how it is working. Then fork that plugin into a new version and start modifying it to suit your needs (modifying meta instead of post status).
在管理面板中同时显示所有帖子时,我有一个自定义列"精选图片".并且此列的值为YesOrNO.
要设置列名称:我在函数里面.php:
为了设置列值,我有:
是,我得到了预期的列名和值(即YesOrNo).在wordpress前端中,我想显示带有条件的帖子的特色图片.条件是:我需要在列值(即YesOrNo)上单击处理程序,以便可以按选择或取消选择它,并且我只想显示所选图像中的特色图像.
我该怎么做?