多个类别的固定链接 [英] permalink for multiple category
问题描述
我有 15 个页面用于 2 个类别......例如 A 类和 B 类......同时我已经显示了标题和内容......但是永久链接是为 A 类创建而不是 B 类......如何我可以编码以获得第二类的永久链接吗...
hi i had 15 pages for 2 categories.. example category A and category B.... while doing so i have displayed title and content... but permalink is creating for category A not for category B... how can i code for to get a permalink for second category...
$cat = get_the_category();
$id= $cat[0]->term_id;
$id1= $cat[1]->term_id;
$args = array('posts_per_page' => 15,
'cat'=> $id1,
'orderby'=> 'post_date',
'order'=> 'ASC',
'paged' => $paged,
'post_type'=> 'post',
'post_status' => 'publish' );
query_posts( $args );
if ( have_posts() ) while ( have_posts() ) : the_post();
$i++;
?>
<li><a href="<?php echo get_permalink(); ?>"><?php the_title();?></a></li>
<?php
endwhile;
wp_reset_query();
?>
但永久链接正在为 $id 创建...
but the permalink is creating for $id...
推荐答案
如果您使用模板或页面来显示这两个类别的帖子.您必须为每个类别运行两个循环.如果您尝试使用短代码或其他东西.它会有所不同.
if you are using template or page to display this two categories post. You have to run two loop for every category. If you are trying to use shortcode or something. it will be different.
$cat = get_the_category();
$cat_01= $cat[0]->term_id;
$cat_02= $cat[1]->term_id;
$args_for_cat_01 = array('posts_per_page' => 15,
'cat'=> $cat_01,
'orderby'=> 'post_date',
'order'=> 'ASC',
'paged' => $paged, //I don't know what is this $paged??
'post_type'=> 'post',
'post_status' => 'publish');
$post_from_cat_01 = get_posts( $args_for_cat_01 );
foreach ( $post_from_cat_01 as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
//Do whatever you want here. Use divs or anything.
</li>
<?php endforeach;
wp_reset_postdata();?>
</ul>
像上面这样.为您的第二个循环创建另一个 args
.
As above like this. Create another args
for your second loop.
$args_for_cat_02 = array('posts_per_page' => 15,... change the cat => cat_02 ..ect
然后使用上面的循环.
$post_from_cat_02 = get_posts( $args_for_cat_02 );
foreach ( $post_from_cat_02 as $post ) : setup_postdata( $post ); ?>
记得更改变量
.我只是为了更多的解释.
Remember to change the variables
. I just use for more explanation.
如果你需要我的帮助.请通过搜索yeshansachithak
找到我任何社交网络.
If you need my help. Please find me any of social network by searching yeshansachithak
.
这篇关于多个类别的固定链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!