Im creating a wordpress site with WP-Ecommerce. My client asked for a functionality that i cant figure out how to make. He has a product with a long description and he wants multiple "read on" l开发者_StackOverflow中文版inks to hide parts of it. It should be done in javascript so that client wont be redirected anywhere when he clicks on read more (extended content should just scroll open.)
it would be nice to find a plugin but i cant seem to find one.
A plugin for this would be easy to write. You just need to write a shortcode that adds the javascript to do what you want. The jQuery accordion for instance.
<?php
function add_accordion_js() {
?>
<script>
$(function() {
$( ".accordion" ).accordion();
});
</script>
<?php
}
function jquery_accordion($atts, $content = null) {
return '<div class="accordion">' . do_shortcode($content) . '</div>';
}
add_action('wp_head', 'add_accordion_js');
add_shortcode('accordion', 'jquery_accordion');
?>
Something like that can be added to your functions.php and you would wrap everything you need to collapse in [accordion][/accordion] tags... and it will break the sections down at the tags...
somhow i couldn't get accordion() function to work but Steve pointed me in right direction and i got this going:
function add_accordion_js() {
?>
<script>
jQuery(function() {
jQuery(".accordion").hide();
jQuery(".opener").click(function (e) {
jQuery(this).parent().next('.accordion').slideDown('fast');
jQuery(this).slideUp();
});
});
</script>
<?php
}
function jquery_accordion($atts, $content = null) {
return '<span class="opener">(read more)</span><div class="accordion">' . do_shortcode($content) . '</div>';
}
add_action('wp_head', 'add_accordion_js');
add_shortcode('accordion', 'jquery_accordion');
and things i needed to hide under read more link i wrapped in [accordion][/accordion]tags
精彩评论