简体   繁体   English

我无法将我的滑块集成到 wordpress 中

[英]I am unable to integrate my slider inside wordpress

I have built a slider using html and css.我已经使用 html 和 css 构建了一个滑块。 I want to integrate it into wordpress.我想将它集成到 wordpress 中。 My slider works fine.我的滑块工作正常。 I have added the css and JS code in custom css and JS snippet plugin.我在自定义 css 和 JS 片段插件中添加了 css 和 JS 代码。 While I am placing below php code inside my theme's function.php file.当我将 php 代码放在主题的 function.php 文件中时。 Now the first image gets displayed but others are not.现在第一个图像被显示,但其他图像没有。 Also slider is kind of messed up.滑块也有点乱。

I hardcoded the html in functions.php file and the slider works fine.我在functions.php文件中对html进行了硬编码,滑块工作正常。 Can someone please check my php code below to see what am i doing wrong?有人可以检查我下面的 php 代码,看看我做错了什么吗? (css and JS are working fine. im unable to integrate html in wordpress properly). (css 和 JS 工作正常。我无法在 wordpress 中正确集成 html)。

  • Also Im displaying the slider on page by putting below code inside a shortcode which is working.我还通过将下面的代码放入正在工作的短代码中来在页面上显示滑块。
  • I am using Custom Post Type UI plugin to get images.我正在使用自定义帖子类型 UI 插件来获取图像。 I have created 2 posts with featured images.我创建了 2 个带有特色图片的帖子。 Now im trying to get those two featured images into my slider.现在我试图将这两个特色图像放入我的滑块中。
<?php //functions.php file

function mySlider(){
    $args = array(
    'post_type' => array('mx-slides'),
        'post_status' => array('publish'),
        'posts_per_page' => array('-1'),
        'order' => array('DESC'),
    );

        $query = new WP_Query( $args );
    if($query-> have_posts()){

        ?>

<!-- Container for the image gallery -->
<div class="container">
  <div class="mySlides">
    <div class="numbertext">6 / 6</div>
       <?php    while ( $query->have_posts() ) {
        $query->the_post();
        $img = the_post_thumbnail();

      ?>
          <?php For($i=0;$i<=2;$i++) {
           ?>
      <img src="<?php $img; ?>" style="width:100%;">
           <?php } ?>
<?php } ?>
  </div>

  <!-- Next and previous buttons -->
  <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
  <a class="next" onclick="plusSlides(1)">&#10095;</a>

  <!-- Image text -->
  <div class="caption-container">
    <p id="caption"></p>
  </div>

  <!-- Thumbnail images -->
  <div class="row">
    <?php   while ( $query->have_posts() ) {
        $query->the_post();
        $img = the_post_thumbnail();
      ?>
        <?php // foreach ($img as $imgx)
                 For($i=0;$i<=5;$i++) 
 {
           ?>
      <div class="column">
        <img class="demo cursor" src="<?php echo $img; ?>" style="width:100%" onclick="currentSlide(1)" alt="No Image">
          </div>
           <?php } ?>

<?php } ?>
</div>
</div>

<?php 

    } 
wp_reset_postdata();
}
add_shortcode('mx-slider', 'mySlider'); 
    ?>
   ?>

Please check with my fixed $arg.请检查我的固定 $arg。 the format of posts_per_page is integer. posts_per_page 的格式是整数。

<?php //functions.php file
    
    function mySlider() {
      $args = array(
        'post_type' => 'mx-slides',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'order' => 'DESC',
      );
    
      $query = new WP_Query($args);
      if ($query->have_posts()) {
    
    ?>

    <!-- Container for the image gallery -->
    <div class="container">
      <div class="mySlides">
        <div class="numbertext">6 / 6</div>
        <?php while ($query->have_posts()) {
          $query->the_post();
          $img = get_the_post_thumbnail_url();
        ?>
          <?php for ($i = 0; $i <= 2; $i++) {
          ?>
            <img src="<?php echo $img; ?>" style="width:100%;">
          <?php } ?>
        <?php } ?>
      </div>

      <!-- Next and previous buttons -->
      <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
      <a class="next" onclick="plusSlides(1)">&#10095;</a>

      <!-- Image text -->
      <div class="caption-container">
        <p id="caption"></p>
      </div>

      <!-- Thumbnail images -->
      <div class="row">
        <?php while ($query->have_posts()) {
          $query->the_post();
          $img = get_the_post_thumbnail_url();
        ?>
          <?php // foreach ($img as $imgx)
          for ($i = 0; $i <= 5; $i++) {
          ?>
            <div class="column">
              <img class="demo cursor" src="<?php echo $img; ?>" style="width:100%" onclick="currentSlide(1)" alt="No Image">
            </div>
          <?php } ?>

        <?php } ?>
      </div>
    </div>

<?php

  }
  wp_reset_postdata();
}
add_shortcode('mx-slider', 'mySlider');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法在 docker wordpress 安装中升级我的 PHP 版本 - I am unable to upgrade my PHP version in my docker wordpress installation MYOB Exonet如何工作? 我可以将其集成到我的WordPress网站吗? - How MYOB Exonet work? Can I integrate it to my WordPress website? 我无法在Codeigniter中调整图像大小 - I am unable to resize my image in codeigniter Wordpress 自定义主题 - 我无法使用此代码显示徽标 - Wordpress custom theme - I am unable to display the logowith this code 无法将下载的HTML模板集成到wordpress主题中 - Unable to integrate downloaded HTML template in wordpress Theme 我正在尝试将模板与“ i18n扩展程序”集成在一起。 坚持与xgettext集成 - I am trying to integrate my template to twig with “The i18n Extension”. Stuck on integration with xgettext 我想将贝宝支付网关集成到我的应用程序中,但是我无法传递金额变量 - I want to integrate paypal payment gateway to my application but i am not able to pass the amount variable 我试图让一个jquery插件在我的wordpress网站上工作 - I am trying to get a jquery plug in to work on my wordpress site 我无法在 php 中链接 href 标签 - I am unable to link href tag inside php 在回声内使用回声的语法(wordpress滑块) - Syntax for using echo inside an echo (wordpress slider)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM