WordPress.org

Ready to get started?Download WordPress

Forums

meta keywords from terms2tags (or terms2 post) (2 posts)

  1. joelwalsh
    Member
    Posted 8 years ago #

    I tried modifying the code of the terms2tags plugin to make it simply output the list of keywords, so I could use it in the <title>, for a longer, more keyword-rich and descriptive title than the mere post title. But nothing comes out. I suspect there's a faster, easier way of doing this--what is it?

    require_once dirname(__FILE__) . '/sem-extract-terms.php';

    /*
    * sem_get_terms2keywords()
    * ----------------
    * returns post's terms as meta keywords
    **/

    function sem_get_terms2keywords( $my_post = null )
    {
    if ( function_exists( 'sem_extract_terms' ) )
    $terms = sem_extract_terms( $my_post );

    if ( $terms )
    {
    foreach ( $terms as $term )
    $output .= $term. ', ';
    return $output;
    }
    } // end sem_get_terms2keywords()

    #
    # sem_terms2keywords()
    #
    function sem_terms2keywords($my_post = null)
    {
    echo sem_get_terms2keywords($my_post);
    } # end sem_terms2keywords()
    ?>

  2. c0c0c0
    Member
    Posted 8 years ago #

    I just hacked up his tags plugin and renamed it terms2keywords, upped it and made it a plugin. It isn't perfect, but it works for me.

    Try this:


    <?php
    /*
    Plugin Name: Terms2tags*cough*keywords*cough*
    Plugin URI: http://www.semiologic.com/projects/terms2tags/
    Description: <a href="http://www.semiologic.com/projects/terms2tags/">Doc/FAQ</a> &bull; <a href="http://wordpress.org/tags/semiologic">Support forum</a> — Requires the <a href="http://www.semiologic.com/projects/extract-terms/">Extract terms plugin</a>. Returns Yahoo! terms as technorati tags. To use, call sem_terms2tags(); where you want the terms to appear.
    Version: 1.6
    Author: Denis de Bernardy
    Author URI: http://www.semiologic.com
    Place the following code in your header:
    <meta name="keywords" content="<?php if ( is_single() ) {
    sem_terms2keywords($wp_query->post);
    } else {
    bloginfo('name'); echo " - "; bloginfo('description');
    }
    ?>"/>
    */
    /*
    * Terms of use
    * ------------
    * Except where otherwise noted, this software is:
    * - Copyright 2005, Denis de Bernardy
    * - Licensed under the terms of the CC/GNU GPL
    * http://creativecommons.org/licenses/GPL/2.0/
    * - Provided as is, with NO WARRANTY whatsoever
    **/
    require_once dirname(__FILE__) . '/sem-extract-terms.php';
    /*
    * sem_get_terms2keywords()
    * ----------------
    * returns post's terms as meta keywords
    **/
    function sem_get_terms2keywords( $my_post = null )
    {
    if ( function_exists( 'sem_extract_terms' ) )
    $terms = sem_extract_terms( $my_post );
    if ( $terms && sizeof( $terms ) )
    {
    foreach ( $terms as $term )
    $output .= "$term" . ( ( ++$i < sizeof($terms) ) ? ', ' : '' );
    return $output;
    }
    } // end sem_get_terms2keywords()
    #
    # sem_terms2keywords()
    #
    function sem_terms2keywords($my_post = null)
    {
    echo sem_get_terms2keywords($my_post);
    } # end sem_terms2keywords()
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic