Skip to content

Instantly share code, notes, and snippets.

@roeeyossef
Created April 28, 2015 16:40
Show Gist options
  • Save roeeyossef/d862ce4e0190bc3ffe60 to your computer and use it in GitHub Desktop.
Save roeeyossef/d862ce4e0190bc3ffe60 to your computer and use it in GitHub Desktop.
הצגת פוסטים אחרונים מקטגורייה מסוימת בוורדפרס
function my_post_by_category() {
// the query
$the_query = new WP_Query( array( 'category_name' => 'XXXXXX', 'posts_per_page' => 4 ) );
// The Loop
if ( $the_query->have_posts() ) {
$string .= '<ul class="postsbycategory widget_recent_entries">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
if ( has_post_thumbnail() ) {
$string .= '<li>';
$string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 50, 50) ) . get_the_title() .'</a></li>';
} else {
// אם לא נמצאו תמונות
$string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';
}
}
} else {
// לא מצאו פוסטים
}
$string .= '</ul>';
return $string;
/* Restore original Post Data */
wp_reset_postdata();
}
// הוסיפו shortcode
add_shortcode('categoryposts', 'my_post_by_category');
// אפשרו שימוש של shortcode בווידג׳טים
add_filter('widget_text', 'do_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment