{"id":5905,"date":"2021-04-12T12:25:50","date_gmt":"2021-04-12T12:25:50","guid":{"rendered":"https:\/\/musilda.cz\/?p=5905"},"modified":"2021-04-12T12:25:50","modified_gmt":"2021-04-12T12:25:50","slug":"jak-omezit-odkaz-pouze-na-obrazek-v-loopu-produktu","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-omezit-odkaz-pouze-na-obrazek-v-loopu-produktu\/","title":{"rendered":"Jak omezit odkaz pouze na obr\u00e1zek v loopu produktu"},"content":{"rendered":"\n

Ve v\u00fdpisu produkt\u016f zahrnuje odkaz na detail produktu obr\u00e1zek, n\u00e1zev produktu i cenu. Pokud pot\u0159ebujete mezi cenu a n\u00e1zev p\u0159idat jin\u00e9 prvky, m\u016f\u017ee to b\u00fdt probl\u00e9m. <\/p>\n\n\n\n

Jak Woocommerce skl\u00e1d\u00e1 jednotliv\u00e9 prvky?<\/strong><\/p>\n\n\n\n

  1. Prvn\u00ed je hook woocommerce_before_shop_loop_item a ten obsahuje funkci s otev\u00edrac\u00ed \u010d\u00e1st\u00ed tagu A. <\/li>
  2. Druh\u00fd je woocommerce_before_shop_loop_item_title, kter\u00fd obsahuje sale flash a obr\u00e1zek produktu.<\/li>
  3. T\u0159et\u00ed je woocommerce_shop_loop_item_title – n\u00e1zev produktu.<\/li>
  4. N\u00e1sleduje woocommerce_after_shop_loop_item_title a v n\u011bm je hodnocen\u00ed a cena produktu.<\/li>
  5. Nakonec woocommerce_after_shop_loop_item, kde je kone\u010dn\u011b uzav\u00edrac\u00ed \u010d\u00e1st tagu A. Za n\u00edm je je\u0161t\u011b tla\u010d\u00edtko „P\u0159idat do ko\u0161\u00edku“.<\/li><\/ol>\n\n\n\n

    V\u0161echno co se nach\u00e1z\u00ed mezi body 1 a\u017e 5, je uvnit\u0159 odkazu. C\u00edlem \u00fapravy je uzav\u0159\u00edt do odkazu obr\u00e1zek a sale flash a vytvo\u0159it odkaz z n\u00e1zvu produktu, tak aby bylo mo\u017en\u00e9 p\u0159id\u00e1vat prvky nad a pod n\u00e1zev produktu, bez toho, aby byli uvnit\u0159 odkazu.<\/p>\n\n\n\n

    Postup<\/h2>\n\n\n\n

    Nejprve odebereme z loopu uzav\u00edrac\u00ed tag odkazu:<\/p>\n\n\n\n

    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );<\/code><\/pre>\n\n\n\n

    P\u0159esuneme jej za obr\u00e1zek:<\/p>\n\n\n\n

    add_action( ‚woocommerce_before_shop_loop_item_title‘, ‚woocommerce_template_loop_product_link_close‘, 20 );<\/p>\n\n\n\n

    Nakonec uprav\u00edme n\u00e1zev produktu, kter\u00fd je aktu\u00e1ln\u011b vypisov\u00e1n jako H2 nadpis, co\u017e lze ud\u011blat dv\u011bma zp\u016fsoby.<\/p>\n\n\n\n

    1. vyu\u017eit\u00edm toho, \u017ee funkce woocommerce_template_loop_product_title je uzav\u0159en\u00e1 ve podm\u00ednce a funkci function_exists. To n\u00e1m umo\u017e\u0148uje do functions.php vlo\u017eit rovnou celou funkci a p\u0159epsat jej\u00ed k\u00f3d:<\/p>\n\n\n\n

    function woocommerce_template_loop_product_title() {\n        echo '<h2 class=\"' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '\"><a href=\"' . get_the_permalink() . '\">' . get_the_title() . '<\/a><\/h2>';\n    }<\/code><\/pre>\n\n\n\n

    2. Nebo funkci deregistrovat a zaregistrovat si vlastn\u00ed<\/p>\n\n\n\n

    remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );\nadd_action( 'woocommerce_shop_loop_item_title', 'musilda_template_loop_product_title', 10 );\nfunction musilda_template_loop_product_title() {\n        echo '<h2 class=\"' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '\"><a href=\"' . get_the_permalink() . '\">' . get_the_title() . '<\/a><\/h2>';\n    }<\/code><\/pre>\n\n\n\n

    A m\u00e1me hotovo. Budu se t\u011b\u0161it u dal\u0161\u00edho n\u00e1vodu.<\/p>\n\n\n\n

    Dal\u0161\u00ed u\u017eite\u010dn\u00e9 snippety najdete na str\u00e1nce U\u017eite\u010dn\u00e9 snippety pro WooCommerce<\/a><\/strong> <\/p>\n","protected":false},"excerpt":{"rendered":"

    Ve v\u00fdpisu produkt\u016f zahrnuje odkaz na detail produktu obr\u00e1zek, n\u00e1zev produktu i cenu. Pokud pot\u0159ebujete mezi cenu a n\u00e1zev p\u0159idat jin\u00e9 prvky, m\u016f\u017ee to b\u00fdt probl\u00e9m. Jak Woocommerce skl\u00e1d\u00e1 jednotliv\u00e9 prvky? Prvn\u00ed je hook woocommerce_before_shop_loop_item a ten obsahuje funkci s otev\u00edrac\u00ed \u010d\u00e1st\u00ed tagu A. Druh\u00fd je woocommerce_before_shop_loop_item_title, kter\u00fd obsahuje sale flash a obr\u00e1zek produktu. T\u0159et\u00ed<\/p>\n","protected":false},"author":1,"featured_media":5600,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[19,29],"tags":[],"class_list":["post-5905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-snippety","category-woocommerce-snippety"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5905"}],"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=5905"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5905\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/5600"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=5905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=5905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=5905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}