[英]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)。
<?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)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</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)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</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.