Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-----------How to query custom post with shortcode--------------->
- 1.First register custom post in fuctions.php like bellow....
- function portfolio_list_custom_post() {
- register_post_type( 'portfolio_items',
- array(
- 'labels' => array(
- 'name' => __( 'portfolios' ),
- 'singular_name' => __( 'portfolio' ),
- 'all_items' => __( 'All portfolio' ),
- 'add_new_item' => __( 'Add new portfolio' ),
- 'search_items' => __( 'Search portfolio' ),
- 'not_found' => __( 'No portfolio found,Please!!! try with another keyword' ),
- 'not_found_in_trash' => __( 'No portfolio found in trash' ),
- 'parent_item' => __( 'Parent portfolio' ),
- 'parent_item_colon' => __( 'Parent portfolio' ),
- 'edit_item' => __( 'Edit portfolio' ),
- 'update_item' => __( 'Update portfolio' ),
- 'view_item' => __( 'View portfolio' ),
- 'new_item_name' => __( 'New portfolio' ),
- 'menu_name' => __( 'portfolio' )
- ),
- 'public' => true,
- 'menu_icon' => 'dashicons-nametag',
- 'supports' => array('title', 'editor','thumbnail'),
- 'has_archive' => true,
- 'menu_position' => 8,
- 'rewrite' => array('slug' => 'portfolio_item')
- )
- );
- }
- add_action('init', 'portfolio_list_custom_post');
- 2.Than add theme support and images size in custom post....
- add_theme_support( 'post-thumbnails' );
- add_image_size( 'portfolio-big', 298, 460, true );
- 3.Than query your post with shortcode in functions.php or shortcode.php file.....
- function portfolio_list_shortcode($atts){
- extract( shortcode_atts( array(
- 'title' => '',
- 'dsc' => '',
- 'more' => '',
- 'build' => '',
- ), $atts, 'portfolio' ) );
- $q = new WP_Query(
- array('posts_per_page' => 4, 'post_type' => 'portfolio_items')
- );
- $list = '
- <!----your content rapper--->
- <div id="portfolio" class="portfolio-area top-40">
- <div class="container">
- <div class="heading-area text-center bottom-30 wow fadeInUp" data-wow-duration="0.6s" data-wow-delay="0.3s">
- <h4 class="heading large">
- '.$title.'
- </h4>
- <span class="sub-heading">
- '.$dsc.'
- </span>
- </div>
- <div id="portfolio-area" class="top-40">
- <div class="row onepixel">';
- while($q->have_posts()) : $q->the_post();
- $idd = get_the_ID();
- $portfolio_big_img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-big' );
- $list .= '
- <!---your dynamic content--->
- <div class="col-md-3 col-sm-6 bottom-1 wow fadeInRight" data-wow-duration="0.6s" data-wow-delay="0.6s">
- <div class="portfolio-item">
- <div class="portfolio-image">
- <a href="portfolio-detail.html" title="">
- <img src="'.$portfolio_big_img[0].'" alt="" class="img-responsive">
- </a>
- </div>
- <div class="portfolio-info">
- <div class="portfolio-info-inner clearfix">
- <div class="portfolio-title">
- <h4 class="bottom-0">
- <a href="portfolio_detail.html">
- '.get_the_title().'
- </a>
- </h4>
- </div>
- <div class="portfolio-star">
- <a href="http://localhost/rrf/wp-content/uploads/2014/08/Desert1.jpg">
- <i class="fa fa-star-o">
- </i>
- </a>
- </div>
- <div class="portfolio-link">
- <a href="'.get_permalink().'">
- <i class="fa fa-link">
- </i>
- </a>
- </div>
- </div>
- </div>
- </div>
- </div>
- ';
- endwhile;
- $list.= '
- <!---your cotent rapper end----->
- </div>
- </div>
- <div class="button-group text-center top-30">
- <a href="'.$more.'" class="button wow fadeInRight" data-wow-duration="0.6s" data-wow-delay="0.3s">
- <span>
- View more projects
- </span>
- <span class="icon">
- <i class="fa fa-briefcase">
- </i>
- </span>
- </a>
- <a href="'.$build.'" class="button black wow fadeInLeft" data-wow-duration="0.6s" data-wow-delay="0.6s">
- <span>
- Build your own
- </span>
- <span class="icon">
- <i class="fa fa-database">
- </i>
- </span>
- </a>
- </div>
- </div>
- </div>
- ';
- wp_reset_query();
- return $list;
- }
- add_shortcode('portfolio', 'portfolio_list_shortcode');
- 4.Next call your shortcode in index.php like bellow ....
- <?php echo do_shortcode('[portfolio title="Recent Projects" dsc="the latest work of our team" more="#" build="#"]'); ?>
- বি:দ্র: যদি shortcode এর অংশ টুকু আলাদা file -এ করতে হয় তাহলে inc নামে একটি folder করে shorcode.php file এর মধ্যে করতে হবে এবং shorcode.php file টিকে functions.php file -এ call করতে হবে এভাবে.......
- include_once('inc/shortcode.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement