现在我的$ticker在posts中是由tag定义的,它非常适合widget
Global $wp_query;
$post_id = $wp_query->get_queried_object_id();
$tags = wp_get_post_tags($post_id);
$category = get_the_category($post_id);
$isHome = is_front_page();
$isArticle = !(empty($tags) || is_category());
//if (!$isHome && !$isArticle && empty($args['force'])) return;
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if (!empty($title))
echo $args['before_title'] . $title . $args['after_title'];
$ticker = tr_get_ticker($post_id);
$sector = tr_get_sector($post_id);
if( $title = apply_filters( 'widget_title', $instance['title'] ) )
echo $args['before_title'] . $title . $args['after_title']; ?>
More <?php echo $ticker ?> Research at TipRanks
但也有帖子,里面没有任何标签。
我需要$ticker从标签或文章中的SPAN获得:
我该怎么办?
如果需要,请在此处搜索标记:
function tr_get_ticker($post_ID) {
$ticker = get_post_meta($post_ID, 'ticker', TRUE);
if (empty($ticker)) {
$tags = wp_get_post_tags($post_ID);
foreach ($tags as $tag) {
$term = $tag->name;
$isTicker = strlen($term) <= 5 && ctype_upper($term);
$isTickerWeak = strlen($term) <= 5;
if ($isTickerWeak) {
$ticker = $term;
}
if ($isTicker) {
$ticker = $term;
break;
}
}
}
return strtoupper($ticker);