在弹出窗口中的滑块中显示OnClick打开的帖子

时间:2016-07-12 作者:Hrushi Patil

在附着的图像中,帖子以滑块样式显示。当我在滑块中单击post时,假设CArd5,则该帖子的详细信息应显示在弹出窗口中,例如:缩略图、摘录等,弹出的html代码已包含在末尾,如“”

Function addcards()
    {
      $the_query = new WP_Query( array( \'post_type\' => \'cards\', \'post_status\' => \'publish\' ));
    ?>
    <body>

          <div id="demo">
            <div class="container">
              <div class="row">
              <div class="row">
                <div class="span12">
                  <div id="owl-demo" class="owl-carousel">


    <?php
    while ($the_query->have_posts()) 
        {
        $the_query->the_post();
        ?>
        <div class="item orange">
         <!-- <a href = "#modal">  -->
         <!-- href = "#modal" -->
         <form action="" method = "post">
          <a href = "#modal" id="<?php echo get_the_title();?>"  onClick="reply_click(this.id)" 
          class="lbp-inline-link-1 cboxElement" style="text-decoration:none">
        <!-- <div style="display: none;">
          <div id="lbp-inline-href-1" style="padding:10px; background: #fff;">
          <p>This content will be in a popup.</p>
          </div>
        </div> -->
        <div class="squarebox">
        <div class="innersquare">
        <div>
        <table>
        <tr>
          <td align="left"><p><?php echo get_the_author();?></p></td>
          <td align="left"><p><?php echo get_the_date();?></p></td>
        </tr> 
        </table>
        </div>

        <div>
        <h3><?php echo get_the_title();?></h3>
        </div>
        <div>
          <img src="<?php echo the_post_thumbnail_url();?>">
        </div>
        <div>
          <p><?php  the_excerpt(); ?></p>
        </div>

        <div class="fb-share-button" data-href="https://www.facebook.com/Techmatters-125167747841183/" data-layout="button" data-mobile-iframe="true"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.facebook.com%2FTechmatters-125167747841183%2F&amp;src=sdkpreparse">Share</a></div>
        <script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
        <script type="IN/Share" data-url="https://www.facebook.com/Techmatters-125167747841183/"></script>


      </div>
      </div>
    </a>
    </form>
    <?php $postid = get_the_title(); ?>
      </div>


        <?php
        }
      ?>

                  </div>
                </div>
              </div>
            </div>
        </div>
    </div> 






    <script type="text/javascript">
    function reply_click(clicked_id)
    {
        var userID = clicked_id;
        alert(userID);

    }   
    </script>





    <!-- popup html -->

    <div class="remodal" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
      <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
      <div>
        <h2 id="modal1Title" class="results">

         </h2>
        <p id="modal1Desc">
          Responsive, lightweight, fast, synchronized with CSS animations, fully customizable modal window plugin
          with declarative state notation and hash tracking.
        </p>
      </div>
      <br>
      <button data-remodal-action="cancel" class="remodal-cancel">Cancel</button>
      <button data-remodal-action="confirm" class="remodal-confirm">OK</button>
    </div>

    <?php
    }
    add_shortcode(\'cards\',\'addcards\');
    ?>

enter image description here

2 个回复
SO网友:Mr. M

我给你一个想法,你必须使用jQuery弹出窗口,下面的语法将在HTML弹出窗口中为你提供当前的帖子数据。

 while ($the_query->have_posts()): $the_query->the_post(); 

        echo \'<div class="non-popup">\';
            echo \'<div class="card-title" id="card-\'.get_the_title.\'">\'.get_the_title().\'</div>\';
               write you front end code + html (http://screenshotlink.ru/eff3d7431f4fbcd6a03ca5fcbbc41cdd.png) 
        echo \'</div>\';
        echo \'<div class="popup" style="display:none;">\';

           echo \'<div class="popup-title">\'.get_the_title().\'</div>\';

             write your popup html + code      

        echo \'</div>\';

endwhile; 
以下是jQuery:

  $(document).ready(function(){
      $(".card-title").on(\'click\',function(){          
           $(this).siblings().css(\'display\',\'block\'); 
      });
  });

SO网友:Neeraj Kumar

有很多方法可以做到这一点,但我建议使用ajax。单击任何帖子时,获取post\\u id并将其传递给ajax函数。在您首先调用的ajax函数(在function.php中)中获取id并获取post数据。在ajax上可以做两件事:1)附加完整的html(弹出式html)或2)仅在html中附加缩略图、标题和摘录值

相关推荐

如何修改WP_INCLUDE/BLOCKS/LATEST_posts.php

我是WordPress开发的初学者,希望得到一些帮助。我在一个简单的WordPress网站上工作。基本上,用户希望在主页上显示最新的帖子。我使用了最新帖子块,并将其设置为显示整个帖子内容,现在用户不希望帖子标题链接到单个帖子页面(因为帖子的内容显示在主页上)。如何安全地修改模板文件,使其像h2标记一样使用,而不是在主题中使用的href标记。我知道您可以创建子主题并修改wp_content 文件,但我不确定如何处理中的文件wp_include. 我读到一些关于修改functions.php 但我不确定,如果