סניפט שימושי ומעניין אשר מורכב מכמה חתיכות לצרכים שונים
- שליפת POST/PAGE ID בתבנית OCEAN WP – משום מה בתבנית הנ"ל שום שניפט של שליפת ID לא עובד
- שימוש בOB_START ו OB_GET_CLEAN על מנת לוודא שהקוד יופיע במקום שהוגדר ולא בראש הדף
- שימוש בשורטקוד שמשנה את מבנה הטאגים באתר TAGS
- שתילת שדה נוסף CUSTOM FIELDS ACF
add_action('template_redirect', function() { $post_id = get_queried_object_id(); add_shortcode('specialize','specialize'); function specialize(){ ob_start(); // Tags if ( has_tag() ) { //get_template_part( 'partials/single/tags' ); echo the_tags('<strong>'.__('תחומי התמחות: ','Machshava').'</strong><span>','|',''); } return ob_get_clean(); } add_shortcode('lang','lang'); function lang(){ ob_start(); if(get_field( 'languages', $post_id) != null){ echo ('<strong>'.__('שפות: ','Machshava').'</strong><span>'.get_field( 'languages', $post_id).'</span>'); } return ob_get_clean(); } });
שליפת ID קטגוריה לא רק בOCEAN
add_action('template_redirect','gs_get_category_id'); function gs_get_category_id(){ global $post; $terms = get_the_terms( $post->ID, 'product_cat' ); $cat_id = $terms[0]->term_id; echo $cat_id; }
add_action('template_redirect','gs_get_category_id'); function gs_get_category_id(){ global $post; $terms = get_the_terms( $post->ID, 'product_cat' ); $nterms = get_the_terms( $post->ID, 'product_tag' ); foreach ($terms as $term ) { $product_cat_id = $term->term_id; $product_cat_name = $term->name; break; } }