{"id":2106,"date":"2014-10-27T18:57:43","date_gmt":"2014-10-27T18:57:43","guid":{"rendered":"http:\/\/musilda.cz\/?p=2106"},"modified":"2014-10-27T18:57:43","modified_gmt":"2014-10-27T18:57:43","slug":"jak-pridat-vlastni-pole-ve-vypisu-clanku-v-administraci","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-pridat-vlastni-pole-ve-vypisu-clanku-v-administraci\/","title":{"rendered":"Jak p\u0159idat vlastn\u00ed pole ve v\u00fdpisu \u010dl\u00e1nk\u016f v administraci"},"content":{"rendered":"
Proto\u017ee se pod posledn\u00edm \u010dl\u00e1nkem objevila diskuze a dotaz, jak vlo\u017eit sloupec s informacemi do v\u00fdpisu \u010dl\u00e1nk\u016f v administraci, uk\u00e1\u017eeme si dnes, jak je to jednoduch\u00e9. Nejprve v\u0161ak mus\u00edm zareagovat na jednoho z diskutuj\u00edc\u00edch.<\/p>\n
Ano pluginy na to jsou a v\u0161echno si naklik\u00e1te. Jen\u017ee kdy\u017e budete v\u0161echno klikat pomoc\u00ed plugin\u016f, tak se nau\u010d\u00edte pr\u00e1v\u011b jen to – klikat.<\/p>\n
Nav\u00edc pluginy sebou p\u0159in\u00e1\u0161ej\u00ed spoustu k\u00f3du nav\u00edc, kter\u00fd obsahuje r\u016fzn\u00e1 nastaven\u00ed, jen\u017e t\u0159eba ani nevyu\u017eijete. A pokud pot\u0159ebujete rychl\u00e9 a jednoduch\u00e9 \u0159e\u0161en\u00ed, jsou dv\u011b funkce vlo\u017een\u00e9 do functions.php, to prav\u00e9.<\/p>\n
Nyn\u00ed k n\u00e1vodu. Postup si uk\u00e1\u017eeme na n\u00e1hledov\u00e9m obr\u00e1zku, kter\u00fd vlo\u017e\u00edme na za\u010d\u00e1tek \u0159\u00e1dku tabulky.<\/p>\n
Pou\u017eijeme tuto funkci<\/p>\n
\nadd_filter('manage_posts_columns', 'musilda_thumb_column');\nfunction musilda_thumb_column($columns) {\n $new_columns = array();\n foreach($columns as $key => $item){\n $new_columns[$key] = $item;\n if($key == 'cb'){\n $new_columns['thumb'] = __('N\u00e1hled','domain');\n }\n }\n\n return $new_columns;\n}\n<\/pre>\nFunkce je jednoduch\u00e1, ale mus\u00edm vysv\u011btlit, pro\u010d se proch\u00e1z\u00ed cel\u00fdm polem a znovu se generuje. Kdy\u017e toti\u017e pole „nep\u0159erovn\u00e1te“, tak se $columns[‚thumb‘] = __(‚N\u00e1hled‘,’domain‘); vlo\u017e\u00ed na konec a n\u00e1hledov\u00fd obr\u00e1zek bude na konci \u0159\u00e1dku. Proto jej um\u00edst\u00edme hned za checkbox, kter\u00fd m\u00e1 id „cb“.
\nDruh\u00e1 funkce je<\/p>\n
\nadd_filter('manage_posts_custom_column', 'manage_musilda_thumb_column', 10, 2);\nfunction manage_musilda_thumb_column($column_name, $post_id) {\n global $post;\n if( $column_name == 'thumb' ) {\n echo the_post_thumbnail(array(100,100));\n }\n}\n<\/pre>\nTa jen zajist\u00ed v\u00fdpis toho co pot\u0159ebujeme. Pokud tam budeme cht\u00edt m\u00edt custom field, ve funkci m\u00edsto the_post_thumbnail bude n\u011bjak\u00e9 get_post_meta. Z\u00e1le\u017e\u00ed jen na v\u00e1s.<\/p>\n
A to je v\u0161e.
\nStav p\u0159ed
\n<\/a><\/p>\n