I have been working on a shortcode with help from this article: http://code.tutsplus.com/tutorials/create-a-shortcode-to-list-posts-with-multiple-parameters--wp-32199. I have tried to do what the article says, however I have tried to include a while loop. The problem is that when I paste it into the functions.php in the theme editor, the page crashes and returns internal server error 500.
My code looks like this:
add_shortcode('lande_galleri', 'lande_galleri_parameter');
function lande_galleri_parameter($atts) {
ob_start();
//Definer attributter
extract( shortcode_atts( array (
'post_type' => 'embm_beer',
'order' =>'date',
'orderby' => 'title',
'posts' => -1,
'land' => '',
), $atts));
//Definer parametre
$options = array(
'post_type' => $type,
'order' => $order,
'orderby' => $orderby,
'posts_per_page' => $posts,
'land' => $land,
);
$query = new WP_Query($options);
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();{ ?>
<div class="findoel"> <?php
echo '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr($post->post_title) . '">';
echo get_the_post_thumbnail($post->ID, 'medium');
echo '</a>';?>
</div>
<?php endwhile;
wp_reset_query();
wp_reset_postdata();
$myvariable = ob_get_clean();
return $myvariable;
}
}
Can anyone see the problem?
The point of the shortcode: I have a custom post type with a taxanomy. I would like to have the shortcode attribute "land", and then if the input is for example "germany", I would like the file to get all of the posts within the category, and they display the post thumbnails.
if ($query->have_posts())
line. What is that{
doing there? – s_ha_dum Oct 30 '15 at 19:18endif
. If you would indent carefully and avoid those nightmarish "template tag" style conditionals you'd spot this this stuff much more easily. – s_ha_dum Oct 30 '15 at 19:27