Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Kupası
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPress’te Pinterest Stili Yazı Izgarası Eklemek için Masonry Nasıl Kullanılır

Bu yazı Josh Pollock tarafından yazılmıştır

Yazıların Pinterest benzeri ızgara görüntüsü bir süredir WordPress blog dizin sayfaları için popüler bir tasarım olmuştur. Sadece popüler sosyal medya sitesinin görünümünü taklit ettiği için değil, aynı zamanda ekrandaki alanı en iyi şekilde kullandığı için de popülerdir. Bir WordPress blog dizininde, her bir yazı önizlemesinin fazladan boşluk bırakmadan doğal olarak olması gereken boyutta olmasını sağlar.

Bu eğitimde, blog dizininiz için basamaklı ızgara düzenleri ve temanız için arşiv sayfaları oluşturmak üzere popüler Masonry JavaScript Kütüphanesini nasıl kullanacağınızı göstereceğim. Mobil optimizasyon için göz önünde bulundurmanız gereken birkaç sorunu ve bunları nasıl çözeceğinizi ele alacağım.

Screenshot of Masonry Grid Layout in WordPress

Not: Bu, WordPress temalarını düzenleme konusunda rahat hisseden ve yeterli HTML/CSS bilgisine sahip olanlar için ileri düzey bir eğitimdir.

Adım 1: Temanıza Gerekli Kütüphaneleri Ekleyin

Güncelleme: WordPress 3.9 artık Masonry’nin en son sürümünü içeriyor.

Öncelikle bu kodu kullanarak Masonry’yi temanıza yüklemeniz gerekir:

if (! function_exists('slug_scripts_masonry') ) :
if ( ! is_admin() ) :
function slug_scripts_masonry() {
    wp_enqueue_script('masonry');
    wp_enqueue_style('masonry’, get_template_directory_uri().'/css/’);
}
add_action( 'wp_enqueue_scripts', 'slug_scripts_masonry' );
endif; //! is_admin()
endif; //! slug_scripts_masonry exists

Bu kod basitçe masonry’yi yükler ve temanızın şablon dosyalarında kullanılabilir hale getirir ( WordPress’te JavaScripts ve Styles‘ın nasıl düzgün bir şekilde ekleneceğine ilişkin kılavuzumuza bakın). Ayrıca her ikisi için de jQuery’yi bağımlılık olarak eklemediğimizi unutmayın. Masonry 3’ün avantajlarından biri jQuery gerektirmemesi, ancak onunla birlikte kullanılabilmesidir. Deneyimlerime göre, Masonry’yi jQuery olmadan başlatmak daha güvenilirdir ve hem sayfa yükleme sürelerine hem de uyumluluk sorunlarına yardımcı olabilecek jQuery’yi yüklemeyi atlama olasılığını açar.

Adım 2: Javascript’i Başlatın

Sıradaki fonksiyon Masonry’yi kurar, onunla birlikte kullanılacak konteynerleri tanımlar ve ayrıca her şeyin doğru sırada gerçekleşmesini sağlar. Masonry’nin ızgarasını dinamik olarak düzenleyebilmesi için sayfadaki her bir öğenin boyutunu hesaplaması gerekir. Birçok tarayıcıda Masonry ile karşılaştığım bir sorun, Masonry’nin yavaş yüklenen görüntülere sahip öğelerin yüksekliğini yanlış hesaplaması ve üst üste binen öğelere yol açmasıdır. Çözüm, tüm resimler yüklenene kadar Masonry’nin düzeni hesaplamasını önlemek için imagesLoaded kullanmaktır. Bu, düzgün boyutlandırma sağlar.

Bu, sayfa altbilgisinde başlatma komut dosyasının çıktısını alacak işlev ve eylemdir:

if ( ! function_exists( 'slug_masonry_init' )) :
function slug_masonry_init() { ?>
<script>
    //set the container that Masonry will be inside of in a var
    var container = document.querySelector('#masonry-loop');
    //create empty var msnry
    var msnry;
    // initialize Masonry after all images have loaded
    imagesLoaded( container, function() {
        msnry = new Masonry( container, {
            itemSelector: '.masonry-entry'
        });
    });
</script>
<?php }
//add to wp_footer
add_action( 'wp_footer', 'slug_masonry_init' );
endif; // ! slug_masonry_init exists

Fonksiyon satır içi yorumlarla adım adım açıklanmıştır. Javascript fonksiyonunun yaptığı şey, Masonry’ye “masonry-entry” sınıfına sahip öğeler için “masonry-loop” id’sine sahip bir konteynerin içine bakmasını ve ızgarayı yalnızca görüntüler yüklendikten sonra hesaplamasını söylemektir. Dış konteyneri querySelector ve iç konteyneri itemSelector ile ayarlıyoruz.

Adım 2: Duvar Döngüsü Oluşturun

Masonry için HTML işaretlemesini doğrudan bir şablona eklemek yerine, bunun için ayrı bir şablon parçası oluşturacağız. “content-masonry.php” adında yeni bir dosya oluşturun ve temanıza ekleyin. Bu, Masonry döngüsünü istediğiniz kadar farklı şablona eklemenize olanak tanıyacaktır.

Yeni dosyanıza aşağıda gösterilen kodu ekleyeceksiniz. Biçimlendirme, normalde herhangi bir içerik önizlemesi için göreceğinize benzer. İstediğiniz şekilde değiştirebilirsiniz, sadece en dıştaki öğenin son adımda itemSelector olarak ayarladığımız “masonry-entry” sınıfına sahip olduğundan emin olun.

<article class="masonry-entry" id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
<?php if ( has_post_thumbnail() ) : ?>
    <div class="masonry-thumbnail">
        <a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('masonry-thumb'); ?></a>
    </div><!--.masonry-thumbnail-->
<?php endif; ?>
    <div class="masonry-details">
        <h5><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><span class="masonry-post-title"> <?php the_title(); ?></span></a></h5>
        <div class="masonry-post-excerpt">
            <?php the_excerpt(); ?>
        </div><!--.masonry-post-excerpt-->
    </div><!--/.masonry-entry-details -->  
</article><!--/.masonry-entry-->

Bu biçimlendirmenin her bir parçası için sınıflar vardır, böylece temanıza uygun biçimlendirme ekleyebilirsiniz. Ben .masonry-entry’ye hoş, hafif yuvarlak bir kenarlık eklemeyi seviyorum. Bir başka güzel seçenek de .masonry-entry için kenarlık kullanmamak ama hafif bir gölge vermek. Bu, özellikle yazı küçük resmi kabın sınırına kadar uzandığında iyi görünür; bu da .masonry-thumbnail kenar boşlukları ve dolguları her yönde 0 verilerek gerçekleştirilebilir. Tüm bu stilleri temanızın css dizinindeki masonry.css adlı bir dosyaya eklemek isteyeceksiniz.

Adım 3: Şablonlara Duvar Döngüsü Ekleyin

Artık şablon parçamız olduğuna göre bunu temanızdaki istediğiniz herhangi bir şablonda kullanabilirsiniz. Kategori arşivleri için kullanılmasını istemiyorsanız index.php’ye ekleyebilirsiniz, ancak category.php’ye eklemeyebilirsiniz. Yalnızca temanızın ana sayfasında, blog yazılarını gösterecek şekilde ayarlandığında kullanılmasını istiyorsanız, home.php’de kullanırsınız. Nereyi seçerseniz seçin yapmanız gereken tek şey döngüyü “masonry-loop” kimliğine sahip bir konteynere sarmak ve get_template_part() kullanarak şablon kısmını döngüye eklemektir. Masonry loop konteynerini while (have_posts() )’dan önce başlattığınızdan emin olun.

Örneğin, burada twentythirteen’in index.php dosyasındaki ana döngü yer almaktadır:

<?php if ( have_posts() ) : ?>

    <?php /* The loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; ?>

    <?php twentythirteen_paging_nav(); ?>

<?php else : ?>
    <?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>

Ve burada Duvarcılık döngümüzü kullanmak için değiştirilmiştir:

<?php if ( have_posts() ) : ?>
<div id="masonry-loop">
    <?php /* The loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', 'masonry' ?>
    <?php endwhile; ?>
</div><!--/#masonry-loop-->
    <?php twentythirteen_paging_nav(); ?>

<?php else : ?>
    <?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>

Adım 4: Duvar Öğelerinin Duyarlı Genişliklerini Ayarlayın

Her bir Duvar öğesinin genişliğini ayarlamanın birkaç yolu vardır. Masonry’yi başlattığınızda genişliği bir piksel sayısı kullanarak ayarlayabilirsiniz. Duyarlı temalar kullandığımdan ve küçük ekranlarda işleri doğru yapmak için bazı karmaşık medya sorguları gerektirdiğinden bunu yapmayı sevmiyorum. Duyarlı tasarımlar için yapılacak en iyi şeyin, bir satırda kaç öğe istediğinize bağlı olarak .masonry-entry için bir yüzde ile bir genişlik değeri ayarlamak ve Masonry’nin sizin için matematiğin geri kalanını yapmasına izin vermek olduğunu buldum.

Bunun için tek yapmanız gereken 100’ü temanızın style.css dosyasındaki basit bir girdide yüzdeyi ayarlamak istediğiniz öğe sayısına bölmektir. Örneğin, her satırda dört öğe istiyorsanız bunu masonry.css dosyanızda yapabilirsiniz:

.masonry-entry{width:25%}

Adım 5: Mobil Optimizasyon

Burada durabiliriz, ancak nihai sonucun küçük telefon ekranlarında inanılmaz derecede iyi çalıştığını düşünmüyorum. Temanızın masaüstünüzde yeni Masonry ızgarasıyla nasıl göründüğünden memnun olduğunuzda, telefonunuzda kontrol edin. Telefonunuzda nasıl göründüğünden memnun değilseniz, küçük bir çalışma yapmanız gerekecektir.

İçerik-masonluk şablonu bölümümüze eklediğimiz her şey için bir telefonun ekranında yeterli yer olduğunu sanmıyorum. Kullanabileceğiniz iki iyi çözüm, telefonlar için alıntıyı kısaltmak veya tamamen atlamaktır. İşte bunu yapmak için temanızın functions.php’sine ekleyebileceğiniz ekstra bir fonksiyon. Bu sorunların tabletlerde bir sorun olduğunu düşünmediğim için, bu bölümdeki tüm örneklerde değişiklikleri tabletlerde değil yalnızca telefonlarda yapmak için harika bir eklenti olan Mobble ‘ı kullanıyorum. Ayrıca Mobble’ı kullanmadan önce aktif olup olmadığını kontrol ediyorum ve gerekirse WordPress’te yerleşik olarak bulunan daha genel mobil algılama işlevi wp_is_mobile’a geri dönüyorum.

if (! function_exists('slug_custom_excerpt_length') ) :
function slug_custom_excerpt_length( $length ) {
    //set the shorter length once
    $short = 10;
    //set long length once
    $long = 55;
    //if we can only set short excerpt for phones, else short for all mobile devices
    if (function_exists( 'is_phone') {
        if ( is_phone() ) {
            return $short;
        }
        else {
            return $long;
        }        
    }
    else {
        if ( wp_is_mobile() ) {
            return $short;
        }
        else {
            return $long;
        }
    }
}
add_filter( 'excerpt_length', 'slug_custom_excerpt_length', 999 );
endif; // ! slug_custom_excerpt_length exists

Gördüğünüz gibi, uzun alıntı uzunluğunu ve kısa alıntı uzunluğunu değişkenlerde saklayarak başlıyoruz, çünkü bu değerleri iki kez kullanacağız ve daha sonra ihtiyacımız olursa bunları tek bir yerden değiştirebilmek istiyoruz. Buradan Mobble’ın is_phone() fonksiyonunu kullanıp kullanamayacağımızı test ediyoruz. Eğer öyleyse telefonlar için kısa alıntıyı, değilsek uzun alıntıyı ayarlıyoruz. Bundan sonra aynı temel şeyi yapıyoruz, ancak is_phone() kullanılamazsa tüm mobil cihazları etkileyecek olan wp_is_mobile’ı kullanıyoruz. Umarım bu fonksiyonun else kısmı hiçbir zaman kullanılmaz, ancak her ihtimale karşı bir yedeğe sahip olmak iyidir. Alıntı uzunluğu mantığı ayarlandıktan sonra geriye sadece fonksiyonu excerpt_length filtresine bağlamak kalıyor.

Alıntıyı kısaltmak bir seçenektir, ancak basit bir işlemle bunu tamamen ortadan kaldırabiliriz. İşte content-masonry’nin telefonlarda tüm alıntı kısmı çıkarılmış yeni bir sürümü:

<article class="masonry-entry" id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
<?php if ( has_post_thumbnail() ) : ?>
    <div class="masonry-thumbnail">
        <a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('masonry-thumb'); ?></a>
    </div><!--.masonry-thumbnail-->
<?php endif; ?>
    <div class="masonry-details">
        <h5><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><span class="masonry-post-title"> <?php the_title(); ?></span></a></h5>
        <?php 
            //put the excerpt markup in variable so we don't have to repeat it multiple times.
            $excerpt = '<div class="masonry-post-excerpt">';
            $excerpt .= the_excerpt();
            $excerpt .= '</div><!--.masonry-post-excerpt-->';
//if we can only skip for phones, else skip for all mobile devices
            if (function_exists( 'is_phone') {
                if ( ! is_phone() ) {
                    echo $excerpt;
                }
            }
            else {
                if ( ! wp_is_mobile() ) {
                    echo $excerpt;
                }
            }
        ?>
    </div><!--/.masonry-entry-details -->  
</article><!--/.masonry-entry-->

Bu sefer bir telefon/mobil cihazda olup olmadığımızı test ediyoruz ve eğer öyleyse döngümüzün alıntı kısmını döndürüyoruz. Eğer bir telefon/ mobil cihazda isek hiçbir şey yapmıyoruz.

Yapmak isteyebileceğiniz bir başka şey de, mobil cihazlarda bir satırdaki sayıyı azaltan Masonry öğelerinin genişliğini artırmaktır. Bunu yapmak için, cihaz algılamasına bağlı olarak başlığa farklı bir satır içi stil ekleyeceğiz. Bu işlev wp_add_inline_styles kullandığından, belirli bir stil sayfasına bağımlı olacaktır. Bu durumda ben masonry.css kullanıyorum, siz de duvar stillerinizi ayrı tutmak isteyebilirsiniz. Bunu kullanmak istemezseniz, zaten kayıtlı olan başka bir stil sayfasındaki tutamacı kullanabilirsiniz.

if ( ! function_exists ( 'slug_masonry_styles' ) ) :
function slug_masonry_styles() {
    //set the wide width
    $wide = '25%';
    //set narrow width
    $narrow = '50%';
    /**Determine value for $width**/
    //if we can only set narrow for phones, else narrow for all mobile devices
    if (function_exists( 'is_phone') {
        if ( is_phone() ) {
            $width = $narrow;
        }
        else {
            $width = $wide;
        }        
    }
    else {
        if ( wp_is_mobile() ) {
            $width = $narrow;
        }
        else {
            $width = $wide;
        }
    }
    /**Output CSS for .masonry-entry with proper width**/
    $custom_css = ".masonry-entry{width: {$width};}";
    //You must use the handle of an already enqueued stylesheet here.
    wp_add_inline_style( 'masonry', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'slug_masonry_styles' );
endif; // ! slug_masonry_styles exists

Bu fonksiyon özel stil sayfasını çağırır ve ardından artık çok tanıdık gelmesi gereken mantığı kullanarak genişlik için bir değer belirler. Bundan sonra genişlik değerini {$width} ile normal görünümlü bir CSS parçasına aktararak $custom_css değişkenini oluşturuyoruz. Bundan sonra wp_add_inline_style kullanarak WordPress’e Masonry stil sayfası kullanıldığında satır içi stillerimizi başlığa yazdırmasını söylüyoruz ve ardından tüm işlevi wp_enqueue_scripts’e bağlıyoruz ve işimiz bitiyor.

Masonry stillerinizi mevcut bir stil sayfasında birleştirmeyi seçtiyseniz, bu stil sayfasının tutamacını wp_add_inline_style ile kullandığınızdan emin olun, aksi takdirde satır içi stilleriniz dahil edilmeyecektir. Ben wp_add_inline_style kullanmayı seviyorum çünkü genellikle Masonry’yi sıraya almak için eylem kancasını bir koşula bağlıyorum, böylece yalnızca gerektiğinde ekleniyor. Örneğin, Masonry’yi yalnızca blog dizinimde ve arşiv sayfalarımda kullanıyorsam bunu yaparım:

if ( is_home() || is_archive() ) {
    add_action( 'wp_enqueue_scripts', 'slug_scripts_masonry' );
}

Bu son birkaç örnek beyninizde başka fikirlerin oluşmasını sağlayacaktır. Örneğin, benzer bir mantıkla mobil bir cihazda duvar yazılarını tamamen atlayabilirsiniz. Ayrıca wp_add_inline_style() daha az kullanılan ancak çok yararlı bir işlevdir, çünkü herhangi bir koşul türüne göre programlı olarak farklı stiller ayarlamanıza olanak tanır. Herhangi bir öğenin stilini yalnızca cihaz algılamasına göre değil, aynı zamanda hangi şablonun kullanıldığına ve hatta kullanıcının oturum açıp açmadığına göre de kökten değiştirmenize olanak tanıyabilir.

Umarım yaptığım bu farklı değişiklikleri yaratıcı olmak için bir fırsat olarak görürsünüz. Masonry ve benzeri basamaklı ızgara sistemleri bir süredir popüler, bu yüzden bu popüler fikir üzerinde bazı yeni değişiklikler yapmanın zamanı geldi. Bir WordPress temasında Masonry kullanmak için bulduğunuz harika yolları yorumlarda bize gösterin.

Çok amaçlı bir WordPress adamı olan Josh Pollock, WordPress hakkında yazıyor, tema geliştiriyor, Pods Framework için topluluk yöneticisi olarak hizmet veriyor ve sürdürülebilir tasarım için açık kaynaklı çözümleri savunuyor.

Açıklama: İçeriğimiz okuyucu desteklidir. Bu, bazı bağlantılarımıza tıklarsanız komisyon kazanabileceğimiz anlamına gelir. WPBeginner'ın nasıl finanse edildiğini, neden önemli olduğunu ve nasıl destek olabileceğinizi görün. İşte editoryal sürecimiz.

Avatar

This post was written by a guest contributor. You can see their details in the post above. If you'd like to write a guest post for WPBeginner, then check out our Write for WPBeginner page for details. We'd love to share your tips with our community.

Ultimate WordPress Araç Kiti

Araç setimize ÜCRETSİZ erişim sağlayın - her profesyonelin sahip olması gereken WordPress ile ilgili ürün ve kaynaklardan oluşan bir koleksiyon!

Reader Interactions

39 yorumBir Cevap Bırakın

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Neil says

    Just a quick note if you’re getting the “imagesLoaded” error, try adding the Javascript code after the wp_footer call in your footer.php.

    This work for me:

    Add to functions.php

    add_action( ‘wp_enqueue_scripts’, ‘slug_masonry’ );
    function slug_masonry( ) {
    wp_enqueue_script(‘masonry’); // note this is not jQuery
    }

    In your loop, make sure your div is:

    And the image class is:

    and then after wp_footer in your footer.php this:

    //set the container that Masonry will be inside of in a var
    var container = document.querySelector(‘#masonry-loop’);
    //create empty var msnry
    var msnry;
    // initialize Masonry after all images have loaded
    imagesLoaded( container, function() {
    msnry = new Masonry( container, {
    itemSelector: ‘.masonry-entry’
    });
    });

  3. Marisa Di Monda says

    Hi Andy I just tried this and I couldn’t get it to work. Everything is still running vertically in one column.
    Any solutions?

  4. Peter says

    did not work for me. i see only two images on my front page which are arranged underneath. don’t know where is the problem :(

  5. Eva says

    For some reason my posts will just all show just in rows like normal, not in masonry form, I’m not really sure how this can happen. Any ideas?

  6. jcbrmn06 says

    For anyone still having issues with this, I noticed that this code:

    //set the container that Masonry will be inside of in a var

    var container = document.querySelector(‘#masonry-loop’);

    //create empty var msnry

    var msnry;

    // initialize Masonry after all images have loaded

    imagesLoaded( container, function() {

    msnry = new Masonry( container, {

    itemSelector: ‘.masonry-entry’

    });

    });

    Was before the masonry JS library. Therefore you get the imagesLoaded error. Like Andy suggested below putting it in the header should fix it. Basically you just have to make sure the library has to come before this code.

  7. Andy Giesler says

    Thanks again for this tutorial, it really helped start me on my way.

    Even with everything in place, I saw intermittent problems where the tiles simply ran down the left of the page in a single column, and Firebug confirmed that sometimes the Masonry code didn’t execute. This happened only occasionally, and only in Firefox.

    It seemed that under certain load scenarios, there were probems with code trying to execute before the required files were loaded. I don’t think this was an imagesLoaded problem, since that has different symptoms.

    I fixed the problem as follows:

    1. The “slug_masonry_init” function places the masonry init code inline into the footer. I removed that whole function (as well as the add_action ‘wp_footer’ code) and moved the JS into an extenal file: masonry-init.js

    2. I wrapped the masonry init code in jQuery to take advantage of its document.ready ability. It’s unfortunate to pull in jQuery since this is the jQuery-free version of Masonry, but document.ready seemed necessary for the code to execute in all load scenarios.

    (function( $ ) {
    “use strict”;
    $(function() {

    });
    }(jQuery));

    3. I enqueued the scripts like this:

    wp_enqueue_script( ‘masonry’ );
    wp_enqueue_script( ‘jquery’ );
    wp_enqueue_script( ‘masonryInit’, get_stylesheet_directory_uri().’/js/masonry-init.js’, array( ‘masonry’, ‘jquery’ ) );

  8. Daniel Nikolovski says

    Done exactly as the tutorial says, wp 3.9.1.. imagesLoaded isn’t even being loaded. Some help would be highly appreciated

  9. Jenny Beaumont says

    I’m having trouble getting this to work…followed things accordingly, based on _s, but my columns don’t wrap – just get one long one. Have any css examples to go with? I’m obviously missing something. cheers!

  10. caratcake says

    I’m desperately confused. I performed every step down to the letter, and my site just goes blank. A problem with the functions file. My browser doesn’t even allude to which line causes any error, all I get is ”
    Server error
    The website encountered an error while retrieving (url) It may be down for maintenance or configured incorrectly.”

    The same happened for the WP Admin login page. I deleted functions.php in my theme folder, and the login screen was restored, but the front page was not. If you could give me any clues to what the problem might be, I would be very grateful. Regardless, many thanks for the tutorial and in depth explanations.

  11. Andy Giesler says

    In case this helps others to get the sample working:

    It wasn’t working for me even after I made the fix that others have noted — changing “function slug_masonry_exists()” to “function slug_masonry_init()”. The libraries were being loaded, but Masonry wasn’t doing its thing.

    Then I changed the wp_enqueue_script calls so that Masonry and imagesLoaded got loaded in the header instead of at the bottom.

    Suddenly everything worked.

    • Jean says

      Hi, i can´t figure out how do change the wp_enqueue_script. I will really appreciate if you can explain that in detail. Thanks!

  12. gabi says

    Hello, It doesn’t work for me I have this error message :
    ” Parse error: syntax error, unexpected T_ENDIF in…”…functions.php on line 17

    It means an error on the script from the 3td step. What did I miss ?

  13. Steven Gardner says

    The initialization script keeps being called before imagesloaded has been defined so I get

    Uncaught ReferenceError: imagesLoaded is not defined

    How can I make sure imagesLoaded is there first before I start to initialise things?

    • Violacase says

      imagesLoaded is called before enqueueing has been established. Give it a low priority so that it is called last, like:

      add_action( ‘wp_footer’, ‘slug_masonry_init’, 100000 );

      This did the trick for me.

      Nota: I think this article needs to be updated. Not only because of this issue.

  14. Kate says

    Thanks for this post. I am trying to set up a blog page with Masonry posts, but I’m snagged at step 1. Whenever I add the functions for adding the two libraries to my functions file, my site goes totally blank. Since I am developing in a subdirectory, I tried to make the paths to the js files absolute rather than relative, but that didn’t help. Any idea what I’m missing?

  15. Amitabha Ghosh says

    Thanks. It’s a great post and it is working for me. I am doing a template with this code and it is working perfect. But two obstacles I am facing
    1. I want to limit my posts in my index page so that it shows first 6 to 7 posts and below will be a button with “Load More” feature which when clicked shall load the other posts.

    2. I am trying to integrate infinite scroll javascript of Paul Irish but I couldn’t make it work. Any help??

    Thanks

  16. Ismar Hadzic says

    Well I followed all of your steps and I run on fatal error ” PHP Fatal error: Call to undefined function wp_enquqe_style() ” and i still don’t understand why wp_enquqe_style() i don’t understand why can you check that out.

  17. Aurélien Denis says

    Hi there!

    This post is great start but I found some mistakes…

    1/ You should use the_title_attribute() for the attribute title instead of the title
    2/ add_action( ‘wp_footer’, ‘slug_masonry_exists’ ); is the correct code and not add_action( ‘wp_footer’, ‘slug_masonry_init’ );

    Cheers!

  18. Ben Racicot says

    Can’t get this working with an infinite scroll setup in my $ajax success CB. Any advice would be great.

  19. Tomasz Bystrek says

    I was looking for this effect, but I did’t know how it is called and how to search for it, until now. I’ll definitely try it in one of my future project of photo blog. Thanks!

  20. Katrina Moody says

    Great post – wish it was around when I started working with Masonry on a theme a few weeks ago :D

    A couple variations – I created a new post-thumbnail image size to pull in so that both horizontal and vertical images would have equal attention within the Masonry pages – it’s fairly easy to change out the actual image for a new one (I did that at first, creating a new “entry-thumbnail” size and allowing unlimited length so that horizontal images would display properly). Then I just edited the post-thumbnail ;-)

    I also wrapped the post-thumbnail within an tag so that I could allow it to return to the post permalink (I changed that out to return the media file link so I could implement a lightbox effect – per a client’s request) so visitors could go directly to the post.

    I also added a hover effect to the post-thumbnail to indicate it was clickable :D

    Now I need to pick through what I’ve done and compare it to yours and see what I can improve with your knowledge (love the WordPress community!)

Bir Cevap Bırakın

Yorum bırakmayı seçtiğiniz için teşekkür ederiz. Lütfen tüm yorumların yorum poli̇ti̇kasi uyarınca denetlendiğini ve e-posta adresinizin yayımlanmayacağını unutmayın. Ad alanında anahtar kelime KULLANMAYIN. Kişisel ve anlamlı bir sohbet edelim.