Skip to content

Instantly share code, notes, and snippets.

@wolffe
Last active December 16, 2015 03:38
Show Gist options
  • Save wolffe/5370815 to your computer and use it in GitHub Desktop.
Save wolffe/5370815 to your computer and use it in GitHub Desktop.
Show category posts in page, two-column formatting, cleared floats.
<?php
function pp_custom_content($atts) {
extract(shortcode_atts(array(
'type' => '',
'cat' => '',
), $atts));
$am_display = '';
$loop = new WP_Query(array('post_type' => $type, 'posts_per_page' => 10, 'category_name' => $cat));
while($loop->have_posts()) : $loop->the_post();
$am_display .= '<div style="float: left; width: 47%; margin-right: 16px; height: 200px; overflow: hidden;">';
$am_display .= '<div style="float: left; margin-right: 8px;"><a href="' . get_permalink() . '">' . get_the_post_thumbnail(get_the_ID(), 'thumbnail') . '</a></div>';
$am_display .= '<div><strong>' . get_the_title() . '</strong> (<a href="' . get_permalink() . '">Detalii</a>)<br>' . get_the_excerpt() . '</div>';
$am_display .= '</div>';
endwhile;
$am_display .= '<br clear="all">';
$am_display .= '<hr>';
return $am_display;
}
// usage: [pp type="post" cat="category"]
add_shortcode('pp', 'pp_custom_content'); // shortcode, function
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment