我向WordPress网站制作了单页HTML。共有4个部分和4个菜单项。部分ID和菜单ID相同(按页面顺序排序)。
当您单击菜单时,基本上以HTML格式显示滚动条会自动转到相关部分。当我把它变成WordPress时,一切都正常,但是当我点击菜单时却没有。
<!-- Menu section -->
<div class="col-md-8 col-sm-10 col-xs-4 main-menu text-right">
<ul class="menu-first hidden-sm hidden-xs">
<?php
global $post;
$args = array('post_type'=>'page','orderby'=>'menu_order','order'=>'ASC');
$myposts = get_posts($args);
foreach($myposts as $post) : setup_postdata($post);?>
<li><a href="#<?php echo $post->post_name; ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<a href="#" class="toggle-menu visible-sm visible-xs"><i class="fa fa-bars"></i></a>
</div> <!-- /.main-menu -->
<!-- Service -->
<div class="content-section" id="<?php echo $post->post_name; ?>">
<div class="container">
<div class="row">
<div class="heading-section col-md-12 text-center">
<h2>Services</h2>
</div> <!-- /.heading-section -->
</div> <!-- /.row -->
<div class="row">
<?php
global $post;
$args = array('post_type'=>'service','orderby'=>'menu_order','order'=>'ASC');
$myposts = get_posts($args);
foreach($myposts as $post) : setup_postdata($post); ?>
<div class="col-md-3 col-sm-6">
<div class="service-item" id="service-1">
<div class="service-icon">
<i class="fa fa-<?php echo $service_icon; ?>"></i>
</div> <!-- /.service-icon -->
<div class="service-content">
<div class="inner-service">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
</div> <!-- /.service-content -->
</div> <!-- /#service-1 -->
</div> <!-- /.col-md-3 -->
<?php endforeach; ?>
</div> <!-- /.row -->
</div> <!-- /.container -->
</div> <!-- /#services -->
相关代码也位于paste bin。
答案 0 :(得分:0)
我没有看到任何具有name
属性的锚点,您的链接实际上会跳转到。试试这个:
<?php foreach($myposts as $post) : setup_postdata($post); ?>
<div class="col-md-3 col-sm-6">
<div class="service-item" id="service-1">
<!-- Rest of markup removed for clarity -->
<h3>
<a name="<?php echo $post->post_name; ?>"><?php the_title(); ?></a>
</h3>
</div>
</div>
<?php endforeach; ?>