Ich möchte Kommas in Tag-Namen zulassen? Zum Beispiel "hello, world"
oder "portland, or"
, aber Wordpress trennt sie weiterhin. Ich kann es von der Kategorieseite machen:
image http://img839.imageshack.us/img839/6869/picturepp.png
Und es zeigt sich gut. Aber alles, was von der Seitenleiste der Beiträge hinzugefügt wurde, wird hier nicht angezeigt:
image http://img52.imageshack.us/img52/4950/picture1oax.png
Hier wird darüber diskutiert: http://core.trac.wordpress.org/ticket/14691 aber es sieht so aus, als würde es zumindest für eine Weile nicht gelöst.
In der Zwischenzeit suche ich nach einer einfacheren Lösung als das Hinzufügen von Kategorien über die Kategorieseite.
Ich habe versucht, nach Plugins zu suchen, und habe keine gefunden, die hilfreich wären. Es gibt einige, die das Ersetzen von Kommas durch andere Zeichen beim Anzeigen einer Liste von Kategorien oder Tags behandeln, aber ich sehe keine Plugins, mit denen der Benutzer das Standardtrennzeichen ersetzen kann.
Es ist mir egal, ob ich den Core selbst patchen muss. Idealerweise könnte ich ein Plugin schreiben, aber nachdem ich einen Teil des Codes durchgesehen habe, kann ich nicht herausfinden, wo dies gehandhabt wird.
Hat jemand eine Lösung oder Tipps, mit welchen Funktionen und Javascript das Hacken beginnen soll? Ich bin mir nicht sicher, wo ich anfangen soll, im Code zu suchen.
Kein Core-Hacking erforderlich - dank: HOOKS.
Mit Hooks können Sie das Problem mit einer Nice-Kombination von beheben
Hier ist der Code:
// filter for tags with comma
// replace '--' with ', ' in the output - allow tags with comma this way
// e.g. save tag as "Fox--Peter" but display thx 2 filters like "Fox, Peter"
if(!is_admin()){ // make sure the filters are only called in the frontend
function comma_tag_filter($tag_arr){
$tag_arr_new = $tag_arr;
if($tag_arr->taxonomy == 'post_tag' && strpos($tag_arr->name, '--')){
$tag_arr_new->name = str_replace('--',', ',$tag_arr->name);
}
return $tag_arr_new;
}
add_filter('get_post_tag', 'comma_tag_filter');
function comma_tags_filter($tags_arr){
$tags_arr_new = array();
foreach($tags_arr as $tag_arr){
$tags_arr_new[] = comma_tag_filter($tag_arr);
}
return $tags_arr_new;
}
add_filter('get_terms', 'comma_tags_filter');
add_filter('get_the_terms', 'comma_tags_filter');
}
Vielleicht helfen auch einige zusätzliche Details in meinem Blog-Beitrag zu diesem Thema. http://blog.foobored.com/all/wordpress-tags-with-commas/
Grüße, Andi
Es ist möglich und sehr einfach, Tags mit Kommas programmatisch zu speichern.
Wenn Sie beim Aufrufen von wp_set_post_terms( $post_id, $terms, $taxonomy )
eine Zeichenfolge angeben, wird diese in ein Array aufgelöst. Wenn Sie Ihren $terms
als Array angeben, wird jedes Element im Array als eigener Begriff angegeben, ohne in mehrere Begriffe aufgeteilt zu werden.
// Example term with comma.
$terms = 'Surname, Given Names';
// Creates and/or assigns multiple terms separated by a comma.
wp_set_post_terms( $post_id, $terms, $taxonomy );
// Creates and/or assigns a single term with a comma.
wp_set_post_terms( $post_id, (array) $terms, $taxonomy );
Sowohl wp_insert_post
als auch anschließend wp_update_post
verwenden wp_set_post_terms
, wenn der $arg
tax_input
festgelegt ist.
// Ensure $terms is an array.
$args['tax_input'][$taxonomy] = (array) $terms;
$post_id = wp_insert_post( $args );
Möglicherweise müssen Sie ein eigenes Meta-Feld erstellen, in dem alle Zeichenfolgen, einschließlich Kommas, als einzelner Begriff übergeben werden. Dies ist die beste Möglichkeit, um Begriffe im Handumdrehen mithilfe der Benutzeroberfläche von WordPress Dashboard zu erstellen. Einige Plugins, wie z. B. ACF Pro, tun dies standardmäßig, wenn Sie ein benutzerdefiniertes Feld zum Speichern der Taxonomie erstellen und auswählen, dass die Begriffe beim Speichern auch geladen und zugewiesen werden sollen.
/* Example JSON config snippet for an ACF Pro Export/Import. */
/* Most likely config for most of these situations: "allow_null" */
/* and "field_type" may need to be adjusted depending on the situation. */
{
"type": "taxonomy",
"field_type": "multi_select",
"allow_null": 1,
"add_term": 1,
"save_terms": 1,
"load_terms": 1
}
Selbst wenn diese Begriffe mit einem Komma gespeichert werden, werden sie beim Bearbeiten des Beitrags möglicherweise immer noch als separate Elemente angezeigt. In diesem Fall ist es möglicherweise am besten, die Standardbenutzeroberfläche zu deaktivieren und sich auf die benutzerdefinierten Metaboxen zu verlassen. Dies kann über die Bildschirmoptionen beim Bearbeiten eines Beitragstyps erfolgen. Benutzerdefinierte Taxonomien können bei der Registrierung auch im Schnellbearbeitungsbereich ausgeblendet werden.
// Register Custom Taxonomy args - disable default UI in quick edit.
$args['show_in_quick_edit'] = false;
register_taxonomy( $taxonomy, (array) $post_types, $args );
sie können einen Filter verwenden.
Wenn Sie beispielsweise nach jedem Tag in einer Tag-Cloud ein Komma hinzufügen möchten, können Sie Folgendes in die Datei functions.php einfügen
function myfunc_filter_tag_cloud($args) {
$args['smallest'] = 18;
$args['largest'] = 32;
$args['unit'] = 'px';
$args['separator']= ', ';
return $args;
}
add_filter ( 'widget_tag_cloud_args', 'myfunc_filter_tag_cloud');
Hier liegt Ihre Lösung. Beachten Sie die Zeile 2614:
/**
2588 * Updates the cache for Term ID(s).
2589 *
2590 * Will only update the cache for terms not already cached.
2591 *
2592 * The $object_ids expects that the ids be separated by commas, if it is a
2593 * string.
2594 *
2595 * It should be noted that update_object_term_cache() is very time extensive. It
2596 * is advised that the function is not called very often or at least not for a
2597 * lot of terms that exist in a lot of taxonomies. The amount of time increases
2598 * for each term and it also increases for each taxonomy the term belongs to.
2599 *
2600 * @package WordPress
2601 * @subpackage Taxonomy
2602 * @since 2.3.0
2603 * @uses wp_get_object_terms() Used to get terms from the database to update
2604 *
2605 * @param string|array $object_ids Single or list of term object ID(s)
2606 * @param array|string $object_type The taxonomy object type
2607 * @return null|bool Null value is given with empty $object_ids. False if
2608 */
2609 function update_object_term_cache($object_ids, $object_type) {
2610 if ( empty($object_ids) )
2611 return;
2612
2613 if ( !is_array($object_ids) )
2614 $object_ids = explode(',', $object_ids);
2615
2616 $object_ids = array_map('intval', $object_ids);
2617
2618 $taxonomies = get_object_taxonomies($object_type);
2619
2620 $ids = array();
2621 foreach ( (array) $object_ids as $id ) {
2622 foreach ( $taxonomies as $taxonomy ) {
2623 if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) {
2624 $ids[] = $id;
2625 break;
2626 }
2627 }
2628 }
2629
2630 if ( empty( $ids ) )
2631 return false;
2632
2633 $terms = wp_get_object_terms($ids, $taxonomies, array('fields' => 'all_with_object_id'));
2634
2635 $object_terms = array();
2636 foreach ( (array) $terms as $term )
2637 $object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term;
2638
2639 foreach ( $ids as $id ) {
2640 foreach ( $taxonomies as $taxonomy ) {
2641 if ( ! isset($object_terms[$id][$taxonomy]) ) {
2642 if ( !isset($object_terms[$id]) )
2643 $object_terms[$id] = array();
2644 $object_terms[$id][$taxonomy] = array();
2645 }
2646 }
2647 }
2648
2649 foreach ( $object_terms as $id => $value ) {
2650 foreach ( $value as $taxonomy => $terms ) {
2651 wp_cache_set($id, $terms, "{$taxonomy}_relationships");
2652 }
2653 }
2654 }
2655
Innerhalb von wp-includes/taxonomy.php . Viel Glück beim Hacken des Codes. Es gibt keinen Haken. es ist hart codiert ... Entschuldigung. Ich denke, dass das Hacken des Codes Ihre einzige Option für den Moment ist.