2015-02-07 17:11
浏览 37


I'm editing a wordpress theme. (this: Onetone theme) I'm trying to make some pages like the home seeing the theme don't provide it (I've already contacted them). So in each page i would have some < section > with a specific id and a menu with the link for each of them.

I've already make a proof:

$sections = array('home','A','B','C','D');// home,A,B,C,D are the ids of the section added manually
foreach ($sections as $section) {
    echo '<li  class="onetone-menuitem"><a class="onetone-menu-link" id="onetone-menu-'.$section.'" href="#'.$section.'" >

But as you can see,I was not able to get programmatically the ids of the sections. How can i do it? Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqdtgiw4736 2015-02-08 08:29

    Using jQuery to extract the section id's, here is a basic working example to get you started. You canpaste this code in a php or html file and call it from your browser. The only thing you will need the change is the location of jquery.js.

    <!doctype html>
    <script type='text/javascript' src='http://localhost/lccs/wp-includes/js/jquery/jquery.js?ver=1.11.1'></script>
        display: inline-block;
        padding: 1em;
        background-color: #444;
    <script language="javascript">
                var menucode="<span class='menu-item'><a href='#"+this.id+"'>Item</a></span>";
    <main id="main" class="site-main" role="main">
    <aside class="menu-aside">
    <span id="menu-items"></span>
    <article class='student type-student status-publish hentry'>
    <section id="seca-1"><h2>Section A</h2>
    <section id="seca-2"><h2>Section B</h2>
    <section id="seca-3"><h2>Section C</h2>
    <section id="seca-4"><h2>Section D</h2>
    点赞 打赏 评论

相关推荐 更多相似问题