1

私は次のコードで手動でライトボックスを開くために prettyPhoto API を使用しています:

api_images  ['images/fullscreen/image1.jpg','images/fullscreen/image2.jpg','images/fullscreen/image3.jpg'];
api_titles = ['Title 1','Title 2','Title 3'];
api_descriptions = ['Description 1','Description 2','Description 3']
$.prettyPhoto.open(api_images,api_titles,api_descriptions);

私が直面している問題は、説明の値が Wordpress の WYSIWYG から取得され、コードがランダムな html タグや句読点などで簡単に壊れてしまうことです。

  <script type="text/javascript">
    $(document).ready(function() {
        $('#menu-item-1006').on('click', function(e) {
            e.preventDefault();
            var images = new Array();
            var descriptions = new Array();
            var titles = new Array();
<?php
$i = 0;
$images = new WP_Query(array('post_type' => 'clearance', 'showposts' => -1, 'order' => 'menu_order', 'orderby' => 'ASC'));
if ($images->have_posts()) : while ($images->have_posts()) : $images->the_post();

        $featured = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
        ?>
                            images[<?php echo $i; ?>] = '<?php echo $featured[0]; ?>';
                            titles[<?php echo $i; ?>] =  '<?php the_title(); ?>'
                            descriptions[<?php echo $i; ?>] = '<?php echo get_the_content(); ?>';

        <?php
        $i++;
    endwhile;
else:
    ?>
<?php endif; ?>

            $.prettyPhoto.open(images, titles, descriptions);
        }) 
    });    
</script>

get_the_content() 関数をフィルタリングして、エラーなしで出力するにはどうすればよいですか? ありがとう!

4

3 に答える 3

1

簡単な解決策は次のとおりです。

交換

<?php echo get_the_content(); ?>

<?php echo preg_replace('/\<[^\>]+\>/s', '', get_the_content()); ?>
于 2013-07-04T17:55:16.423 に答える