Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.