Deprecated: Creation of dynamic property CF\WordPress\DataStore::$logger is deprecated in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php on line 23

Deprecated: Creation of dynamic property CF\WordPress\Proxy::$pluginAPI is deprecated in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/Proxy.php on line 31

Deprecated: Creation of dynamic property SyntaxHighlighter::$brush_names is deprecated in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/syntaxhighlighter/syntaxhighlighter.php on line 248

Deprecated: Creation of dynamic property SyntaxHighlighter::$specialchars is deprecated in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/syntaxhighlighter/syntaxhighlighter.php on line 326
המכללה | קבצי include
Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

קבצי include

ברמת העיקרון, וורדפרס מספקת פונקציות שתפקידן לקרוא לרכיבים קבועים במערכת.
כך למשל יש לנו את get_header, get_sidebar, get_footer ודומיהן על מנת לקרוא לרכיבי ההדר, הפוטר ובר הניווט.
אומנם פונצקיות אלו פשוטות וכבר נכתבו מראש והן קלות לשימוש, אבל בסופו של דבר לעיתים נרצה לשלב מידע נוסף אל תוך העמודים מבלי להתעסק בכל הקבצים.
אם למשל נרצה לתחזק מערכת באנרים ולשלב אותם במקומות שונים באתר, אנחנו עלולים למצוא את עצמנו נזקקים לעריכה מחודשת של מספר דפים על מנת להחליף באנר פשוט. במקום זה, ניתן להשתמש בקבצי include וכך לייצר קובץ אחד שאותו מעדכנים ומכניסים אליו קריאה מכל שאר העמודים הרלוונטים.

לצורך כך, נשתמש בפונקציית ה include – שהיא פונקציה של php בצורה הבאה:

ראשית, ניצור את הקובץ של הפירסומת – לצורך הדוגמא הוא יקרא ad.php ותכולתו תהייה:

< ?php
        $link = http://example.link;
        $img = example.img;
	echo '

במקרה המודגם, התוצאה תהייה שבכל מקום שבו קראנו לקובץ יופיע הגיף המדובר עם הפניה לקישור המוגדר.

לעומת זאת, ניתן להשתמש בפונקציה על מנת לייצר מערכת פירסום מתוחכמת יותר בצורה הבאה:

< ?php
	function makeBanner($link, $location)
	{
	echo '

הפונקציה הזו, מקבלת כפרמטר לינק ומיקום של אימג' ומייצרת מחרוזת טקסט שתראה בסופו של דבר בדיוק כמו הדוגמא הקודמת.
עם זאת, הפעם אם רק נבצע include לא נראה שום השפעה. על מנת לראות את התוצאה נאלץ לקרוא לפונקציה עצמה עם הערכים הרלוונטיים.

יישומים נוספים

מלבד היישום כמערכת פירסום, ניתן להשתמש באפשרות האינקלוד על מנת לשלב כל מידע שהוא בעמוד. כך למשל ניתן לאסוף את כל לינקי הסטטיסטיקות למיניהם אל תוך קובץ אחד ולקרוא לו – ובכך להקל על מעבר בין ערכת עיצוב אחת לאחרת. בנוסף, ניתן לייצר עמודי php נוספים עבור הבלוג ולשלב אותם ישירות בדרך זו. כך למשל, ניתן ליצור קובץ הדר נוסף לבלוג (למשל header1.php) שיראה טיפה שונה (גיף אחר, טקסט אחר וכיוצ"ב) ולקרוא לו מתוך עמוד קטגוריה במקום להדר המקורי. כך במקום להשתמש ב get_header נשתמש ב include header1.php. אותו דבר ניתן לעשות גם עם ברי הניווט, הפוטר וכמובן כל חלק אחר בעמוד.

לדרג את הפוסט
5

Posted

in

by

Tags:

Comments

2 תגובות על “קבצי include”

  1. […] באחד מהפוסטים הקודמים עברנו על התנהגות ה include – פונקציה המאפשרת לנו לקרוא לדף php מתוך הדף הקיים ולגשת […]

  2. קבצי include במערכת וורדפרס

    ניצן ברומר נותן מבוא לגבי קבצי include במערכות מבוססות וורדפרס.

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *


Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/DataStore.php:23) in /home/nitzan_n2b/n2b.org/wordpress/wp-content/plugins/cloudflare/src/WordPress/HTTP2ServerPush.php on line 79