{"id":1900,"date":"2014-08-08T16:25:15","date_gmt":"2014-08-08T16:25:15","guid":{"rendered":"http:\/\/musilda.cz\/?p=1900"},"modified":"2014-08-08T16:25:15","modified_gmt":"2014-08-08T16:25:15","slug":"zobrazeni-nahledoveho-obrazku-id-clanku-a-post-meta-ve-vypisu-clanku-v-administraci","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/zobrazeni-nahledoveho-obrazku-id-clanku-a-post-meta-ve-vypisu-clanku-v-administraci\/","title":{"rendered":"Zobrazen\u00ed n\u00e1hledov\u00e9ho obr\u00e1zku, id \u010dl\u00e1nku a post meta ve v\u00fdpisu \u010dl\u00e1nk\u016f v administraci"},"content":{"rendered":"

Pon\u011bkud krkolomn\u00fd titulek uv\u00e1d\u00ed \u010dl\u00e1nek, v kter\u00e9m se budu v\u011bnovat \u00faprav\u011b v\u00fdpisu \u010dl\u00e1nku v administraci. D\u00e1 se \u0159\u00edci, \u017ee navazuje na p\u0159edminul\u00fd \u010dl\u00e1nek, kdy jsme do v\u00fdpisu p\u0159idali zobrazen\u00ed status\u016f \u010dl\u00e1nku.<\/p>\n

Proto\u017ee se dost \u010dasto setk\u00e1v\u00e1m s t\u00edm, \u017ee p\u0159i v\u011bt\u0161\u00edm mno\u017estv\u00ed \u010dl\u00e1nk\u016f, je pom\u011brn\u011b zdlouhav\u00e9 a nep\u0159\u00edjemn\u00e9 otev\u0159\u00edt ka\u017ed\u00fd \u010dl\u00e1nek a zji\u0161\u0165ovat post id, nebo jin\u00e1 data. Uk\u00e1\u017eeme si tedy, jak p\u0159idat do v\u00fdpisu \u010dl\u00e1nk\u016f id postu, n\u00e1hledov\u00fd obr\u00e1zek a post meta.<\/p>\n

U post meta se zastav\u00edm. J\u00e1 sem zde zvolil post meta s n\u00e1zvem template, proto\u017ee si dovedu p\u0159edstavit, \u017ee hled\u00e1m jen \u010dl\u00e1nky se sidebarem vlevo. Ale vy m\u016f\u017eete pou\u017e\u00edt pro v\u00fdpis jakoukoliv hodnotu a m\u016f\u017eete si tak nap\u0159\u00edklad na\u010d\u00edtat po\u010det obsazen\u00fdch reklamn\u00edch pozic v \u010dl\u00e1nc\u00edch.<\/p>\n

Nyn\u00ed u\u017e samotn\u00fd k\u00f3d.<\/p>\n

Nejprve vytvo\u0159\u00edme funkci, pomoc\u00ed kter\u00e9 p\u0159id\u00e1me columns do v\u00fdpisu tabulky:<\/p>\n

\nadd_filter('manage_posts_columns', 'posts_columns', 5);\n\nfunction posts_columns($defaults){\n  $defaults['musilda_post_id']       = 'ID';\n  $defaults['musilda_post_thumbs']   = 'N\u00e1hled';\n  $defaults['musilda_post_template'] = '\u0160ablona';\n  return $defaults;\n}\n<\/pre>\n

Pomoc\u00ed manage_posts_columns jsme funkci p\u0159i\u0159adili pro v\u00fdpis \u010dl\u00e1nk\u016f. Pokud budeme cht\u00edt ud\u011blat obdobnou \u00fapravu pro str\u00e1nky, p\u0159id\u00e1me funkci do filtru manage_pages_columns.
\nNyn\u00ed vytvo\u0159\u00edme funkci pro zobrazen\u00ed hodnot jednotliv\u00fdch bun\u011bk:<\/p>\n

\nadd_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2);\n\nfunction posts_custom_columns($column_name, $id){\n  if($column_name === 'musilda_post_id'){\n    echo $id;\n  }\n  if($column_name === 'musilda_post_thumbs'){\n    echo the_post_thumbnail(array(50,50));\n  }\n  if($column_name === 'musilda_post_template'){\n    echo get_post_meta($id,'template',true);\n  }\n}\n<\/pre>\n

D\u00edky t\u011bmto dvou jednoduch\u00fdm funkc\u00edm se n\u00e1m v\u00fdpis zobrazuje takto:
\n\"P\u0159\u00edsp\u011bvky<\/a><\/p>\n

Par\u00e1da – nebo ne?<\/h3>\n

Bohu\u017eel to bude cht\u00edt je\u0161t\u011b jednu \u00fapravu. Funkce automaticky p\u0159i\u0159ad\u00ed hodnoty na konec pole. Osobn\u011b preferuji m\u00edt id \u010dl\u00e1nku hned za checkboxem pro hromadn\u00e9 \u00fapravy a za n\u00edm n\u00e1hledov\u00fd obr\u00e1zek. U post meta to je asi jedno. Tak\u017ee funkci mus\u00edme upravit:<\/p>\n

\nadd_filter('manage_posts_columns', 'posts_columns', 5);\n\nfunction posts_columns($defaults){\n  $new_columns = array();\n  $new_columns['cb']                    = '';\n  $new_columns['musilda_post_id']       = 'ID';\n  $new_columns['musilda_post_thumbs']   = 'N\u00e1hled';\n  $new_columns['title']                 = 'Title';\n  $new_columns['categories']            = 'Categories';\n  $new_columns['tags']                  = 'Tags';\n  $new_columns['date']                  = 'Date';\n  $new_columns['musilda_post_template'] = '\u0160ablona';\n\n  return $new_columns;\n\n}\n<\/pre>\n

\u00dapln\u00fdm z\u00e1v\u011brem trochu styl\u016f:<\/p>\n

\nadd_action('admin_head','musilda_columns_style');\nfunction musilda_columns_style(){\n  echo '\n    \n      #musilda_post_id,\n      #musilda_post_thumbs{\n        width:50px;\n      }\n    \n  ';\n}\n<\/pre>\n

Pokud si d\u011bl\u00e1te podobn\u00e9 \u00fapravy \u010dast\u011bji, vytvo\u0159te si css soubor pro administraci, a\u0165 necpete k\u00f3d zbyte\u010dn\u011b do hlavi\u010dky.<\/p>\n

\"P\u0159\u00edsp\u011bvky<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

Pon\u011bkud krkolomn\u00fd titulek uv\u00e1d\u00ed \u010dl\u00e1nek, v kter\u00e9m se budu v\u011bnovat \u00faprav\u011b v\u00fdpisu \u010dl\u00e1nku v administraci. D\u00e1 se \u0159\u00edci, \u017ee navazuje na p\u0159edminul\u00fd \u010dl\u00e1nek, kdy jsme do v\u00fdpisu p\u0159idali zobrazen\u00ed status\u016f \u010dl\u00e1nku. Proto\u017ee se dost \u010dasto setk\u00e1v\u00e1m s t\u00edm, \u017ee p\u0159i v\u011bt\u0161\u00edm mno\u017estv\u00ed \u010dl\u00e1nk\u016f, je pom\u011brn\u011b zdlouhav\u00e9 a nep\u0159\u00edjemn\u00e9 otev\u0159\u00edt ka\u017ed\u00fd \u010dl\u00e1nek a zji\u0161\u0165ovat post id,<\/p>\n","protected":false},"author":1,"featured_media":1484,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[12,19,30],"tags":[],"class_list":["post-1900","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","category-snippety","category-wordpress"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1900"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=1900"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1900\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/1484"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=1900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=1900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=1900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}