添加“更多”按钮

时间:2014-05-09 21:19:21

标签: javascript php jquery

我正在尝试添加“加载更多”按钮并限制下面的结果,以便在投资组合页面中不会同时加载1000个内容,此处:http://typesetdesign.com/portfolio/

我对PHP的了解不是很好,所以我不确定我应该做什么。我知道我可以在这里限制项目:

<?php query_posts( 'post_type=project&posts_per_page=200' );

但是,如果我限制了那个结果,那么如何加载更多呢?

以下是整个页面的页面编码:

<div id="projects" class="clearfix">        

<?php $page_skills = get_post_meta($post->ID, "_ttrust_page_skills", true); ?>

<?php if ($page_skills) : // if there are a limited number of skills set ?>
    <?php $skill_slugs = ""; $skills = explode(",", $page_skills); ?>

    <?php if (sizeof($skills) > 1) : // if there is more than one skill, show the filter nav?>  
        <ul id="filterNav" class="clearfix">
            <li class="allBtn"><a href="#" data-filter="*" class="selected"><?php _e('All', 'themetrust'); ?></a></li>

            <?php
            $j=1;                     
            foreach ($skills as $skill) {               
                $skill = get_term_by( 'slug', trim(htmlentities($skill)), 'skill');
                if($skill) {
                    $skill_slug = $skill->slug;             

                    $skill_slugs .= $skill_slug . ",";
                    $a = '<li><a href="#" data-filter=".'.$skill_slug.'">';
                    $a .= $skill->name;                 
                    $a .= '</a></li>';
                    echo $a;
                    echo "\n";
                    $j++;
                }         
            }?>
        </ul>
        <?php $skill_slugs = substr($skill_slugs, 0, strlen($skill_slugs)-1); ?>
    <?php else: ?>
        <?php $skill = $skills[0]; ?>
        <?php $s = get_term_by( 'name', trim(htmlentities($skill)), 'skill'); ?>
        <?php if($s) { $skill_slugs = $s->slug; } ?>
    <?php endif;        

    $temp_post = $post;
    $args = array(
        'ignore_sticky_posts' => 1,
        'posts_per_page' => 200,
        'post_type' => 'project',
        'skill' => $skill_slugs
    );
    $projects = new WP_Query( $args );      

else : // if not, use all the skills ?>

    <ul id="filterNav" class="clearfix">
        <li class="allBtn"><a href="#" data-filter="*" class="selected"><?php _e('All', 'themetrust'); ?></a></li>
        <?php $j=1;
        $skills = get_terms('skill');
        foreach ($skills as $skill) {
            $a = '<li><a href="#" data-filter=".'.$skill->slug.'">';
            $a .= $skill->name;                 
            $a .= '</a></li>';
            echo $a;
            echo "\n";
            $j++;
        }?>
    </ul>
    <?php
    $temp_post = $post;
    $args = array(
        'ignore_sticky_posts' => 1,
        'posts_per_page' => 200,
        'post_type' => 'project'            
    );
    $projects = new WP_Query( $args );

endif; ?>

<div class="thumbs masonry">            
<?php  while ($projects->have_posts()) : $projects->the_post(); ?>

    <?php
    global $p;              
    $p = "";
    $skills = get_the_terms( $post->ID, 'skill');
    if ($skills) {
       foreach ($skills as $skill) {                
          $p .= $skill->slug . " ";                     
       }
    }
    ?>      
    <?php get_template_part( 'part-project-thumb'); ?>      

<?php endwhile; ?>
<?php $post = $temp_post; ?>
</div>

非常感谢,任何输入都是帮助!

2 个答案:

答案 0 :(得分:1)

编辑
使用具有分页引导样式的表http://datatables.net/examples/basic_init/multiple_tables.html

带分页的海量数据库请点击此处:https://stackoverflow.com/a/3707457/2293454

我没有看到你的网站,现在我有,你可能需要的是这样的:
https://stackoverflow.com/a/21408418/2293454
正如您所看到的那样,示例有一个限制器iMyLoadLimit = 5,因此,当用户向下滚动页面时,它将根据获取的数据总数加载更多,如果您加载100篇文章或1000,它们将被除以java中的限制器,结果是每次用户向下滚动时都会显示下一个5或你要显示的任何数字......

我希望有帮助...

答案 1 :(得分:0)

您需要分页(服务器端)并且可能需要无限滚动(客户端)

您可能需要查看:

Simple PHP Pagination script

http://jscroll.com/

How to paginate query results for Infinite Scroll?