0

私はブログテンプレートを使用しています.squarespace 6は、.html /へのアクセスを許可せず、.cssへのアクセスを制限しています

ブログ投稿を作成するたびに、タグとカテゴリを追加しますが、これらのタグ/カテゴリはブログ投稿の下部に配置されます。それらをサイドバーに移動しようとしています。

問題は、ページごとに複数のブログ投稿があることです。jquery を使用して.tags.categoryクラスを選択し、次のような with コードの.sidebar前に移動しようとしています。.date

$(document).ready(function(){

var $categories = $('div.categories').parent('article');
var $spanDate =('span.date').parent('article');  

$categories.insertBefore($spanDate);

});

(このコードは .categories の例にすぎません)

問題は、このコードがすべてのブログ投稿からタグ/カテゴリを取得し、それをすべてのサイドバーに適用するため、カテゴリとタグが混同されることです.

親記事の.tagsとを選択し、それらを に移動するコードを取得しようとしています。同じ親の。.categorysidebararticle

これをすべてのブログ投稿に適用したいので、特定の ID を使用することはできませんが、タグ/カテゴリはその投稿内にとどまる必要があります。

挿入されたコードはたくさんありますが、HTML の基本構造は次のとおりです。

<blog>  //Wrapper for the whole blog page
<content>
<article> //Each article is a blog entry
  <section class="main"> //Contains the contents of the blog entry. This also has a dynamically generated ID, 
    //Blog Entry Content Goes Here
    <footer>
      <div class="meta"> //Contains the tags/categories I try to pull out of the DOM
        <span class="tags"></span> //Contains the tags each wrapped in an `<a>`
        <span class="categories"></span> //Contains the category tags
      </div>
    </footer>
   </section>
   <section class="sidebar"> //This is where I'm trying to place the tags/categories
     <span class="date"></span> //I try to place the category before this in the jquery code above
     <more spans....> // I try to place the tags appended onto the end of the sidebar (code not shown above).
   </section>
</article>
<article></article> //More blog entries with same structure
<article></article> //More blog entries with same structure
<article></article> //More blog entries with same structure
</content>
</blog>
4

1 に答える 1

0

私があなたを正しく理解しているなら、これはすべきです:

$('div.categories').each(function(){
    var $this = $(this);
    var $date = $this.closest("article").find(".date");

    $this.insertBefore($date);
});

重要なのは、それぞれについて、すべてではなく.categories関連するものを見つけることです。また、コードは、提供された html で何も実行しないでください。あなたもあなたも の直接の親を持っていません。.date.date.categories.datearticle

于 2013-02-07T14:31:14.520 に答える