Wordpress - Templates: Unterschied zwischen den Versionen
Aus Wikizone
(Die Seite wurde neu angelegt: „Links * http://codex.wordpress.org/Template_Tags“) |
|||
| Zeile 2: | Zeile 2: | ||
* http://codex.wordpress.org/Template_Tags | * http://codex.wordpress.org/Template_Tags | ||
| + | |||
| + | |||
| + | == Snippets == | ||
| + | * Nur 1 Kommentar für jeden Post und Tag, außer für User höherer Level. | ||
| + | |||
| + | /wp-content/themes/myTheme/comments.php | ||
| + | |||
| + | comment_form(); | ||
| + | ersetzen durch: | ||
| + | <pre> | ||
| + | <?php | ||
| + | |||
| + | global $wpdb, $current_user; | ||
| + | $limit = 1; | ||
| + | //this is limit per day per user | ||
| + | $minUserLevel = 6; | ||
| + | // no limit for users above this level | ||
| + | $myUser_level = 0; | ||
| + | $myUser_level = intval($current_user -> user_level); | ||
| + | $myUser_login = $current_user -> user_login; | ||
| + | $myUser_id = $current_user -> ID; | ||
| + | $myComment_id = get_comment_ID(); | ||
| + | $myComment_post_id = get_the_ID(); | ||
| + | |||
| + | /* | ||
| + | echo("<div>user id: " . $myUser_id . "</div>"); | ||
| + | echo("<div>comment id: " . $myComment_id . "</div>"); | ||
| + | echo("<div>comment post id: " . $myComment_post_id . "</div>"); | ||
| + | echo("<div>user level: " . $myUser_level . "</div>"); | ||
| + | echo("<div>min user level: " . $minUserLevel . "</div>"); | ||
| + | */ | ||
| + | $comment_count = $wpdb -> get_var($wpdb -> prepare(" | ||
| + | SELECT count(*) | ||
| + | FROM kas_wp_comments | ||
| + | WHERE user_id = '%d' AND comment_parent = '0' AND comment_post_ID = '%d' | ||
| + | ;", $myUser_id, $myComment_post_id)); | ||
| + | |||
| + | /* $comment_count = $wpdb -> get_var($wpdb -> prepare(" | ||
| + | SELECT count(*) | ||
| + | FROM kas_wp_comments | ||
| + | WHERE user_id = '%d' AND comment_parent = 0 AND comment_post_ID = '%d' | ||
| + | AND comment_date >= DATE_SUB(NOW(),INTERVAL 1 DAY);", $myUser_id,$myComment_post_id)); | ||
| + | */ | ||
| + | |||
| + | //echo("<div>Beiträge zum Thema: " . $comment_count . "/" . $limit . "</div>"); | ||
| + | |||
| + | $level_ok = 0; | ||
| + | $limit_ok = 0; | ||
| + | if ($comment_count < $limit) { | ||
| + | $limit_ok = 1; | ||
| + | // echo "<div>limit_ok</div>"; | ||
| + | } | ||
| + | |||
| + | if ($myUser_level > $minUserLevel) { | ||
| + | $level_ok = 1; | ||
| + | // echo "<div>level_ok</div>"; | ||
| + | |||
| + | } | ||
| + | |||
| + | if ($level_ok || $limit_ok) { | ||
| + | comment_form(); | ||
| + | } else { | ||
| + | //echo 'Sie haben die maximale Anzahl von Fragen ('.$limit.') gestellt. Sie können weiterhin auf gestellte Fragen antworten.'; | ||
| + | echo('<div class="invisible"><br>'); | ||
| + | comment_form(); | ||
| + | echo('</div>'); | ||
| + | } | ||
| + | ?> | ||
| + | </pre> | ||
Version vom 12. März 2013, 16:17 Uhr
Links
Snippets
- Nur 1 Kommentar für jeden Post und Tag, außer für User höherer Level.
/wp-content/themes/myTheme/comments.php
comment_form();
ersetzen durch:
<?php
global $wpdb, $current_user;
$limit = 1;
//this is limit per day per user
$minUserLevel = 6;
// no limit for users above this level
$myUser_level = 0;
$myUser_level = intval($current_user -> user_level);
$myUser_login = $current_user -> user_login;
$myUser_id = $current_user -> ID;
$myComment_id = get_comment_ID();
$myComment_post_id = get_the_ID();
/*
echo("<div>user id: " . $myUser_id . "</div>");
echo("<div>comment id: " . $myComment_id . "</div>");
echo("<div>comment post id: " . $myComment_post_id . "</div>");
echo("<div>user level: " . $myUser_level . "</div>");
echo("<div>min user level: " . $minUserLevel . "</div>");
*/
$comment_count = $wpdb -> get_var($wpdb -> prepare("
SELECT count(*)
FROM kas_wp_comments
WHERE user_id = '%d' AND comment_parent = '0' AND comment_post_ID = '%d'
;", $myUser_id, $myComment_post_id));
/* $comment_count = $wpdb -> get_var($wpdb -> prepare("
SELECT count(*)
FROM kas_wp_comments
WHERE user_id = '%d' AND comment_parent = 0 AND comment_post_ID = '%d'
AND comment_date >= DATE_SUB(NOW(),INTERVAL 1 DAY);", $myUser_id,$myComment_post_id));
*/
//echo("<div>Beiträge zum Thema: " . $comment_count . "/" . $limit . "</div>");
$level_ok = 0;
$limit_ok = 0;
if ($comment_count < $limit) {
$limit_ok = 1;
// echo "<div>limit_ok</div>";
}
if ($myUser_level > $minUserLevel) {
$level_ok = 1;
// echo "<div>level_ok</div>";
}
if ($level_ok || $limit_ok) {
comment_form();
} else {
//echo 'Sie haben die maximale Anzahl von Fragen ('.$limit.') gestellt. Sie können weiterhin auf gestellte Fragen antworten.';
echo('<div class="invisible"><br>');
comment_form();
echo('</div>');
}
?>