حتما شده به ذهنتان رسیده باشد مطالبی که سنجاق می کنید را در جایی از قالب یا در یک برگه یا در یک ابزارک قرار دهید ، راه حل شما این است که کمی به این مطلب دقت کنید و طبق آموزش پیش بروید.
با مطالب ثابت یا پست ثابت وردپرس آشنا هستید ؟ برای نمایش آخرین پست های ثابت ابتدا کدهای زیر را در فایل فانکشن ( functions.php ) قرار دهید و ذخیره کنید ؛
function wpb_latest_sticky() { /* Get all sticky posts */ $sticky = get_option( 'sticky_posts' ); /* Sort the stickies with the newest ones at the top */ rsort( $sticky ); /* Get the 5 newest stickies (change 5 for a different number) */ $sticky = array_slice( $sticky, 0, 5 ); /* Query sticky posts */ $the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) ); // The Loop if ( $the_query->have_posts() ) { $return .= '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); $return .= '<li><a href="' .get_permalink(). '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>'; } $return .= '</ul>'; } else { // no posts found } /* Restore original Post Data */ wp_reset_postdata(); return $return; } add_shortcode('latest_stickies', 'wpb_latest_sticky');
حال فانکشن را ذخیره کنید.
حال برای استفاده از کد فانکشن در برگه ها ، نوشته ها و ابزارک می توانید از شورت کد زیر استفاده کنید :
[latest_stickies]
برای استفاده در ابزارک های متنی باید کد زیر نیز بعد از کد فانکشن بالا قرار بگیرد ؛
add_filter('widget_text', 'do_shortcode');
برای استفاده از شورت کد در قالب می توانید از کد زیر استفاده نمایید ؛
<div class="last"> <?php do_shortcode(' [latest_stickies] '); ?> </div>
موفق باشید