WordPress在投资组合页面上显示所有类别的错误



我使用以下代码在此模板中使用称为portfolio.php的模板创建Portfolio页面。
我想在页面上显示所有类别和投资组合。

参考链接:-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('&amp;', "", $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('&amp;', "", $string);?>"><?php echo $value; ?></button>
                        <?php
}}
}
?>
                </div>
            </div>

尝试添加 "numberposts" => -1, $ args

中的代码

相关内容

最新更新