【问题标题】:Opening post in popup by clicking on it's shorter version通过单击它的较短版本在弹出窗口中打开帖子
【发布时间】:2013-06-06 11:07:53
【问题描述】:

您好,我需要为 wordpress 网站创建一个简单的弹出功能。

我的循环正在运行并正确显示帖子。单击后发布应出现在弹出窗口中。我到目前为止所得到的。除了添加 fancybox 来完成它的工作。

<a class="modalbox" rel="<?php echo $post->ID; ?>" href=" http://localhost/makijaz/?page_id=12">
     <article> ...Wordpress post </article>

我从其他线程得到了下面的那个,但它不起作用。

 $(".modalbox").on("click", function() {
       var postId = $(this).prop("rel");
       $(this).fancybox();

    });

href in 指向带有其他循环的模板页面。需要简单地对 PostID (它在 rel 中)进行 gram 并将其放入其他循环中以显示在弹出窗口中。

    <?php
/*
Template Name: Ajax Post Handler
*/
?>
<?php
    $post = get_post($_GET['id']);
?>
<?php if ($post) : ?>
    <?php setup_postdata($post); ?>
    <div class="whatever">
        <h2 class="entry-title"><?php the_title() ?></h2>
        <div class="entry-content">
            <?php the_content(); ?>
        </div>
    </div>
<?php endif; ?>

希望我已经说清楚了。

【问题讨论】:

    标签: php wordpress popup fancybox


    【解决方案1】:

    我猜你的页面模板没有 get_header 和 get_footer 所以在你的示例脚本中不会加载。

    <?php
      /*
      Template Name: Your Temp Name
      */
    get_header(); ?>
    

    【讨论】:

      【解决方案2】:

      如果你想传递 post id 以便$post = get_post($_GET['id']); 可以获取它,你可以尝试

      jQuery(document).ready(function ($) {
          $(".modalbox").on("click", function (e) {
              e.preventDefault();
              var postId = $(this).prop("rel");
              $.fancybox.open({
                  href: this.href + "&amp;id=" + postId,
                  type: "ajax"
              });
          });
      });
      

      JSFIDDLE

      【讨论】:

        猜你喜欢
        • 2018-02-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-31
        • 1970-01-01
        • 2016-07-27
        • 1970-01-01
        相关资源
        最近更新 更多