[英]Displaying a page of all post categories with thumbnails in Wordpress
[英]error in displaying all categories on portfolio page in wordpress
我正在使用下面的代码在此模板中使用名为portfolio.php的模板创建投资组合页面。
我想在页面上显示所有类别和投资组合。
参考链接: - https://www.thewritersforhire.com/portfolio/
完全相同,如上页。
只显示一个数组,但在我的页面中显示1个类别即全部
我用过的代码:
<?php
$alltags = [];
$args = [
'order' => 'ASC',
'orderby' => 'menu_order',
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'child_of' => 0,
'parent' => $id,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish',
'cat' => 399,
'posts_per_page' => 100,
];
$query = new WP_Query($args);
$pages = $query->posts;
foreach ($pages as $page) {
// echo "<pre>";
//print_r($page);
//echo "</pre>";
//$meta = get_post_meta($page->ID, '', true);
$tags = wp_get_post_tags($page->ID);
if ($tags) {
foreach ($tags as $tag) {
// $tag->name = str_replace('&', "", $tag->name);
array_push($alltags, $tag->name);
}
}
}
$uniquetag = array_unique($alltags);
asort($uniquetag);
array_unshift($uniquetag, 'All');
echo "<pre>";
print_r($uniquetag);
echo "</pre>";
?>
<div class="row">
<div class="toolbar mb2 mt2">
<?php
if ($uniquetag) {
foreach ($uniquetag as $key => $value) {
if ($value == 'Addhomeportfolio') {} else {
?>
<button class="btn fil-cat" data-rel="<?php $string = str_replace(' ', '', $value);
echo $string = str_replace('&', "", $string);?>"><?php echo $value; ?></button>
<?php
}}
}
?>
</div>
</div>
尝试在$ args中添加"numberposts" => -1,
代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.