Kann mir da ein Wordpress Spezi nen Tipp geben?
Verfasst: 11.03.2012, 18:39
Also ich war im Netz auf der Suche nach einem Wordpress Plugin das einem Artikel anhand der Tags automatisch eine Kategorie zuweist. Dabei bin ich über folgenden Code gestolpert:
Leider war keine Anleitung dabei. Einer eine Idee wohin damit (wahrscheinlich irgendwo in der functions.php). Alternativ kennt vielleicht jemand von euch ein Plugin das den Job erledigt. Wie gesagt ich brauche eine Lösung um einem Artikel automatisch die passende Kategorie (bspw. nach Keywords im Titel) in die (vorhandene) passende Kategorie zuweist.
Danke schonmal für jeden Tipp
Code: Alles auswählen
// Add a category to a post for each of selected tags the post already has.
// Modify the $tag_categories array. Use one tag name => one category name
function mam_add_category ($post_id = 0) {
if (!$post_id) return;
$tag_categories = array ( // The tag names and the corresponding category name to add
'info' => 'information',
'INFO' => 'information',
'search optimization' => 'SEO',
);
$post_tags = get_the_tags($post_id);
foreach ($post_tags as $tag) {
if ($tag_categories[$tag->name] ) {
$cat_id = get_cat_ID($tag_categories[$tag->name]);
if ($cat_id) {
$result = wp_set_post_terms( $post_id, $tags = $cat_id, $taxonomy = 'category', $append = true );
}
}
}
}
add_action('publish_post','mam_add_category');
?>
Danke schonmal für jeden Tipp