function generate_ryuzine_stylesheets() { // verify this came from the our screen and with proper authorization. if (!wp_verify_nonce($_POST['ryu_regenstyles_noncename'], 'ryuzine-regenstyles_install')) { return; } // Check permissions if (!current_user_can('administrator')) { echo "<div class='error'><p>Sorry, you do not have the correct priveledges to install the files.</p></div>"; return; } $my_query = null; $my_query = new WP_Query(array('post_type' => 'ryuzine')); if ($my_query->have_posts()) { while ($my_query->have_posts()) { $my_query->the_post(); $stylesheet = ""; $issuestyles = get_post_meta(get_the_ID(), '_ryustyles', false); if (!empty($issuestyles)) { foreach ($issuestyles as $appendstyle) { // If there are multiple ryustyles append them // $stylesheet = $stylesheet . $appendstyle; } } if ($stylesheet != "") { ryu_create_css($stylesheet, get_the_ID()); } } } // reset css check // // update_option('ryu_css_admin',0); wp_reset_query(); return; }
/** * Outputs any floor plan links for virtual tours on the property templates * * When the hook epl_buttons_single_property is used and the property * has floor plans links they will be output on the template */ function epl_button_floor_plan() { $floor_plan = get_post_meta(get_the_ID(), 'property_floorplan', true); $floor_plan_2 = get_post_meta(get_the_ID(), 'property_floorplan_2', true); $links = array(); if (!empty($floor_plan)) { $links[] = $floor_plan; } if (!empty($floor_plan_2)) { $links[] = $floor_plan_2; } if (!empty($links)) { foreach ($links as $k => $link) { if (!empty($link)) { $number_string = ''; if ($k > 0) { $number_string = ' ' . $k + 1; } ?> <span class="epl-floor-plan-button-wrapper<?php echo $number_string; ?> "> <button type="button" class="epl-button epl-floor-plan" onclick="location.href='<?php echo $link; ?> '"><?php echo apply_filters('epl_button_label_floorplan', __('Floor Plan', 'epl')) . $number_string; ?> </button></span><?php } } } }
public function parse_lists_in_post($content) { $this->post_ID = get_the_ID(); $this->comment_ID = ''; $this->user_can_edit_object = $this->current_user_can_edit_checklist('post', $this->post_ID); return $this->parse_lists($content); }
function widget($args, $instance) { extract($args, EXTR_SKIP); $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); $sticky = get_option('sticky_posts'); $number = empty($instance['number']) ? 1 : (int) $instance['number']; $cat = empty($instance['category']) ? 0 : (int) $instance['category']; if (is_single()) { array_push($sticky, get_the_ID()); } echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } else { echo '<br />'; } $featuredPosts = new WP_Query(array('posts_per_page' => $number, 'cat' => $cat, 'post__not_in' => $sticky, 'no_found_rows' => true)); while ($featuredPosts->have_posts()) { $featuredPosts->the_post(); global $mb_content_area, $more; $mb_content_area = 'sidebar'; get_template_part('content', get_post_format()); } wp_reset_postdata(); echo $after_widget; }
function ewic_popup_content() { if (strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php')) { if (get_post_type(get_the_ID()) != 'easyimageslider') { // START GENERATE POPUP CONTENT ?> <div id="ewicmodal" style="display:none;"> <div id="tinyform" style="width: 550px;"> <form method="post"> <div class="ewic_input" id="ewictinymce_select_slider_div"> <label class="label_option" for="ewictinymce_select_slider">Slider</label> <select class="ewic_select" name="ewictinymce_select_slider" id="ewictinymce_select_slider"> <option id="selectslider" type="text" value="select">- Select Slider -</option> </select> <div class="clearfix"></div> </div> <div class="ewic_button"> <input type="button" value="Insert Shortcode" name="ewic_insert_scrt" id="ewic_insert_scrt" class="button-secondary" /> <div class="clearfix"></div> </div> </form> </div> </div> <?php } } //END }
function moxie_press_endpoint_data() { global $wp_query; // get query vars $json = $wp_query->get('json'); $name = $wp_query->get('name'); // use this template redirect only if json is requested if ($json != 'true') { return; } // build the query $movie_data = array(); // default args $args = array('post_type' => 'movie', 'posts_per_page' => 100); if ($name != '') { $args['name'] = $name; } // add name if provided in query // check if this particular request is cached, if not, perform the query if (false === ($moxie_cached_request = get_transient('moxie_cached_request_' . json_encode($args)))) { $moxie_cached_request = new WP_Query($args); set_transient('moxie_cached_request_' . json_encode($args), $moxie_cached_request); } // prepare the object we want to send as response if ($moxie_cached_request->have_posts()) { while ($moxie_cached_request->have_posts()) { $moxie_cached_request->the_post(); $id = get_the_ID(); $movie_data[] = array('id' => $id, 'title' => get_the_title(), 'poster_url' => get_post_meta($id, 'moxie_press_poster_url', true), 'rating' => get_post_meta($id, 'moxie_press_rating', true), 'year' => get_post_meta($id, 'moxie_press_year', true), 'short_description' => get_post_meta($id, 'moxie_press_description', true), 'mdbid' => get_post_meta($id, 'moxie_press_mdbid', true)); } wp_reset_postdata(); } // send json data using built-in WP function wp_send_json(array('data' => $movie_data)); }
function cats() { foreach (wp_get_post_categories(get_the_ID()) as $c) { $cat = get_category($c); return ' - <a href="' . get_category_link($cat) . '" title="' . $cat->name . '" class="category">' . $cat->name . '</a>'; } }
public function widget($args, $instance) { if (!is_singular()) { return; } $the_id = get_the_ID(); if (!comments_open($the_id)) { return; } else { $html = $args['before_widget']; if (!empty($instance['title'])) { $html .= $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; } $api_url = esc_url(home_url('/')) . 'wp-json/wp/v2/comments'; $author = __('NAME:', 'rest-api-widgets'); $mailaddress = __('MAIL:', 'rest-api-widgets'); $content = __('COMMENTS:', 'rest-api-widgets'); $send_btn = __('SEND', 'rest-api-widgets'); $success_text = __('Success! Reload now.', 'rest-api-widgets'); $fail_text = __('Fail :(', 'rest-api-widgets'); $html .= "<form action={$api_url} method='post' id='rest-api-widgets-comment'>"; $html .= '<dl>'; $html .= "<dt>{$author}</dt><dd><input name='author_name' value=''></dd>"; $html .= "<dt>{$mailaddress}</dt><dd><input name='author_email' value=''></dd>"; $html .= "<dt>{$content}</dt><dd><textarea name='content' id=' cols='30' rows='10'></textarea></dd>"; $html .= '</dl>'; $html .= "<input type='hidden' name='post' value='{$the_id}'>"; $html .= "<input type='hidden' name='success_text' value='{$success_text}'>"; $html .= "<input type='hidden' name='fail_text' value='{$fail_text}'>"; $html .= "<button>{$send_btn}</button>"; $html .= '</form>'; } echo $html . $args['after_widget']; }
/** * This is a reusable function that allows us to grab place-specific data and * return it in a consistent way across our plugin scripts, and in theme * template files as well. */ function wanderlist_place_data($data, $post_ID = null) { switch ($data) { case 'country': // We need to figure out our place's country. Here we go. $countries = wp_get_object_terms(get_the_ID(), 'wanderlist-country', array('fields' => 'names')); if ($countries) { $count = 0; foreach ($countries as $country => $name) { if (0 === $count) { $output = $name; } else { $output .= ', ' . $name; } $count++; } } else { $output = ''; } break; case 'city': $output = get_post_meta($post_ID, 'wanderlist-city', true); break; case 'lat': $output = get_post_meta($post_ID, 'wanderlist-lat', true); break; case 'lng': $output = get_post_meta($post_ID, 'wanderlist-lng', true); break; } return $output; }
/** * change_add_to_cart_button_text. */ public function change_add_to_cart_button_text($add_to_cart_text, $single_or_archive) { $product_categories = get_the_terms(get_the_ID(), 'product_cat'); if (empty($product_categories)) { return $add_to_cart_text; } for ($i = 1; $i <= apply_filters('wcj_get_option_filter', 1, get_option('wcj_add_to_cart_per_category_total_groups_number', 1)); $i++) { if ('yes' !== get_option('wcj_add_to_cart_per_category_enabled_group_' . $i)) { continue; } // $categories = array_filter( explode( ',', get_option( 'wcj_add_to_cart_per_category_group_' . $i ) ) ); $categories = get_option('wcj_add_to_cart_per_category_ids_group_' . $i); if (empty($categories)) { continue; } foreach ($product_categories as $product_category_id => $product_category) { foreach ($categories as $category) { if ($product_category_id == $category) { return get_option('wcj_add_to_cart_per_category_text_' . $single_or_archive . '_group_' . $i, $add_to_cart_text); } } } } return $add_to_cart_text; }
/** * Echo the client address * @param integer $id * @return string */ function si_client_address($id = 0) { if (!$id) { $id = get_the_ID(); } echo apply_filters('si_client_address', si_address(si_get_client_address($id)), $id); }
/** * Render Wish List Columns * * @since 1.0 * @param string $column_name Column name * @param int $post_id Download (Post) ID * @return void */ function edd_wl_render_admin_columns($column_name, $post_id) { if (get_post_type($post_id) == 'edd_wish_list') { $items = get_post_meta(get_the_ID(), 'edd_wish_list', true); switch ($column_name) { case 'downloads': if ($items) { echo count($items); } else { echo 0; } break; case 'total': echo edd_wl_get_list_total(get_the_ID()); break; case 'list_author': $post = get_post(); if (0 == $post->post_author) { echo __('Guest', 'edd-wish-lists'); } else { printf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, 'author' => get_the_author_meta('ID')), 'edit.php')), get_the_author()); } break; } } }
function add_doctrinal_statement_JS() { wp_register_script('doctrinal-statement', get_stylesheet_directory_uri() . '/JS/doctrine.min.js', array('jquery')); if (get_the_ID() == '8') { wp_enqueue_script('doctrinal-statement'); } }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $number = $instance['number']; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <div class="recent-works-items clearfix"> <?php $args = array('post_type' => 'evolve_portfolio', 'posts_per_page' => $number, 'has_password' => false); $portfolio = new WP_Query($args); if ($portfolio->have_posts()) { ?> <?php while ($portfolio->have_posts()) { $portfolio->the_post(); ?> <?php if (has_post_thumbnail()) { ?> <?php $link_target = ""; $url_check = get_post_meta(get_the_ID(), 'pyre_link_icon_url', true); if (!empty($url_check)) { $new_permalink = get_post_meta(get_the_ID(), 'pyre_link_icon_url', true); if (get_post_meta(get_the_ID(), 'pyre_link_icon_target', true) == "yes") { $link_target = ' target="_blank"'; } } else { $new_permalink = get_permalink(); } ?> <a href="<?php echo $new_permalink; ?> "<?php echo $link_target; ?> title="<?php the_title(); ?> "> <?php the_post_thumbnail('recent-works-thumbnail'); ?> </a> <?php } } } wp_reset_query(); ?> </div> <?php echo $after_widget; }
/** * Output for Shortcode * * @since 1.1.9 * * @param $atts * * @return mixed|null */ function shortcode_output($atts) { $default_atts = array('key' => '', 'field' => '', 'job_id' => get_the_ID()); $merged_atts = array_merge($default_atts, $atts); try { // Attributes $args = shortcode_atts($merged_atts, $atts, 'jmfe'); if (empty($args['key']) && empty($args['field'])) { throw new Exception(__('Meta Key was not specified!', 'wp-job-manager-field-editor')); } if (empty($args['job_id'])) { throw new Exception(__('Unable to determine correct job/resume/post ID!', 'wp-job-manager-field-editor')); } if ($args['key']) { $meta_key = $args['key']; } if ($args['field']) { $meta_key = $args['field']; } ob_start(); the_custom_field($meta_key, $args['job_id'], $args); $shortcode_output = ob_get_contents(); ob_end_clean(); return $shortcode_output; } catch (Exception $error) { error_log('Shortcode output error: ' . $error->getMessage()); } }
function foundation_featured_setup() { if (function_exists('add_theme_support')) { add_theme_support('post-thumbnails'); add_image_size('foundation-featured-image', 900, 9999, false); } global $foundation_featured_posts; $settings = foundation_get_settings(); $args = foundation_featured_get_args(); if ($settings->featured_enabled) { $slides = foundation_featured_get_slides(); $slide_count = 0; if ($slides->post_count > 0) { while ($slides->have_posts() && $slide_count < $args['num']) { $slides->the_post(); $image = foundation_featured_has_image(); if ($image) { $slide_count++; $foundation_featured_posts[] = get_the_ID(); } } } } add_filter('parse_query', 'foundation_featured_modify_query'); }
function wpex_gallery_is_lightbox_enabled() { $link_images = get_post_meta(get_the_ID(), '_easy_image_gallery_link_images', true); if ('on' == $link_images) { return true; } }
public function filter_content($content) { // Get Templates $templates = self::get_option('rwp_templates'); $terms = wp_get_object_terms(get_the_ID(), array_keys(get_taxonomies())); $terms_keys = array(); foreach ($terms as $term) { $terms_keys[$term->taxonomy][] = $term->term_id; } //self::pretty_print( $terms_keys ); foreach ($templates as $template) { if (isset($template['template_auto_reviews']) && !empty($template['template_auto_reviews'])) { if (is_singular($template['template_auto_reviews']) && is_main_query()) { if (isset($template['template_exclude_terms'])) { $to_exclude = false; foreach ($template['template_exclude_terms'] as $id) { $i = explode('-', $id); if (in_array($i[1], $terms_keys[$i[0]])) { $to_exclude = true; break; } } if ($to_exclude) { continue; } } $new_content = '[rwp-review id="-1" template="' . $template['template_id'] . '"]'; $content .= $new_content; } } } return $content; }
function x_shortcode_toc_item($atts) { extract(shortcode_atts(array('id' => '', 'class' => '', 'style' => '', 'title' => '', 'page' => ''), $atts, 'x_toc_item')); $id = $id != '' ? 'id="' . esc_attr($id) . '"' : ''; $class = $class != '' ? 'x-toc-item ' . esc_attr($class) : 'x-toc-item'; $style = $style != '' ? 'style="' . $style . '"' : ''; $title = $title != '' ? $title : ''; switch ($page) { case 0: $page = ''; break; case 1: $page = ''; break; default: $page = $page; if (get_post_status(get_the_ID()) == "draft") { $page = '&page=' . $page; } else { $page = get_the_ID() == get_option('page_on_front') ? 'page/' . $page . '/' : $page . '/'; } } $link = esc_url(get_permalink()); $output = "<li {$id} class=\"{$class}\" {$style}><a href=" . $link . $page . " title=\"Go to {$title}\">" . $title . '</a></li>'; return $output; }
function al_portfolio_meta_tags() { $post_type = get_post_type(); if ('portfolio' == $post_type) { $title = get_post_meta(get_the_ID(), "al_pf_og_title", TRUE); $title = !empty($title) ? $title : get_the_title(); $meta = array('og:title' => $title, 'og:url' => get_permalink()); $desc = get_post_meta(get_the_ID(), "al_pf_og_description", TRUE); $desc = !empty($desc) ? $desc : false; if ($desc) { $meta['og:description'] = $desc; } if (has_post_thumbnail()) { $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); $meta['og:image'] = $thumbnail[0]; } if (get_post_format() == 'gallery') { $images = rwmb_meta('al_pf_gallery_images', 'type=image&size=full'); if (is_array($images)) { foreach ($images as $image) { $meta['images'][] = $image['url']; } } } foreach ($meta as $key => $value) { if ($key == 'images') { foreach ($value as $image) { echo '<meta property="og:image" content="' . $image . '" />'; } } else { echo '<meta property="' . $key . '" content="' . $value . '" />'; } } } }
/** * manage_posts_custom_column * @param string $column_name * @param int $post_id */ public function manage_posts_custom_column($column_name, $post_id) { $this->assign('post_id', get_the_ID()); if ($column_name === 'mwform_form_key') { $this->render('admin-list/form-key'); } }
public function gather_products_data(&$products_info) { //return array(); $args = array('post_type' => 'product', 'posts_per_page' => -1); $loop = new WP_Query($args); if ($loop->have_posts()) { while ($loop->have_posts()) { $loop->the_post(); $the_ID = get_the_ID(); //$the_product = new WC_Product( $the_ID ); $the_product = wc_get_product($the_ID); $the_price = $the_product->get_price(); $the_stock = $the_product->get_total_stock(); //if ( 0 == $the_stock ) //$the_stock = get_post_meta( $the_ID, '_stock', true ); $the_title = get_the_title(); $the_categories = $the_product->get_categories(); $the_date = get_the_date(); $the_permalink = get_the_permalink(); $post_custom = get_post_custom($the_ID); $total_sales = isset($post_custom['total_sales'][0]) ? $post_custom['total_sales'][0] : 0; //$available_variations = $the_product->get_available_variations(); $purchase_price = wc_get_product_purchase_price($the_ID); $sales_in_day_range = array(); foreach ($this->ranges_in_days as $the_range) { $sales_in_day_range[$the_range] = 0; } $products_info[$the_ID] = array('ID' => $the_ID, 'title' => $the_title, 'category' => $the_categories, 'permalink' => $the_permalink, 'price' => $the_price, 'stock' => $the_stock, 'stock_price' => $the_price * $the_stock, 'total_sales' => $total_sales, 'date_added' => $the_date, 'purchase_price' => $purchase_price, 'last_sale' => 0, 'sales_in_period' => $sales_in_day_range); } } }
function sfhiv_add_event_filter() { $archive_type = mini_archive_on_page(get_the_ID()); if (is_page() && $archive_type && $archive_type == 'event') { get_template_part("nav", "event"); } }
/** * Shortcode Post ID getter. * If post id isn't set try to get from get_the_ID function. * @since 4.4 * @return int|bool; */ public function postId() { if (false === $this->post_id) { $this->post_id = get_the_ID(); } return $this->post_id; }
function cscf_ContactForm() { $contact = new cscf_Contact(); if ($contact->IsValid()) { if ($contact->SendMail()) { $view = new CSCF_View('message-sent'); $view->Set('heading', cscf_PluginSettings::SentMessageHeading()); $view->Set('message', cscf_PluginSettings::SentMessageBody()); } else { $view = new CSCF_View('message-not-sent'); } return $view->Render(); } //here we need some jquery scripts and styles, so load them here if (cscf_PluginSettings::UseClientValidation() == true) { wp_enqueue_script('jquery-validate'); wp_enqueue_script('cscf-validate'); } //only load the stylesheet if required if (cscf_PluginSettings::LoadStyleSheet() == true) { wp_enqueue_style('cscf-bootstrap'); } $messageSentView = new CSCF_View('message-sent'); $messageSentView->Set('heading', cscf_PluginSettings::SentMessageHeading()); $messageSentView->Set('message', cscf_PluginSettings::SentMessageBody()); $view = new CSCF_View('contact-form'); $view->Set('contact', $contact); $view->Set('message', cscf_PluginSettings::Message()); $view->Set('version', CSCF_VERSION_NUM); $view->Set('confirmEmail', cscf_PluginSettings::ConfirmEmail()); $view->Set('postID', get_the_ID()); $view->Set('messageSentView', $messageSentView); $view->Set('messageNotSentView', new CSCF_View('message-not-sent')); return $view->Render(); }
function widget($args, $instance) { global $post; // Preserve global $post $preserve = $post; extract($args); // only useful on post pages if (!is_single()) { return; } $title = apply_filters('widget_title', empty($instance['title']) ? __('Read Next', 'largo') : $instance['title'], $instance, $this->id_base); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $related = new Largo_Related($instance['qty']); //get the related posts $rel_posts = new WP_Query(array('post__in' => $related->ids(), 'nopaging' => 1, 'posts_per_page' => $instance['qty'], 'ignore_sticky_posts' => 1)); if ($rel_posts->have_posts()) { echo '<ul class="related">'; while ($rel_posts->have_posts()) { $rel_posts->the_post(); echo '<li>'; echo '<a href="' . get_permalink() . '"/>' . get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class' => 'alignleft')) . '</a>'; ?> <h4><a href="<?php the_permalink(); ?> " title="Read: <?php esc_attr(the_title('', '', FALSE)); ?> "><?php the_title(); ?> </a></h4> <h5 class="byline"> <span class="by-author"><?php largo_byline(true, true); ?> </span> <time class="entry-date updated dtstamp pubdate" datetime="<?php echo esc_attr(get_the_date('c')); ?> "><?php largo_time(); ?> </time> </h5> <?php // post excerpt/summary largo_excerpt(get_the_ID(), 2, false, '', true); echo '</li>'; } echo "</ul>"; } echo $after_widget; // Restore global $post wp_reset_postdata(); $post = $preserve; }
/** * Outputs the HTML for this widget. * * @param array An array of standard parameters for widgets in this theme * @param array An array of settings for this widget instance * @return void Echoes it's output **/ public function widget($args, $instance) { extract($args, EXTR_SKIP); $count = esc_attr($instance['count']); $count = 0 < $count && $count < 10 ? $count : 2; $loop = new WP_Query(array('post_type' => 'event', 'posts_per_page' => $count, 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => '_event_start', 'meta_query' => array(array('key' => '_event_end', 'value' => time(), 'compare' => '>')))); if ($loop->have_posts()) { echo $before_widget; if ($instance['title']) { echo $before_title . apply_filters('widget_title', $instance['title']) . $after_title; } echo '<ul>'; while ($loop->have_posts()) { $loop->the_post(); global $post; $output = '<span class="meta">' . date(get_option('date_format'), get_post_meta(get_the_ID(), '_event_start', true)) . '</span> <a href="' . get_permalink() . '">' . get_the_title() . '</a>'; $read_more = apply_filters('em4wp_events_manager_upcoming_widget_output', $output, $post); if ($read_more) { echo '<li>' . $read_more . '</li>'; } } if ($instance['more_text']) { echo '<li><a href="' . get_post_type_archive_link('event') . '">' . esc_attr($instance['more_text']) . '</a></li>'; } echo '</ul>'; echo $after_widget; } wp_reset_postdata(); }
/** * Adds the subscription level dropdown to the member directory edit screen. */ function jp_um_admin_extend_directory_options_general($this) { $post_id = get_the_ID(); $saved_level = get_post_meta($post_id, 'um_rcp_subscription_level', true); $saved_level = !empty($saved_level) ? absint($saved_level) : 'none'; ?> <p> <label class="um-admin-half">RCP Members to Display</label> <span class="um-admin-half"> <select name="um_rcp_subscription_level" id="um_rcp_subscription_level" class="umaf-selectjs um-adm-conditional" style="width: 300px" data-cond1='other' data-cond1-show='custom-field'> <option value="none" <?php selected('none', $saved_level); ?> >None</option> <?php foreach (rcp_get_subscription_levels() as $key => $level) { echo '<option value="' . $level->id . '" ' . selected($level->id, $saved_level) . '>' . $level->name . '</option>'; } ?> </select> </span> </p><div class="um-admin-clear"></div> <?php wp_nonce_field('um_rcp_subscription_level_nonce', 'um_rcp_subscription_level_nonce'); }
function html_sitemap_shortcode_handler($args, $content = null) { if (is_feed()) { return ''; } $args['echo'] = 0; $args['title_li'] = ''; unset($args['link_before']); unset($args['link_after']); if (isset($args['child_of']) && $args['child_of'] == 'CURRENT') { $args['child_of'] = get_the_ID(); } else { if (isset($args['child_of']) && $args['child_of'] == 'PARENT') { $post =& get_post(get_the_ID()); if ($post->post_parent) { $args['child_of'] = $post->post_parent; } else { unset($args['child_of']); } } } $html = wp_list_pages($args); // Remove the classes added by WordPress $html = preg_replace('/( class="[^"]+")/is', '', $html); return '<ul>' . $html . '</ul>'; }
/** * Prints HTML with meta information for the categories, tags and comments. */ function smittenkitchen_primary_category() { if ('post' == get_post_type()) { $categories = get_the_category(get_the_ID()); // For each category, derive a list of top-level parent categories. $parent_categories = array(); foreach ($categories as $category) { if (0 === $category->category_parent) { $top_level_parent = $category->name; } else { // Get the top-level parent. $all_parents = get_category_parents($category->term_id, false, '&&&'); $all_parents = explode('&&&', $all_parents); $top_level_parent = $all_parents[0]; } // Add category to our array. if (!in_array($top_level_parent, $parent_categories)) { $parent_categories[] = $top_level_parent; } } // Join strings together! $parent_category_string = implode(', ', $parent_categories); if ($parent_category_string && smittenkitchen_categorized_blog()) { printf('<span class="smittenkitchen-primary-category">' . esc_html__('%1$s', 'smittenkitchen') . '</span>', $parent_category_string); // WPCS: XSS OK. } } }