{"id":2077,"date":"2014-10-12T18:56:21","date_gmt":"2014-10-12T18:56:21","guid":{"rendered":"http:\/\/musilda.cz\/?p=2077"},"modified":"2014-10-12T18:56:21","modified_gmt":"2014-10-12T18:56:21","slug":"funkce-get_post_ancestors","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/funkce-get_post_ancestors\/","title":{"rendered":"Funkce get_post_ancestors"},"content":{"rendered":"
Funkce get_post_ancestors je dal\u0161\u00ed z funkc\u00ed, pro manipulaci s posty. P\u0159i jej\u00edm pou\u017eit\u00ed v\u00e1m vr\u00e1t\u00ed pole v\u0161ech rodi\u010dovsk\u00fdch (nad\u0159azen\u00fdch) post\u016f, v z\u00e1vislosti na post ID.<\/p>\n
get_post_ancestors( $post );<\/pre>\nParametry<\/h3>\n
Funkce m\u00e1 pouze jeden parametr $post a t\u00edm je bu\u010f ID postu, nebo object $post.<\/p>\n
Jak jsem psal ji\u017e v\u00fd\u0161e, funkce prac\u00ed pole ID v\u0161ech rodi\u010dovsk\u00fdch post\u016f, nebo pr\u00e1zdnou hodnotu, pokud nen\u00ed nalezen \u017e\u00e1dn\u00fd ancestor. Jako prvn\u00ed v poli je nejbli\u017e\u0161\u00ed rodi\u010dovsk\u00fd post a posledn\u00edm je nejvy\u0161\u0161\u00ed nad\u0159azen\u00fd.<\/p>\n
P\u0159\u00edklady<\/h3>\n
Tento p\u0159\u00edklad vr\u00e1t\u00ed nejv\u00fd\u0161e postavenou nad\u0159azenou str\u00e1nku pro aktu\u00e1ln\u00ed str\u00e1nku a z\u00edsk\u00e1 jej\u00ed slug, pro body class.<\/p>\n
\n$class = '';\nif( is_page() ) {\n global $post;\n $parents = get_post_ancestors( $post->ID );\n $id = ($parents) ? $parents[count($parents)-1]: $post->ID;\n $parent = get_page( $id );\n $class = $parent->post_name;\n}\n<\/pre>\nPodobn\u00fdm zp\u016fsobem dostaneme nap\u0159\u00edklad n\u00e1hledov\u00fd obr\u00e1zek nejv\u00fd\u0161e polo\u017een\u00e9 str\u00e1nky, k aktu\u00e1ln\u00ed.<\/p>\n
\nglobal $post;\n$parents = get_post_ancestors( $post->ID );\n$id = ($parents) ? $parents[count($parents)-1]: $post->ID;\nif(has_post_thumbnail( $id )) {\n\tget_the_post_thumbnail( $id, 'thumbnail');\n}\n<\/pre>\nK\u00f3d p\u0159\u00edklad\u016f je p\u0159evzat z WordPress.org<\/p>\n","protected":false},"excerpt":{"rendered":"
Funkce get_post_ancestors je dal\u0161\u00ed z funkc\u00ed, pro manipulaci s posty. P\u0159i jej\u00edm pou\u017eit\u00ed v\u00e1m vr\u00e1t\u00ed pole v\u0161ech rodi\u010dovsk\u00fdch (nad\u0159azen\u00fdch) post\u016f, v z\u00e1vislosti na post ID.<\/p>\n","protected":false},"author":1,"featured_media":8523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[7,15],"tags":[],"class_list":["post-2077","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codex","category-post-funkce"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/2077"}],"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=2077"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/2077\/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=2077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=2077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=2077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}