January 20, 2015 at 7:57 pm
Hello.
I am getting duplicated attached images in the frontend, I cant find where in Virtue theme is this happening. I also oppened a case in WP forums here:
*Login to see link
The plugin User-Submitted-Posts needs some code in functions.php so the uploaded images turn featured images and then they are shown in the published post (I followed this tutorial: *Login to see link The problem is when I add that code in functions.php, I get the featured pictures above the topbar, in all my pages and posts. Whyy do you think this is happening?
an example page with the error is: *Login to see link and a screenshot is: *Login to see link
The functions.php file got like this:
<?php
// featured images
add_theme_support('post-thumbnails');
set_post_thumbnail_size(300, 300, true); // width, height, hard crop
// display user-submitted images
function usp_display_images($content) {
global $post;
$args = array('order'=>'ASC', 'post_type'=>'attachment', 'post_parent'=>$post->ID, 'post_mime_type'=>'image', 'post_status'=>null);
$items = get_posts($args); ?>
<div class="usp-image">
<?php foreach ($items as $item) {
$atts = wp_get_attachment_image_src($item->ID, 'medium');
$full = wp_get_attachment_image_src($item->ID, 'full'); ?>
<a href="<?php echo $full[0]; ?>" target="_blank"><img src="<?php echo $atts[0]; ?>" width="<?php echo $atts[1]; ?>" height="<?php echo $atts[2]; ?>" alt=""></a>
<?php }
$author = get_post_meta($post->ID, 'user_submit_name', true);
$url = get_post_meta($post->ID, 'user_submit_url', true);
if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
echo '<span class="usp-author-link">Posted by <a href="' . $url . '">' . $author . '</a></span> ';
} ?>
</div>
<?php return $content;
}
add_filter('the_content', 'usp_display_images');
?>
and I believe I didnt touch the template single.php file because I didnt find it.