{"id":1278,"date":"2013-11-06T18:57:40","date_gmt":"2013-11-06T18:57:40","guid":{"rendered":"http:\/\/musilda.cz\/?p=1278"},"modified":"2013-11-06T18:57:40","modified_gmt":"2013-11-06T18:57:40","slug":"funkce-get_children","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/funkce-get_children\/","title":{"rendered":"Funkce get_children"},"content":{"rendered":"
Funkce get_children vrac\u00ed podstr\u00e1nky, revize a p\u0159\u00edlohy, tedy attachment, jako jsou obr\u00e1zky a jin\u00e9 soubory p\u0159ilo\u017een\u00e9 k postu. Funguje podobn\u011b jako get_posts a do verze 3.6 byla jedin\u00fdm zp\u016fsobem, jak z\u00edskat obr\u00e1zky p\u0159i\u0159azen\u00e9 k \u010dl\u00e1nku.
\nPou\u017eit\u00ed:<\/p>\n
\n$children = get_children( $args = \"\", $output = OBJECT);\n<\/pre>\nParametry:<\/strong><\/p>\n$arg – seznam argument\u016f pro v\u00fdpis, podobn\u00e9 jako u WP_Query a get_posts.<\/p>\n
P\u0159\u00edklad:<\/strong><\/p>\n\n$defaults = array(\n 'post_parent' => 0,\n 'post_type' => 'any',\n 'numberposts' => -1,\n 'post_status' => 'any'\n);\n<\/pre>\nNejd\u016fle\u017eit\u011bj\u0161\u00edm je post_mime_type, kter\u00fd ur\u010duje o jak\u00fd druh p\u0159ilo\u017een\u00e9ho souboru jde. Je samoz\u0159ejm\u011b z\u00e1visl\u00fd na post_type, kter\u00e9 mus\u00ed b\u00fdt attachment. M\u016f\u017eete tak vypsat image, video, audio. Pro seznam v\u0161ech typ\u016f hledejte post_mime_type v Codexu WordPressu.<\/p>\n
$output – ur\u010duje, zda bude vr\u00e1cen objekt, nebo pole, defaultn\u011b OBJECT. M\u016f\u017ee nab\u00fdvat t\u011bchto hodnot OBJECT, ARRAY_A, ARRAY_N.<\/p>\n
P\u0159\u00edklad pro v\u00fdpis prvn\u00edho obr\u00e1zku, p\u0159i\u0159azen\u00e9ho k postu. D\u00e1 se vyu\u017e\u00edt jako n\u00e1hrada za thumbnail image, pokud si nejste jisti, zda jsou vlo\u017een\u00e9.<\/p>\n
\nfunction echo_first_image( $postID ) {\n\t$args = array(\n\t\t'numberposts' => 1,\n\t\t'order' => 'ASC',\n\t\t'post_mime_type' => 'image',\n\t\t'post_parent' => $postID,\n\t\t'post_status' => null,\n\t\t'post_type' => 'attachment',\n\t);\n\n\t$attachments = get_children( $args );\n\nif ( $attachments ) {\n\tforeach ( $attachments as $attachment ) {\n$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'thumbnail' ) ?\nwp_get_attachment_image_src( $attachment->ID, 'thumbnail' ) :\nwp_get_attachment_image_src( $attachment->ID, 'full' );\n\necho '
ID ) . '\" class=\"current\">';\n\t\t}\n\t}\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"Funkce get_children vrac\u00ed podstr\u00e1nky, revize a p\u0159\u00edlohy, tedy attachment, jako jsou obr\u00e1zky a jin\u00e9 soubory p\u0159ilo\u017een\u00e9 k postu. Funguje podobn\u011b jako get_posts a do verze 3.6 byla jedin\u00fdm zp\u016fsobem, jak z\u00edskat obr\u00e1zky p\u0159i\u0159azen\u00e9 k \u010dl\u00e1nku.<\/p>\n","protected":false},"author":1,"featured_media":8523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,15],"tags":[170],"class_list":["post-1278","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codex","category-post-funkce","tag-get_children"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1278"}],"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=1278"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1278\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8523"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=1278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=1278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=1278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}