将小部件正确添加到砖石布局-jQuery&&||PHP

时间:2013-01-30 作者:Ben Racicot

我尝试在我的小部件区域中逐渐添加到砖石布局(下面的PHP),但我无法像其他块一样将其包含到砖石中。

        $counts = 0 ;
        $addin = get_sidebar(\'masonry\'); 

        foreach ($posts as $post) : setup_postdata($post); $counts++; ?>
                <div class="box">
                <?php  if($count == 9) {echo $addin;} else {?>
                <a href="<?php the_permalink() ?>">
                <h2><?php the_title(); echo $counts; // just to see ?></h2>
                <?php if (has_post_thumbnail()) {
                    the_post_thumbnail(\'thumbnail\');
                }?>
                <?php the_content();?></a>
                </div><?php } endforeach; ?>
我也尝试了这个jQuery,但它破坏了我的结构:

jQuery(document).ready(function($){
    $(\'.arrange\').masonry({
       itemSelector: \'.box\',
       isFitWidth: true,
    });
 $(\'#addinWidget\').click(function(){
        var $container = $(\'#mas-widget\');
        var addinWidget = $(\'<div class="element"><?php get_sidebar(\'masonry\');?></div>\');
        addinWidget.insertAfter($container.find(\'.element\').eq(3));
        $container.masonry(\'reload\');
    });
是否有人可以引导我正确地将我的小部件正确地放置在指定块号处/旁边或前面的砖石布局中?

1 个回复
最合适的回答,由SO网友:Ben Racicot 整理而成

算了吧!下面是一个get\\u posts方法,可以添加一个小部件(或任何内容到您定义的“$counts”数字处的砖石布局中)

<div class="arrange">
        <?php 
        $args = array(
            \'posts_per_page\'  => 10000,
            \'offset\'          => 5,
            \'orderby\'         => \'post_date\',
            \'order\'           => \'DESC\',
            \'exclude\'         => \'none\',
            // \'post_type\'       => array(\'post\', \'page\', \'video_type\', \'review_type\' ),
            \'post_status\'     => \'publish\',
            \'suppress_filters\' => true 
            ); 

        $posts = get_posts($args);
        $counts = 0 ;
        foreach ($posts as $post) : setup_postdata($post); $counts++; 
            get_sidebar(\'corner-box\');?>
                <div class="box"> 
                    <a href="<?php the_permalink() ?>">
                        <h2><?php the_title(); echo $counts; // to see your box number ?></h2>
                        <?php if (has_post_thumbnail()) {the_post_thumbnail(\'masonry\');} 
                        the_content();?>
                    </a>
                </div><?php if($counts == 9) { get_sidebar(\'masonry\');}
                endforeach; ?>

    </div> <!-- end masonry -->

结束

相关推荐

JQuery上的添加/删除操作切换

我有Ajax设置,我正在尝试切换一个函数,以避免加载到wp\\U头中。它适用于第一个切换函数,但第二个函数不注册。function av_maintenance_mode_turn_on() { if( !wp_verify_nonce( $_GET[\'nonce\'], \'av-maintenance-mode-nonce\' )) die( \'Go away!\'); if( add_action( \'get_header\', \'av_mai