Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我想在主页WordPress中显示自定义分类列表_Php_Html_Css_Wordpress - Fatal编程技术网

Php 我想在主页WordPress中显示自定义分类列表

Php 我想在主页WordPress中显示自定义分类列表,php,html,css,wordpress,Php,Html,Css,Wordpress,我用html和css创建了一些列表。我想根据这个设计显示我的自定义分类法。出于这个原因,我已经注册了一个名为“surgical”的自定义post类型和一个名为“surgical_cat”的自定义分类法。我希望当我创建类别时,它会显示为包含4列的列表。当我单击任何类别时,它会将我带到一个特定页面(例如“类别”),其中显示该类别下的所有帖子 要查看设计,请访问以下链接: 请参阅我的html代码: <div class="fix top_listing"> <header class

我用html和css创建了一些列表。我想根据这个设计显示我的自定义分类法。出于这个原因,我已经注册了一个名为“surgical”的自定义post类型和一个名为“surgical_cat”的自定义分类法。我希望当我创建类别时,它会显示为包含4列的列表。当我单击任何类别时,它会将我带到一个特定页面(例如“类别”),其中显示该类别下的所有帖子

要查看设计,请访问以下链接:

请参阅我的html代码:

<div class="fix top_listing">
<header class="fix listing_title">
<h2>Procedures Surgical</h2>
</header>
<div class="fix floatleft single_listing">
<ul>
    <li><a href="">Arm Lift (0)</a></li>
    <li><a href="">Breast Lift (1)</a></li>
    <li><a href="">Cheek Implants (1) </a></li>
    <li><a href="">Face Lift (1)</a></li>
    <li><a href="">Liposuction (1)</a></li>
    <li><a href="">Lumpectomy (1)</a></li>
</ul>
</div>
</div>
请参阅functions.php中的自定义分类代码:

/* Register Custom Post Types ********************************************/

add_action( 'init', 'surgical_post' );
function surgical_post() {

register_post_type( 'surgical',
    array(
            'labels' => array(
                    'name' => __( 'Surgical' ),
                    'singular_name' => __( 'Surgical' ),
                    'add_new' => __( 'Add New' ),
                    'add_new_item' => __( 'Add New Surgical' ),
                    'edit_item' => __( 'Edit Surgical' ),
                    'new_item' => __( 'New Surgical' ),
                    'view_item' => __( 'View Surgical' ),
                    'not_found' => __( 'Sorry, we couldn\'t find the Surgical you are looking for.' )
            ),
    'public' => true,
    'publicly_queryable' => false,
    'exclude_from_search' => true,
    'menu_position' => 14,
    'has_archive' => false,
    'hierarchical' => false,
    'capability_type' => 'page',
    'rewrite' => array( 'slug' => 'surgical' ),
    'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail', ),
    'taxonomies' => array('tag')
    )
);
}
/* REGISTERING CUSTOM TAXONOMY FOR BUSINESS LISTING *******************************************/

add_action( 'init', 'business_listing_taxonomy');
function business_listing_taxonomy() {
register_taxonomy(
    'surgical_cat',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    'surgical',  //post type name
    array(

        'public'                => true,
        'hierarchical'          => true,
        'label'                 => 'Surgical Category',  //Display name
        'query_var'             => true,
        'show_admin_column' => true,
        'rewrite'               => array(
            'slug'              => 'surgical-category', // This controls the base slug that will display before each term
            'with_front'        => false // Don't display the category base before
            )
        )
);

}

我想知道我应该在html/css列表中使用哪些循环或查询,以便它们可以在主页中显示自定义类别?有人能帮我修一下吗

在要列出自定义分类法的文件中使用以下代码

<style>
    ul.custom_cat_list {
        list-style: none;
    }
    ul.custom_cat_list li {
        width: 25%;
        float: left;
    }
</style>

<ul class="custom_cat_list">
    <?php $categories = get_categories('taxonomy=surgical_cat&post_type=surgical'); ?>
        <?php foreach ($categories as $category) : ?>
            <li><a href="<?php echo get_category_link($category->cat_ID); ?>"><?php echo $category->name; ?></a></li>
    <?php endforeach; ?>
<ul>

定制目录{
列表样式:无;
}
定制目录{
宽度:25%;
浮动:左;
}

Hi@Kausha Mehta,谢谢你的回答。使用代码后,我的清单如下所示:。但我想将其显示在4列中,就像design(我在问题中提到过)一样。我怎么做呢?没有了,我在等待你的善意回应。保持良好状态。@active worker我根据您的要求更新了我的答案,只需在
ul
中添加类并为其添加样式即可。希望它能为你工作。嗨@Kausha Mehta,我很高兴地说它工作得很好!!!如果你不介意,我可以问你另一件事吗?我希望当点击一个类别链接时,该类别中的所有帖子都会显示在一个类别页面上,使用模板层次规则指定的相应类别模板。我怎么做呢?谢谢。嗨@Kausha Mehta,请访问以下链接:和。希望你能理解。谢谢。嗨@Kausha Mehta,谢谢你的建议。好的,我将为此创建一个新问题。我接受你的回答。非常感谢您花宝贵的时间回复。当心。