wordpress自定义页面发布查询

时间:2015-10-22 13:47:38

标签: php mysql wordpress

我有问题因为我的数据库有用于存储帖子数据的表。我需要从这个表中获取数据并显示在我的register_post_type上。

function DuonamPost() {

    $labels = array(
        'name'                => _x( 'nam', 'Post Type General Name', 'DuonamPost' ),
        'singular_name'       => _x( 'nam', 'Post Type Singular Name', 'DuonamPost' ),
        'menu_name'           => __( 'nam', 'DuonamPost' ),
        'name_admin_bar'      => __( 'nam', 'DuonamPost' ),
        'parent_item_colon'   => __( 'Parent Item:', 'DuonamPost' ),
        'all_items'           => __( 'All Items', 'DuonamPost' ),
        'add_new_item'        => __( 'Add New Item', 'DuonamPost' ),
        'add_new'             => __( 'Add New', 'DuonamPost' ),
        'new_item'            => __( 'New Item', 'DuonamPost' ),
        'edit_item'           => __( 'Edit Item', 'DuonamPost' ),
        'update_item'         => __( 'Update Item', 'DuonamPost' ),
        'view_item'           => __( 'View Item', 'DuonamPost' ),
        'search_items'        => __( 'Search Item', 'DuonamPost' ),
        'not_found'           => __( 'Not found', 'DuonamPost' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'DuonamPost' ),
    );
    $args = array(
        'label'               => __( 'nam', 'DuonamPost' ),
        'description'         => __( 'Duo nam plugin', 'DuonamPost' ),
        'labels'              => $labels,
        'supports'            => array( ),
        'taxonomies'          => array( 'nam_tax' ),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'menu_position'       => 5,
        'show_in_admin_bar'   => true,
        'show_in_nav_menus'   => true,
        'can_export'          => true,
        'has_archive'         => true,      
        'exclude_from_search' => true,
        'publicly_queryable'  => true,
        'query_var'           => 'nam_query',
        'capability_type'     => 'page',
    );
    register_post_type( 'nam', $args );

}
add_action( 'init', 'DuonamPost');

在此代码上,我的链接显示如下: http://localhost/wp/nam/pageopen

现在" pageopen"需要从数据库中检索并显示的是值。

我的表名为wp_duonam,当我打开链接http://localhost/wp/nam/pageopen时,我的查询必须看起来像#34;从wp_duonam中选择*其中link = pageopen;

<?php 
// the query
$the_query = new WP_Query(  array( 'post_type' => 'nam' ) ); ?>

<?php if ( $the_query->have_posts() ) : ?>

    <!-- pagination here -->

    <!-- the loop -->
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    <!-- end of the loop -->

    <!-- pagination here -->

    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

0 个答案:

没有答案