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です.
列名を設定するには:functions.php内にあります:
列の値を設定するために、次のものがあります:
はい、期待どおりに列の名前と値(つまり、YesOrNo)を取得します.ワードプレスのフロントエンドでは、条件付きの投稿の注目画像を表示したいと思います.条件は次のとおりです.選択したものと選択していないものを切り替えることができるように、列の値(つまり、YesOrNo)にクリックハンドラーが必要であり、選択したものからの注目の画像のみを表示したい.
どうすればよいですか?