【问题标题】:WordPress: Countdown before opening the post?WordPress:打开帖子之前的倒计时?
【发布时间】:2014-01-22 05:22:48
【问题描述】:

我搜索并找到了一些 html、jquery 或 javascript 重定向计数器,但我不知道我可以将它与 wordpress 一起使用。 我想让访问者在打开帖子(简码)之前等待 20 秒,然后登录会看到帖子(简码)。

像这样:

function restrict( $atts, $content = null ) {
if ( is_user_logged_in() ) {
    return '<p>I am logged and I can see this</p>';
} else {
    echo HERE SHOULD BE THAT COUNTER;
}}
add_shortcode( 'restrict', 'restrict' );

更新: 使用给定的答案我试过:

function restrict( $atts, $content = null ) {
$cnt = "http://www.youtube.com/embed/HESJgpYYUyM";
if ( is_user_logged_in() ) {
?>
<div class="video" style="display:none;"><iframe width="100%" height="400" src="<?php echo $cnt; ?>?autoplay=1" frameborder="0" scrolling="no" allowfullscreen style="visibility:hidden;" onload="this.style.visibility=\'visible\';"></iframe><br><br></div>
<div class="wait">Please wait 20 seconds.</div>
<script type="text/javascript">
$(document).ready(function() {
    $(".wait").delay(10000).hide(0, function() {
        $(".video").show();
    });
});
</script>
        <?php
}}
add_shortcode( 'restrict', 'restrict' );

*

Uncaught TypeError: Property '$' of object [object Object] is not a function 
Refused to display 'http://www.youtube.com/embed/HESJgpYYUyM' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
Uncaught SyntaxError: Unexpected token ILLEGAL 

*

到目前为止:

function restrict( $atts, $content = null ) {
$cnt = "http://www.youtube.com/embed/HESJgpYYUyM";
if ( is_user_logged_in() ) {
?>
<div class="video" style="display:none;"><iframe width="100%" height="400" src="<?php echo $cnt; ?>?autoplay=1" frameborder="0" scrolling="no" allowfullscreen style="visibility:hidden;" onload="this.style.visibility=\'visible\';"></iframe><br><br></div>
<div class="wait">Please wait 20 seconds.</div>
<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery(".wait").delay(10000).hide(0, function() {
        jQuery(".video").show();
    });
});
</script>
        <?php
}}
add_shortcode( 'restrict', 'restrict' );

Uncaught SyntaxError: Unexpected token ILLEGAL

【问题讨论】:

  • 你想将用户重定向到计数器页面,然后再次将他们重定向到帖子OR你只是想显示一个计数器来代替短代码文本吗?
  • 我想在简码文本上显示计数器。

标签: wordpress counter countdown


【解决方案1】:

您的代码非常正确。在这里,我强调了您必须放置代码的位置。您需要将此代码放在您的functions.php中。

function restrict_func() {
    if ( is_user_logged_in() ) {
        return '<p>I am logged and I can see this</p>';
    } else {
        ?>
        <script>
            jQuery(document).ready(function() {
                // script code here.
            }
        </script>
        <!-- And HTML HERE, I've added sample HTML below -->
        <p class="hide_after_20_sec"></p>
        <p class="show_after_20_sec"></p>
        <?php
    }
}
add_shortcode( 'restrict', 'restrict_func' );

【讨论】:

  • 我尝试了您的建议,但遇到了视频问题。文字作品,但我的网站是视频网站...
猜你喜欢
  • 2014-06-04
  • 1970-01-01
  • 1970-01-01
  • 2014-07-27
  • 1970-01-01
  • 2019-10-07
  • 2011-06-21
  • 2021-12-28
  • 1970-01-01
相关资源
最近更新 更多