一个完整的WordPress企业黄页和供求信息平台的解决方案

我将为您提供一个完整的WordPress企业黄页和供求信息平台的解决方案。由于WordPress是基于PHP的CMS系统,完整的实现需要多个组件配合,以下是核心功能的实现方案:

把以下代码写进functions.php文件里


// 注册自定义文章类型 - 企业黄页
function create_business_directory() {
    register_post_type('business',
        array(
            'labels' => array(
                'name' => __('企业黄页'),
                'singular_name' => __('企业')
            ),
            'public' => true,
            'has_archive' => true,
            'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
            'rewrite' => array('slug' => 'business')
        )
    );
}
add_action('init', 'create_business_directory');

// 注册自定义分类 - 行业分类
function create_business_taxonomy() {
    register_taxonomy(
        'industry',
        'business',
        array(
            'label' => __('行业分类'),
            'rewrite' => array('slug' => 'industry'),
            'hierarchical' => true
        )
    );
}
add_action('init', 'create_business_taxonomy');

把以下代码写进supply-demand.php文件里

 注册供求信息类型
function create_supply_demand() {
    register_post_type('supply_demand',
        array(
            'labels' => array(
                'name' => __('供求信息'),
                'singular_name' => __('信息')
            ),
            'public' => true,
            'has_archive' => true,
            'supports' => array('title', 'editor', 'author'),
            'rewrite' => array('slug' => 'supply-demand')
        )
    );
    
    // 信息类型分类(供应/求购)
    register_taxonomy(
        'sd_type',
        'supply_demand',
        array(
            'label' => __('信息类型'),
            'rewrite' => array('slug' => 'type'),
            'hierarchical' => false
        )
    );
}
add_action('init', 'create_supply_demand');

把以下代码写进shortcodes.php文件里

 企业列表短代码
function business_directory_shortcode($atts) {
    $args = shortcode_atts(array(
        'industry' => '',
        'limit' => 10
    ), $atts);
    
    $query_args = array(
        'post_type' => 'business',
        'posts_per_page' => $args['limit']
    );
    
    if(!empty($args['industry'])) {
        $query_args['tax_query'] = array(
            array(
                'taxonomy' => 'industry',
                'field' => 'slug',
                'terms' => $args['industry']
            )
        );
    }
    
    $businesses = new WP_Query($query_args);
    
    ob_start();
    if($businesses->have_posts()) {
        echo '<div class="business-directory">';
        while($businesses->have_posts()) {
            $businesses->the_post();
            echo '<div class="business-item">';
            echo '<h3><a href="'.get_permalink().'">'.get_the_title().'</a></h3>';
            echo '<div class="excerpt">'.get_the_excerpt().'</div>';
            echo '</div>';
        }
        echo '</div>';
    }
    wp_reset_postdata();
    return ob_get_clean();
}
add_shortcode('business_directory', 'business_directory_shortcode');

把以下代码写进template-business.php文件里

php
/*
Template Name: 企业详情模板
*/
get_header(); ?>

<div class="business-detail">
    <?php while(have_posts()) : the_post(); ?>
        <h1><?php the_title(); ?></h1>
        <div class="business-meta">
            <?php 
            $address = get_post_meta(get_the_ID(), 'business_address', true);
            $phone = get_post_meta(get_the_ID(), 'business_phone', true);
            ?>
            <p>地址: <?php echo esc_html($address); ?></p>
            <p>电话: <?php echo esc_html($phone); ?></p>
        </div>
        <div class="business-content">
            <?php the_content(); ?>
        </div>
    <?php endwhile; ?>
</div>

<?php get_footer(); ?>

实现说明:

  1. 将functions.php代码添加到您的主题functions.php文件中
  2. supply-demand.php和shortcodes.php可以创建为插件或添加到functions.php
  3. template-business.php保存为模板文件
  4. 您还需要安装Advanced Custom Fields插件来管理自定义字段
  5. 建议使用Elementor或WP Bakery等页面构建器来设计前端界面

这个方案提供了企业黄页和供求信息发布的核心功能,您可以根据需要进一步扩展。建议先安装WordPress并选择一个适合的商业主题作为基础。