SHARE
TWEET

Post list shortcode

me2arafat May 21st, 2019 (edited) 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Shortcode: [lplist catname="" lpimgbg="" lpcatheading="" lpbtnurl=""]
  2. function hm_post_list_shortcode($atts, $content) {
  3. ob_start();
  4. $plistshortcode = shortcode_atts( array(
  5.     'catname'=>'$catatt',
  6.     'lpimgbg' => 'http://localhost/example.com/wp-content/uploads/2019/04/rotating-Whetstone-bass-fishing.jpg',
  7.         'lpcatheading'  => 'Heading Here',
  8.         'lpbtnurl' => 'https://www.google.com'
  9. ), $atts);?>
  10. <div class="lpcontainer" style="background-image: url(<?php echo esc_url($plistshortcode['lpimgbg']); ?>);">
  11.     <div class="lpcontent-box">
  12.         <h3><?php echo esc_html($plistshortcode['lpcatheading']); ?></h3>
  13.         <div class="lplistitem">
  14.             <?php
  15.        $the_query = new WP_Query(array(
  16.             'posts_per_page' => -1,
  17.             'category_name' => $plistshortcode['catname']
  18.         ));?>
  19.             <?php while($the_query->have_posts()) : $the_query->the_post(); ?>
  20.             //Wordpress Default custom field
  21.             <?php $sub_heading = get_post_meta($post->ID, 'sub_heading', true);?>
  22.             <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo $sub_heading; ?></a>
  23.             <?php endwhile;
  24.             wp_reset_postdata();
  25.         ?>
  26.         </div>
  27.         <div class="lpbtncontainer">
  28.             <a href="<?php echo esc_url($plistshortcode['lpbtnurl']); ?>"><?php echo esc_html('View Full List');?></a>
  29.         </div>
  30.     </div>
  31. </div>
  32. <?php $hm_postlist = ob_get_clean();
  33. return $hm_postlist;
  34. }
  35. add_shortcode( 'lplist', 'hm_post_list_shortcode' );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top