伙计们,所以我在我们的网站上有一个项目页面,该页面利用标签将不同标签之间的多个不同项目类型分开。每个选项卡均按类别运行其自己的查询,并按日期对该类别中的项目进行排序并显示:标题,日期,视图,作者,帖子的一小部分摘录和特色图片。
现在的问题是,每个选项卡上的帖子过多,您必须向下滚动才能看到较旧的项目。什么是将每个项目帖子按类别分为4个帖子的页面的最佳解决方案。是否有更好的解决方案来运行单个循环,按类别将项目分为其他选项卡并分页?还是有更雄辩的解决方案?
这是我的主要项目页面,带有标签:
<div id="categoryTabs">
<ul id="news_style1_tabs" class="tabs">
<li><a href="#mining">Mining</a></li>
<li><a href="#ong">Oil & Gas</a></li>
<li><a href="#energy">Energy</a></li>
<li><a href="#infs">Infastructure</a></li>
<li><a href="#global">Global</a></li>
</ul>
<section id="news_style1_body" class="news_body">
<div class="tab_all" id="mining">
<?php get_template_part('page-projectsTabs-mining'); ?>
</div>
<div class="tab_all" id="ong">
<?php get_template_part('page-projectsTabs-ong'); ?>
</div>
<div class="tab_all" id="energy">
<?php get_template_part('page-projectsTabs-energy'); ?>
</div>
<div class="tab_all" id="infs">
<?php get_template_part('page-projectsTabs-infs'); ?>
</div>
<div class="tab_all" id="global">
<?php get_template_part('page-projectsTabs-glob'); ?>
</div>
</section>
这是带有类别的选项卡之一的示例
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args_mining = array( 'post_type' => 'projects',
'status' => 'published',
'category_name' => 'Mining',
'posts_per_page'=> 4,
'orderby' => 'post_date',
'order' => 'DESC'
);
$get_mining = new WP_Query($args_mining);
if($get_mining->have_posts()){
while($get_mining->have_posts()) : $get_mining->the_post();
$image = wp_get_attachment_image(get_post_thumbnail_id($get_mining->ID),'home-feature');?>
<article>
<div class="pic"><a href="<?php the_permalink();?>" class="w_hover img-link img-wrap"><?php echo $image; ?><span class="link-gallery"></span> </a> </div>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<ul class="icons">
<li><a href="<?php the_permalink(); ?>" class="post_date"><?php echo get_the_time('d M, Y', $get_mining);?></a></li>
<li><a href="<?php the_permalink(); ?>" class="post_views"><?php echo get_post_meta(get_the_ID(),'views',true);?></a></li>
<li><a href="<?php the_permalink(); ?>" class="post_submitted"><?php echo get_post_meta(get_the_ID(),'Author',true);?></a></li>
<li><a href="" class="comments_count"></a></li>
</ul>
<div class="text"><?php echo get_excerpt(900,$get_mining); ?></div>
</article>
<?php endwhile;
}?>
<?php wp_reset_postdata(); ?>
任何帮助和建议都会很好。请注意,目前我大约有5个标签页
编辑1:在我的functions.php中添加了我的分页功能
下面是在我的functions.php中找到的分页代码
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
//Check page number and store $pageUp and $pageDown appropriately
if($paged == '1'){
$pageDown = $paged + 1;
$pageUp = $paged +2;
$prev = get_previous_posts_page_link($pageDown);
$next = get_next_posts_page_link($pageUp);
}
elseif(($paged >= 2)&&(!$paged==$numpages)){
$pageDown = $paged -1;
$pagedUp = $paged +1;
$prev = get_previous_posts_page_link();
$next = get_next_posts_page_link();
}
elseif($paged == $numpages){
$pageDown = $paged -2;
$pageUp = $paged -1;
$prev = get_previous_posts_page_link($pageDown);
$next = get_next_posts_page_link($pageUp);
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => False,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo '<div id ="nav_pages">';
echo '<div class="prev_first"></div>';
//echo ' <a href="'.$paginate_links.'" class="next">Next</a>';
echo '<div class="pages"';
echo'<ul>';
if($paged==1){
$pageDown = $paged + 1;
$pageUp = $paged +2;
$prev = get_next_posts_page_link();
$next = get_next_posts_page_link();
echo' <li class="current"><a href="" title="">'.$paged.'</a></li>';
echo'<li><a href="'.$prev.'" title="'.$prev.'">'.$pageDown.'</a></li>';
//echo'<li><a href="'.$next.'" title="'.$next.'">'.$pageUp.'</a></li>';
}
elseif(($paged >= 2)&&($paged!=$numpages)){
$pageDown = $paged -1;
$pageUp = $paged +1;
$prev = get_previous_posts_page_link();
$next = get_next_posts_page_link();
echo'<li><a href="'.$prev.'" title="'.$prev.'">'.$pageDown.'</a></li>';
echo' <li class="current"><a href="" title="">'.$paged.'</a></li>';
echo'<li><a href="'.$next.'" title="">'.$pageUp.'</a></li>';
}
elseif($paged==$numpages){
$pageDown = $paged -2;
$pageUp = $paged -1;
$prev = get_previous_posts_page_link();
$next = get_next_posts_page_link();
echo'<li><a href="'.$prev.'" title="'.$prev.'">'.$pageUp.'</a></li>';
//echo'<li><a href="'.$next.'" title="'.$next.'">'.$pageUp.'</a></li>';
echo' <li class="current"><a href="" title="">'.$paged.'</a></li>';
}
//echo $paginate_links;
echo '</ul>';
echo '<div class="page_x_of_y">Page <span>' . $paged . '</span> of <span>' . $numpages . '</span></div> ';
echo '</div>';
}
}
//End of pagination
答案 0 :(得分:1)
使用以下代码进行分页:
CREATE OR REPLACE PACKAGE test_FORALL AS
PROCEDURE pr_test_FORALL;
END test_FORALL;
CREATE OR REPLACE PACKAGE BODY test_FORALL AS
PROCEDURE pr_test_FORALL IS
TYPE ty_tbl_table_test IS TABLE OF table_test%ROWTYPE INDEX BY BINARY_INTEGER;
l_tbl_table_test_retrieve ty_tbl_table_test;
l_tbl_table_test ty_tbl_table_test;
l_final_amt INTEGER;
l_reference_number VARCHAR2(100);
BEGIN
SELECT * BULK COLLECT
INTO l_tbl_table_test_retrieve
FROM table_test t1;
FOR i IN 1 .. l_tbl_table_test_retrieve.COUNT
LOOP
l_tbl_table_test(l_tbl_table_test.COUNT + 1) := l_tbl_table_test_retrieve(i);
l_final_amt := l_final_amt + 10;
l_reference_number := SYSDATE + l_tbl_table_test_retrieve(i).ID;
insert into some_other_table(fname, address,final_amt,ref_number)
values(l_tbl_table_test_retrieve(i).fname, l_tbl_table_test_retrieve(i).address,l_final_amt,l_reference_number);
END LOOP;
--I want to insert into some_other_table using FORALL. But,l_final_amt and l_reference_number variables
-- are not available in l_tbl_table_test_retrieve.
EXCEPTION
DBMS_OUTPUT.put_line('EXCEPTION occurred');
END;
END pr_test_FORALL;
END test_FORALL;
并在如下所示的查询中使用它:
$paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
然后在结束之后在下面的代码中进行分页;
$args_mining = array( 'post_type' => 'projects',
'status' => 'published',
'category_name' => 'Mining',
'posts_per_page'=> 4,
'orderby' => 'post_date',
'order' => 'DESC',
'paged' => $paged1
);
注意:(将$pag_args1 = array(
'prev_text' => __('<'),
'next_text' => __('>'),
'show_all' => true,
'base' => '' . $url . '?paged1=%#%',
'format' => '?paged1=%#%',
'current' => $paged1,
'total' => $get_mining->max_num_pages);
echo paginate_links( $pag_args1 );
和$paged1
用作不同的类别查询变量