/**
  *
  * The magic function that add the glossary terms to your content
  *
  * @global object $post
  * @param string $text
  * @return string
  */
 public function glossary_auto_link($text)
 {
     if ($this->g_is_singular() || $this->g_is_home() || $this->g_is_category() || $this->g_is_tag() || $this->g_arc_glossary() || $this->g_tax_glossary()) {
         $gl_query = new WP_Query(array('post_type' => 'glossary', 'order' => 'ASC', 'orderby' => 'title', 'posts_per_page' => -1, 'no_found_rows' => true, 'update_post_term_cache' => false));
         while ($gl_query->have_posts()) {
             $gl_query->the_post();
             $url = get_post_meta(get_the_ID(), GT_SETTINGS . '_url', true);
             $type = get_post_meta(get_the_ID(), GT_SETTINGS . '_link_type', true);
             $link = get_glossary_term_url();
             $target = get_post_meta(get_the_ID(), GT_SETTINGS . '_target', true);
             $nofollow = get_post_meta(get_the_ID(), GT_SETTINGS . '_nofollow', true);
             $internal = false;
             //Get the post of the glossary loop
             if (empty($url) && empty($type) || $type === 'internal') {
                 $internal = true;
             }
             if (!empty($link) && !empty($target)) {
                 $target = ' target="_blank"';
             }
             if (!empty($link) && !empty($nofollow)) {
                 $nofollow = ' rel="nofollow"';
             }
             $words[] = $this->search_string(get_the_title());
             if (isset($this->settings['tooltip'])) {
                 global $post;
                 $links[] = $this->tooltip_html($link, '$0', $post, $target, $nofollow, $internal);
             } else {
                 $links[] = '<a href="' . $link . '"' . $target . $nofollow . '>$0</a>';
             }
             $related = $this->related_post_meta(get_post_meta(get_the_ID(), GT_SETTINGS . '_tag', true));
             if (is_array($related)) {
                 foreach ($related as $value) {
                     $words[] = $this->search_string($value);
                     if (isset($this->settings['tooltip'])) {
                         $links[] = $this->tooltip_html($link, '$0', $post, $target, $nofollow, $internal);
                     } else {
                         $links[] = '<a href="' . $link . '"' . $target . $nofollow . '>$0</a>';
                     }
                 }
             }
         }
         if (!empty($words)) {
             if (isset($this->settings['first_occurence'])) {
                 $text = preg_replace($words, $links, $text, 1);
             } else {
                 $text = preg_replace($words, $links, $text);
             }
         }
         wp_reset_postdata();
     }
     return $text;
 }
예제 #2
0
function get_glossary_terms_list($order, $num, $tax = '')
{
    if ($order === 'asc') {
        $order = 'ASC';
    }
    $args = array('post_type' => 'glossary', 'order' => $order, 'orderby' => 'title', 'posts_per_page' => $num, 'update_post_meta_cache' => false, 'fields' => 'ids');
    if (!empty($tax)) {
        $args['tax_query'] = array(array('taxonomy' => 'glossary-cat', 'terms' => $tax, 'field' => 'slug'));
    }
    $glossary = new WP_Query($args);
    if ($glossary->have_posts()) {
        $out = '<dl class="glossary-terms-list">';
        while ($glossary->have_posts()) {
            $glossary->the_post();
            $out .= '<dt><a href="' . get_glossary_term_url(get_the_ID()) . '">' . get_the_title() . '</a></dt>';
        }
        $out .= '</dl>';
        wp_reset_query();
        return $out;
    }
}