Last active
November 30, 2017 09:07
-
-
Save phucdohong96/08d2bbc076605772ffded12ca46c3c93 to your computer and use it in GitHub Desktop.
Example Create Shortcode WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function custom_loop_function( $atts ) { | |
| ob_start(); | |
| $opts = shortcode_atts( array( | |
| 'type' => 'post_type_option', | |
| ), $atts ); | |
| $output = ''; | |
| $args = array( | |
| 'post_type' => $opts['type'], | |
| 'posts_per_page' => '10', | |
| 'order' => 'DESC', | |
| ); | |
| $loop = new WP_Query( $args ); | |
| while ( $loop->have_posts() ) : $loop->the_post(); | |
| $id = get_the_ID(); | |
| $title = get_the_title(); | |
| $image = get_the_post_thumbnail($id,'full'); | |
| $excerpt = get_the_excerpt(); | |
| $link = get_permalink (); | |
| $content = get_the_content (); | |
| ?> | |
| <div>HTML Content</div> | |
| <?php | |
| endwhile; | |
| wp_reset_postdata(); | |
| return ob_get_clean(); | |
| } | |
| add_shortcode('custom_loop_shortcode', 'custom_loop_function'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment