我有一个Wordpress插件(名为幻灯片,找到here),在幻灯片上方有一个分页,在ul(link to slideshow page)中显示为子弹。
我需要的是它以下列格式显示为数字:"图片1 of 15"。我是javascript的新手,我很难做到这一点。我能够识别(至少我认为我是)需要为此更改的代码部分。
PHP(link to file):
<div class="slideshow_container slideshow_container_<?php echo htmlspecialchars($styleName); ?>" style="<?php echo (isset($settings['preserveSlideshowDimensions']) && $settings['preserveSlideshowDimensions'] == 'false' && isset($settings['height']) && $settings['height'] > 0) ? 'height: ' . $settings['height'] . 'px;' : ''; ?> <?php echo (isset($settings['maxWidth']) && $settings['maxWidth'] > 0) ? 'max-width: ' . $settings['maxWidth'] . 'px;' : ''; ?>" data-session-id="<?php echo htmlspecialchars($sessionID); ?>" data-style-name="<?php echo htmlspecialchars($styleName); ?>" data-style-version="<?php echo htmlspecialchars($styleVersion); ?>">
<?php if(isset($settings['showLoadingIcon']) && $settings['showLoadingIcon'] === 'true'): ?>
<div class="slideshow_loading_icon"></div>
<?php endif; ?>
<div class="slideshow_content" style="display: none;">
<?php
if(is_array($views) && count($views) > 0)
{
foreach($views as $view)
{
echo $view->toFrontEndHTML();
}
}
?>
</div>
<div class="slideshow_controlPanel slideshow_transparent" style="display: none;"><ul><li class="slideshow_togglePlay" data-play-text="<?php _e('Play', 'slideshow-plugin'); ?>" data-pause-text="<?php _e('Pause', 'slideshow-plugin'); ?>"></li></ul></div>
<div class="slideshow_button slideshow_previous slideshow_transparent" role="button" data-previous-text="<?php _e('Previous', 'slideshow-plugin'); ?>" style="display: none;"></div>
<div class="slideshow_button slideshow_next slideshow_transparent" role="button" data-next-text="<?php _e('Next', 'slideshow-plugin'); ?>" style="display: none;"></div>
<div class="slideshow_pagination" style="display: none;" data-go-to-text="<?php _e('Go to slide', 'slideshow-plugin'); ?>"><div class="slideshow_pagination_center"></div></div>
<!-- WordPress Slideshow Version <?php echo SlideshowPluginMain::$version; ?> -->
<?php if(is_array($log) && count($log) > 0): ?>
<!-- Error log
<?php foreach($log as $logMessage): ?>
- <?php echo htmlspecialchars($logMessage); ?>
<?php endforeach; ?>
-->
<?php endif; ?>
JS(link to file):
prototype.activatePagination = function () {
if (this.settings.showPagination) {
this.$pagination.find(".slideshow_pagination_center").html("<ul></ul>");
var i = this.$pagination.find("ul");
i.html(""), this.$views.each(t.proxy(function (t) {
var s = "",
e = parseInt(t, 10) + 1,
n = this.$pagination.data("goToText");
("string" != typeof n || n.length <= 0) && (n = this.$pagination.attr("data-go-to-text")), t == this.currentViewID && (s = "slideshow_currentView"), i.append('<li class="slideshow_transparent ' + s + '" data-view-id="' + t + '" role="button" title="' + n + " " + e + '"><span class="assistive-text hide-text">' + n + " " + e + "</span></li>")
}, this)), this.$pagination.find("li").attr("tabindex", "0").click(t.proxy(function (i) {
var s, e = t(i.currentTarget);
this.currentlyAnimating || (s = e.data("viewId"), isNaN(parseInt(s, 10)) && (s = e.attr("data-view-id"), isNaN(parseInt(s, 10))) || (this.pauseAllVideos(), this.playState === this.PlayStates.PLAYING && (this.pause(this.PlayStates.TEMPORARILY_PAUSED), this.play()), this.animateTo(parseInt(s, 10), 0)))
}, this)), this.bindSubmitListener(this.$pagination.find("li")), this.$container.bind("slideshowAnimationStart", t.proxy(function () {
var i = this.$pagination.find("li");
i.each(t.proxy(function (i, s) {
t(s).removeClass("slideshow_currentView")
}, this)), t(i[this.currentViewID]).addClass("slideshow_currentView")
}, this)), this.settings.hidePagination ? (this.$container.mouseenter(t.proxy(function () {
this.$pagination.stop(!0, !0).fadeIn(100)
}, this)), this.$container.mouseleave(t.proxy(function () {
this.$pagination.stop(!0, !0).fadeOut(500)
}, this))) : this.$pagination.show()
}
}, i.Slideshow.prototype.activatePauseOnHover = function () {
this.settings.pauseOnHover && (this.$container.mouseenter(t.proxy(function () {
clearTimeout(this.pauseOnHoverTimer), this.playState !== this.PlayStates.PAUSED && (this.pauseOnHoverTimer = setTimeout(t.proxy(function () {
this.pause(this.PlayStates.TEMPORARILY_PAUSED)
}, this), 500))
}, this)), this.$container.mouseleave(t.proxy(function () {
clearTimeout(this.pauseOnHoverTimer), this.playState !== this.PlayStates.PAUSED && this.interval === !1 && this.play()
}, this)))
}
}();
slideshow_jquery_image_gallery_backend_script_scriptsloadedFlag = !0;
我希望这是足够的信息。还有一个名为all.backend.min.js的文件我不确定是否需要,但以下是link以防万一。
此外,如果任何人有一个替代插件,他们可以建议已经做了类似的事情,这就足够了。我可以编辑CSS来显示我想要的方式,但是我用Javascript来编辑现有的插件还不够好。
答案 0 :(得分:4)
我们可以添加CSS和jQuery来隐藏和修改滑块的输出。它是纯粹的额外代码而不触及原始代码。可以在functions.php
上使用,或者更好地在custom plugin上使用。
使用CSS隐藏内容:
# Required: PHP 5.3
# See Lambda functions: https://stackoverflow.com/q/1909002/1287812
add_action( 'wp_head', function() {
?>
<style>
.slideshow_container_style-light .slideshow_pagination ul li {
background: none !important; /* was the bullet img */
}
span.assistive-text.hide-text { /* unhide text */
display: block !important;
font:15px arial,sans-serif;
position: initial !important;
text-shadow: #000 1px 1px 1px;
color:#fff;
}
</style>
<?php
});
使用jQuery我们修改:
add_action( 'wp_enqueue_scripts', function(){ wp_enqueue_script('jquery'); } );
add_action( 'wp_footer', function() {
?>
<script>
jQuery(document).ready(function($) {
function startUp() {
$("span.assistive-text.hide-text").each(function() {
var text = $(this).text();
text = text.replace("Go to slide", "");
$(this).text(text);
});
}
/* Wait slideshow start to fire the replace function */
var timeoutID = window.setTimeout( startUp, 1500 );
});
</script>
<?php
});
结果是删除子弹并显示数字。要创建导航Picture 1 of 15
,需要进一步使用jQuery,但Stack Overflow search无法帮助回答。