וורדפרס ואתרי אינטרנט

owl-158414_960_720
דורג 5 מתוך 5

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

הפונקציות get_previous_post ו get_next_post

 

get_next_post ( bool $in_same_term = false, array|string $excluded_terms = '', string $taxonomy = 'category' )

 

פונקציה מובנית בוורדפרס שמחזירה מידע על הפוסט הבא בתור.

פרמטרים שהיא מקבלת

Parameters

$in_same_term

    (bool) (Optional) Whether post should be in a same taxonomy term.

    Default value: false
$excluded_terms

    (array|string) (Optional) Array or comma-separated list of excluded term IDs.

    Default value: ''
$taxonomy

    (string) (Optional) Taxonomy, if $in_same_term is true.

    Default value: 'category'

 

הפונקציה מחזירה את הפרמטרים של הפוסט במקרה של הצלחה.

 Member Variable 	Variable Type 	Notes
ID 	int 	The ID of the post
post_author 	string 	The post author's user ID (numeric string)
post_name 	string 	The post's slug
post_type 	string 	See Post Types
post_title 	string 	The title of the post
post_date 	string 	Format: 0000-00-00 00:00:00
post_date_gmt 	string 	Format: 0000-00-00 00:00:00
post_content 	string 	The full content of the post
post_excerpt 	string 	User-defined post excerpt
post_status 	string 	See get_post_status for values
comment_status 	string 	Returns: { open, closed }
ping_status 	string 	Returns: { open, closed }
post_password 	string 	Returns empty string if no password
post_parent 	int 	Parent Post ID (default 0)
post_modified 	string 	Format: 0000-00-00 00:00:00
post_modified_gmt 	string 	Format: 0000-00-00 00:00:00
comment_count 	string 	Number of comments on post (numeric string)
menu_order 	string 	Order value as set through page-attribute when enabled (numeric string. Defaults to 0)

פונים לכל פרמטר בצורה הבאה:

$examplePost = get_next_post();

echo $examplePost->ID; // Display the post's ID

דוגמא:

<?php
$next_post = get_next_post();
if (!empty( $next_post )): ?>
  <a href="<?php echo get_permalink( $next_post->ID ); ?>"><?php echo $next_post->post_title; ?></a>
<?php endif; ?>

אותו דבר אפשר לעשות עם הפקודה get_previous_post

רק שהיא נותנת את הפוסט הקודם.

תפריט נגישות