{"id":95,"date":"2006-07-29T10:22:06","date_gmt":"2006-07-29T09:22:06","guid":{"rendered":"http:\/\/jerome.harckmans.be\/?p=95"},"modified":"2006-07-29T10:22:06","modified_gmt":"2006-07-29T09:22:06","slug":"re-test","status":"publish","type":"post","link":"https:\/\/jerome.harckmans.be\/?p=95","title":{"rendered":"Automatic Keywords Generation"},"content":{"rendered":"<p>I just wrote a small php function that automatically generate HTML meta keywords from the custom &#8220;tags&#8221; field of the displayed posts:<\/p>\n<div class=\"coding\">#########################<br \/>\n# KEYWORDS GENERATOR\t#<br \/>\n#########################\/*<br \/>\nThis function generate HTML Keywords based on<br \/>\nthe tags filled in for the displayed posts.<br \/>\nRequirements: WordPress 2.0, and you have to manually enter<br \/>\nthe tags separated by a comma in the &#8216;custom fields&#8217; (named tags)<br \/>\npart of the post.<br \/>\nTODO: actually, it&#8217;s only applicable to the first page (5 posts).<br \/>\nIt will be updated soon to all post pages.<br \/>\nAuthor: harck (jerome.harckmans.be)<br \/>\n*\/<br \/>\nfunction keywordGen() {<\/p>\n<blockquote><p>\/\/ Global Settings<br \/>\n$num_posts = 5; \/\/ Number of posts per page<br \/>\n$db_name = &#8220;WordPress Database Name&#8221;;<br \/>\n$db_user = &#8220;WordPress Database User&#8221;;<br \/>\n$db_pwd = &#8220;User Password&#8221;;<br \/>\n$db_host = &#8220;WordPress Database Host&#8221;;<br \/>\n\/\/ connecting to DB<br \/>\nmysql_connect($db_host, $db_user, $db_pwd) or die (&#8220;Unable to connect to Database Server!&#8221;);<br \/>\nmysql_select_db($db_name) or die (&#8220;Unable to select Database!&#8221;);<br \/>\n\/\/ Get all tags for the $num_posts last posts<br \/>\n\/\/ (the $num_posts displayed in the home page)<br \/>\n$tags = mysql_query(&#8220;SELECT meta_value FROM wp_postmeta, wp_posts WHERE post_id = ID AND meta_key = &#8216;tags&#8217; ORDER by post_date DESC LIMIT $num_posts &#8220;);<br \/>\n\/\/ Get the number of tags lines (may be different from $num_posts)<br \/>\n$num_tags = mysql_numrows($tags);<br \/>\n\/\/ Loop for each tag line<br \/>\nfor ( $i = 0; $i < $num_tags; $i++ ) {\n\n\n<blockquote>\/\/ Get current tag line<br \/>\n$cur_tags = mysql_result($tags, $i);<br \/>\n\/\/ First time, $keywords = tags<br \/>\nif ( $i == 0 ) {<\/p><\/blockquote>\n<blockquote><p>$keywords = $cur_tags;<\/p><\/blockquote>\n<p>}<br \/>\n\/\/ then append tags to $keywords<br \/>\nelse {<\/p>\n<blockquote><p>$keywords = $keywords.&#8221;,&#8221;.$cur_tags;<\/p><\/blockquote>\n<p>}<br \/>\n}<br \/>\n\/\/ Print HTML Keywords Meta<br \/>\nprint(&#8221;<\/p>\n<p>&lt;meta name=\\&#8221;Keywords\\&#8221; content=\\&#8221;{$keywords}\\&#8221; \/&gt;<br \/>\n&#8220;);<br \/>\n\/\/ THE END<br \/>\n}\n<\/p><\/div>\n<p>Simply call that function from the header part of your index page, and this should make web robots&#8217; life easier \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just wrote a small php function that automatically generate HTML meta keywords from the custom &#8220;tags&#8221; field of the displayed posts: ######################### # KEYWORDS GENERATOR # #########################\/* This function<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,6],"tags":[],"_links":{"self":[{"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=\/wp\/v2\/posts\/95"}],"collection":[{"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=95"}],"version-history":[{"count":0,"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=\/wp\/v2\/posts\/95\/revisions"}],"wp:attachment":[{"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jerome.harckmans.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}