为什么要编写Java脚本,而不是重复循环Main WordPress

时间:2017-02-24 作者:hamid

我不会写英语所以,有一个问题,我希望你能理解

为什么要编写javascript,不要重复,在帖子中,在每篇帖子中。我会影响每个帖子的图片,但不是所有帖子都能工作,只有第一个帖子能工作。当然不是其他帖子,附件文件图片和代码索引。php我的网站enter image description here

<!DOCTYPE html>
<html>
<head>
<title>hello world </title>
<link rel="stylesheet" type="text/css" href="<?php bloginfo(\'stylesheet_url\'); ?>">
<link rel="stylesheet" type="text/css" href="<?php bloginfo(\'template_url\'); ?>/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="<?php bloginfo(\'template_url\'); ?>/responsive.css">

</head>
<body>
<header>
<!--prog menu home-->
<nav>
<div id="myNav" class="overlay">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
  <div class="overlay-content">
  <?php
 wp_nav_menu( array(
\'menu\' => \'menu 1\',
\'items_wrap\' => \'%3$s\' ,
 \'container\' => \'\' ,
 \'theme_location\' => \'navb-header\'
) );
?>
  </div>
</div>
<li class="fa fa-bars fa-2x" onclick="openNav()"></li>
<a href="/" class="active">WallTure.Com<i class="fa fa-home fa-2x"></i></a>
</nav>
<!--end prog menu home-->
<!--prog menu category-->
<section>
<div class="chip">
<a onclick="document.getElementById(\'id01\').style.display=\'block\'" ><i id="search" ></i>
  Search</a>
</div>
<div class="chip">
<a onclick="document.getElementById(\'id02\').style.display=\'block\'" ><i id="box"></i>
  Category</a>
</div>
</section>
<!--start body search-->
<div id="id01" class="modal">

  <div class="modal-content-search animate">
    <div class="imgcontainer">
      <span onclick="document.getElementById(\'id01\').style.display=\'none\'" class="close" title="Close Modal">&times;</span>
     Search The In Site
    </div>

    <div class="container">
      <?php get_search_form(); ?>
    </div>

    <div class="container" style="background-color:#f1f1f1">
      <button type="button" onclick="document.getElementById(\'id01\').style.display=\'none\'" class="cancelbtn button">Cancel</button>
    </div>
  </div>
</div>
<!--end body search-->
<!--start body category-->
<div id="id02" class="modal">
  <form class="modal-content animate">
    <div class="imgcontainer">
      <span onclick="document.getElementById(\'id02\').style.display=\'none\'" class="close" title="Close Modal">&times;</span>
      Choose Category Wallpaper
    </div>

    <div class="container">

        <?php wp_list_categories(array(
        \'title_li\'=>\'\',
        \'orderby\' => \'name\',
        \'include\' => array( 5,6,8,9,10,7,12,11 ) ));
        ?>
    </div>

    <div class="container" style="background-color:#f1f1f1">
      <button type="button" onclick="document.getElementById(\'id02\').style.display=\'none\'" class="cancelbtn button">Cancel</button>

    </div>
  </form>
</div>
<!--end body category-->
<!--end prog menu category-->
</header>

<section><!--start post body-->
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,\'large\'); ?>
<div class="bodypost">

<div class="post-img" >
<div class="ourdownload">
<a href="javascript:void(0)" class="closedownload" onclick="closedownload()">&times;</a>
<div class="download-content">
  <li><?php the_time(\'d-m-y\') ?> | <?php the_time(\'m-h\') ?></li>
 <li> org size : 20*20</li>
 <li> other size : 20*20</li>

  </div>
</div>
<i class="fa fa-download fa-2x post-img-download" onClick="opendownload()" ></i>
<div class="ourinformation">
<a href="javascript:void(0)" class="closeinformation" onclick="closeinformation()">&times;</a>
<div class="information-content">

  <li>our size : 20*20</li>
 <li> org size : 20*20</li>
 <li> other size : 20*20</li>

  </div>
</div>
<i class="fa fa-exclamation-circle fa-2x post-img-note" onClick="openinformation()"></i>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" rel="nofollow"><?php the_post_thumbnail(\'large\'); ?></a>
</div>
<div class="name-post"><a href="<?php the_permalink(); ?>" title="<?php echo get_the_title(); ?>" rel="nofollow">
<?php the_title(); ?>
</a></div>
<div class="name-category"><?php the_category(\', \') ?></div>
</div>
<?php echo \'
<script>
function openNav() {
   document.getElementById("myNav").style.width = "100%";
}

function closeNav() {
   document.getElementById("myNav").style.width = "0%";
}
function opendownload(){
    var x=document.getElementsByClassName("ourdownload");
    x[0].style.width="100%";
    }
function closedownload(){var x=document.getElementsByClassName("ourdownload");
    x[0].style.width="0%";}
function openinformation(){var z=document.getElementsByClassName("ourinformation"); z[0].style.width = "100%";}
function closeinformation(){var z=document.getElementsByClassName("ourinformation"); z[0].style.width = "0%";}
</script> \' ?>
<?php endwhile; ?>
<?php endif; ?>

</section><!--end post body-->

<div class="number-body">
<div class="numall">
Total Wall : <?php //Count Published Posts Mandegarweb.com
echo $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = \'post\' AND post_status = \'publish\'"); ?></div>
<div class="pagination">
<?php if (function_exists(\'mw_pagination\')) mw_pagination(); ?>
</div>
</div>
<footer>Wallture.com & Wallture.ir beging 2015,2016,2017 continue ...</footer>
سس
<script>
// Get the modal
var modal = document.getElementById(\'id02\');
var modal2 = document.getElementById(\'id01\');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }if (event.target == modal2){
        modal2.style.display = "none";
    }
    }
</script>
</body>
</html>

1 个回复
最合适的回答,由SO网友:MahdiY 整理而成

我想你用过#id 设置javascript操作(事件)。使用.class 在jQuery选择器中。在浏览器中打开控制台并查看javascript错误。