2016-07-10 3 views
0

我々は、ページ固有のJSを実行することができます。WordPress Sage:特定のシングルまたはアーカイブのCPTページでJSを焼く方法は? WordPressのセージのmain.jsで

var Sage = { 
    // All pages 
    'common': { 
    init: function() { 
     // JavaScript to be fired on all pages 
    }, 
    finalize: function() { 
     // JavaScript to be fired on all pages, after page specific JS is fired 
    } 
    }, 
    // Home page 
    'home': { 
    init: function() { 
     // JavaScript to be fired on the home page 
    }, 
    finalize: function() { 
     // JavaScript to be fired on the home page, after the init JS 
    } 
    }, 
    // About us page, note the change from about-us to about_us. 
    'about_us': { 
    init: function() { 
     // JavaScript to be fired on the about us page 
    } 
    } 
}; 

しかし、どのように特定の単一またはアーカイブCPTページにJSを実行するには?

答えて

2

JSを起動させたいページ/ポスト/アーカイブの本文でクラス名をチェックし、そのうちの1つを使用します。たとえば、 'work'というカスタムの投稿タイプがある場合、workアーカイブのbody要素のクラスはpost-type-archive-workです。 Paul Irish's post

をチェックしてください詳しくは

// Note the change from about-us to about_us. 
    'post_type_archive_work': { 
    init: function() { 
     // JavaScript to be fired on the 'work' archive 
    } 
    } 

:あなたはそうのような特定のJSを発射するために使用することができました

関連する問題