מה אני יודעת לעשות ?
כל דבר שקשור לוורדפרס כל עוד אינו מצריך יכולות עיצוב.
דוגמאות ניתן לראות בתיק העבודות שלי או ברחבי הבלוג עצמו.
ניתן ליצור איתי קשר במיייל: webmaster@dakars.info
בפוסט הקודם שלי בנושא פילטרים אמרתי שיש לא מעט דברים שניתן לעשות עם פילטרים. בפוסט הזה נראה כמה דוגמאות שימושיות למדיי.
כיווניות תגובות
הקוד הבא יכול לשמש ליישור התגובה לימין או לשמאל כתלות בשפה בה נכתבה
1 2 3 4 5 6 7 8 9 10 11 12 | /* Comments directionality filter */ add_filter('comment_text', 'lang_dir'); function lang_dir($content) { $eng = preg_match_all('/[a-zA-Z].?/', $content, $matches); $heb = preg_match_all('/[א-תץףךםן].?/', $content, $matches); if ($eng > $heb) { return "<div class='lcomment'><p>$content &;lt;/p></div>"; } else { return "<div class='rcomment'><p>$content</p></div>"; } } |
כמובן שצריך להוסיף גם את קוד ה-css הבא:
1 2 3 4 5 6 7 8 | .lcomment { direction: ltr; text-aliggn: left; } .rcomment { direction: rtl; text-align: right; } |
הקוד מטפל כרגע בעברית מול אנגלית, אבל ניתן כמובן להתאים אותו לטיפול בשפות נוספות בקלות יחסית.
מחליף שפות
נכון, יש כל מיני תוספים שעושים בעקרון את העבודה, לא בעקרון את רובם אני לא אוהבת וחושבת שהם מסורבלים. לכן כתבתי פילטר שעושה בדיוק את אותה העבודה
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /* Language 'plugin' for the theme */ function ShowHideJs() { ?> <script> function setElementVisibility(eShow, eHide){ document.getElementById(eShow).style.visibility = "visible"; document.getElementById(eShow).style.display = "block"; document.getElementById(eHide).style.visibility = "hidden"; document.getElementById(eHide).style.display = "none"; } function ShowHeb(){ setElementVisibility("heb", "eng"); } function ShowEng(){ setElementVisibility("eng", "heb"); } </script> <? } function add_buttons($content) { if ((strstr($content, "[heb]") !== false) && (strstr($content, "[eng]") !== false)) { $hebbtn = get_bloginfo('template_url')."/img/hBtn"; $engbtn = get_bloginfo('template_url')."/img/eBtn"; $buttons .= "<img src='".$engbtn.".png' onMouseover='this.src=\"".$engbtn."_Hover.png\"' onMouseout='this.src=\"".$engbtn.".png\"' onClick='ShowEng()' />\n"; $buttons .= "<img src='".$hebbtn.".png' onMouseover='this.src=\"".$hebbtn."_Hover.png\"' onMouseout='this.src=\"".$hebbtn.".png\"' onClick='ShowHeb()' />\n"; return "<div id='lang'>".$buttons."".$content; } return $content; } function heb($content) { return str_replace ("[/heb]", "</div>", str_replace("[heb]", "<div id='heb' name='heb' style='visibility:display;'>", $content)); } function eng($content) { return str_replace ("[/eng]", "</div>", str_replace("[eng]", "<div id='eng' style='visibility:hidden; display:none;'>", $content)); } add_filter('wp_head', 'ShowHideJs'); add_filter('the_content', 'add_buttons'); add_filter('the_content', 'eng'); add_filter('the_content', 'heb'); |
שימו לב שהקוד למעלה משתמש במספר פילטרים שונים:
- פילטר JS שיושב בהדר של העמוד
- פילטר שמוסיף את כפתורי השפה
- פילטר אנגלית, פילטר עברית
את השנים האחרונים היה נניתן כמובן לשלב לפילטר יחיד, אבל אני החלטתי שזה יותר יפה כך
יש עוד לא מעט פילטרים שימושיים, ניתן לראות חלק בפוסטים הבאים:
ויש עוד לא מעט כאלו
נהניתם ? הרשמו לעדכוני RSS !

שמי חנית כהן, אני בת 33 ואשת מחשבים משנת 93.
באיזה פלאגין את משתמשת בשביל להציג את הקוד בעיצוב הזה ?
google syntax highlighter
שאלה לי אלייך,
אני מעוניין למצוא פתרון אלגנטי לצמצום מספר המילים של excerpt, לא דרך תוסף אלא דרך פילטרים.
הפונקציה שמחזירה את ה-excerpt של הפוסט משתמש בפונקציה wp_trim_excerpt(). עיון בקוד של הפונקציה גילה את שורת הקוד הבאה:
$excerpt_length = apply_filters(’excerpt_length’, 55);
איך את מציע לשנות זאת בעזרת פילטר?
add_filter('excerpt_length', 'my_excerpt_length'); function my_excerpt_length($length) { return 20; }תודה, זה עובד מצויין.
הוספתי את הקוד שלך לקודקס:
http://codex.wordpress.org/Function_Reference/wp_trim_excerpt
כדי שכולם יוכלו להינות ממנו. ושוב תודה.
[...] שנתקלתי בפוסט המאלף בבלוג המעלף של חנית כהן. אם יש לכם בלוג מבוסס על [...]
I have tried this plugin (based on this post) and it didn’t work for me
http://etmob.com/blog/index.php/2009/12/wordpress-comments-alignment/
I write this comment in English in order to see if it will align to the left