Php 一岗双雕
这件事让我很沮丧。我有多种自定义帖子类型(CPT)。他们大多数都有档案。现在我有了一个名为Php 一岗双雕,php,wordpress,Php,Wordpress,这件事让我很沮丧。我有多种自定义帖子类型(CPT)。他们大多数都有档案。现在我有了一个名为Portfolio的ctp和一个名为recentwork的cpt 我想要的是两个ctp都显示在归档文件-[slug].php页面中。但在一个归档中,链接应该是/portfolio/page name,而在另一个归档中,链接应该是/recentwork/page name 这两个页面将显示相同的内容,但归档slug会有所不同。我不想创建双重内容 有人知道使用Wordpress是否可以做到这一点,以及我如何做到
Portfolio
的ctp和一个名为recentwork
的cpt
我想要的是两个ctp都显示在归档文件-[slug].php页面中。但在一个归档中,链接应该是/portfolio/page name
,而在另一个归档中,链接应该是/recentwork/page name
这两个页面将显示相同的内容,但归档slug会有所不同。我不想创建双重内容
有人知道使用Wordpress是否可以做到这一点,以及我如何做到这一点
正如Gavin Thomas所说,使用类别(在我的例子中是自定义分类法)。这是我的循环代码:
<?php $args = array(
'post_type' => 'portfolio',
'posts_per_page'=> -1,
'orderby' => 'ID',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'event-type',
'field' => 'slug',
'terms' => 'corporate-events'
)
)
);
$products = new WP_Query( $args );
if( $products->have_posts() ) {
while( $products->have_posts() ) {
$products->the_post();
?>
<?php $naam = get_field('naambedrijf');
$soort = get_field('soort_uitje');
$foto = get_field('flickr_fotoset'); ?>
<div class="col s6 m4 l4">
<a href="<?php the_permalink(); ?>">
<div class="title">
<h2 class="truncate" style="line-height:20px;"><?php echo $naam; ?></h2>
<small class="truncate" style="color:#222;"><?php echo $soort; ?></small>
</div>
<div class="thumb">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} ;?>
</div>
</a>
</div>
<?php
}
}
else {
echo 'There seems to be a problem, please try searching again or contact customer support!';
} ?>
ctp下的项目使用此代码显示,但永久链接仍然是
/portfolio/page name
,而不是/category slug/page name
。我该怎么做呢?如果你把帖子归类,这是可能的。然后您可以拥有/category-{slug}/page name
。这对自定义分类法也适用吗?请在我的OP中查看我的更新。是的,它将-最近完成一些非常类似的事情-只需创建一个category-{slug}.php页面(与存档一样),并将每个post类型添加到wp_查询数组中-例如post_type'=>array('portfolio','recent_work','etc.),'cat'=>1
不应该是一个分类法-{slug}在这种情况下是.php页面吗?或者分类术语会像category-{slug}.php页面一样工作吗?我相信分类术语slug也会工作,但这完全取决于您的WP_查询。e、 g.在category-slug.php页面中,您可以定义要从中提取的帖子类型。如果您将帖子放入一个类别中,这是可能的。然后您可以拥有/category-{slug}/page name
。这对自定义分类法也适用吗?请在我的OP中查看我的更新。是的,它将-最近完成一些非常类似的事情-只需创建一个category-{slug}.php页面(与存档一样),并将每个post类型添加到wp_查询数组中-例如post_type'=>array('portfolio','recent_work','etc.),'cat'=>1
不应该是一个分类法-{slug}在这种情况下是.php页面吗?或者分类术语会像category-{slug}.php页面一样工作吗?我相信分类术语slug也会工作,但这完全取决于您的WP_查询。e、 g.在category-slug.php页面中,您将定义要从中提取的帖子类型。