Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 25th Jul 2015, 09:18 AM   #1
Warrior Member
 
Join Date: 2014
Posts: 21
Thanks: 1
Thanked 0 Times in 0 Posts
Post
Need wordpress shortcode help
Share on: 
fb share twitter share gplus share more share

Guys this is my shortcode

function category_post_shortcode($atts){
extract( shortcode_atts( array(
'title' => '',
'link' => '',
'category' => '',
), $atts, 'category_post' ) );

$q = new WP_Query(
array( 'category' => $category, 'posts_per_page' => '3', 'post_type' => 'post')
);
$list = '<div class="latest_from_category"><h2 class="latest_frm_cat_title">'.$title.'</h2> <a href="'.$link.'" class="latest_more_link">more</a>';

while($q->have_posts()) : $q->the_post();
//get the ID of your post in the loop
$id = get_the_ID();

$post_excerpt = get_post_meta($id, 'post_excerpt', true);
$post_thumbnail= get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
$list .= '

<div class="single_cate_post floatleft">
'.$post_thumbnail.'
<h3>'.get_the_title().'</h3>
<p>'.$post_excerpt.'</p>
<a href="'.get_permalink().'" class="readmore">Read More</a>
</div>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('category_post', 'category_post_shortcode');

the problem is when i want to show specific post from specific category it doesn't do that, it shows all post from all category.Please help me to fix this code.

smsabbir480 is offline  
Unread 25th Jul 2015, 10:29 AM   #2
Warrior Member
 
Join Date: 2015
Location: Bosnia
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: Need wordpress shortcode help
Share on: 
fb share twitter share gplus share more share

5th line - delete comma on the end of line
tzman is offline  
Unread 25th Jul 2015, 03:47 PM   #3
HyperActive Warrior
 
Zenoth's Avatar
 
Join Date: 2014
Posts: 185
Thanks: 32
Thanked 39 Times in 34 Posts
Default
Re: Need wordpress shortcode help
Share on: 
fb share twitter share gplus share more share

Originally Posted by smsabbir480 View Post

= new WP_Query(
array( 'category' => , 'posts_per_page' => '3', 'post_type' => 'post')
);
Instead of 'category' use:
'cat' => if $category stores the category ID
'category_name' => if $category stores the category name

Zenoth is offline  
Closed Thread


Bookmarks

Tags
shortcode, wordpress


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:46 AM.