Php 如何在WordPress主页上显示自定义帖子?

Php 如何在WordPress主页上显示自定义帖子?,php,html,wordpress,wordpress-theming,Php,Html,Wordpress,Wordpress Theming,现在互联网上有很多关于如何在WordPress页面上显示自定义帖子的问题。我从一开始就遵循了教程 1。我注册了一个自定义帖子 add_action('init', 'portfolio_register'); function portfolio_register() { $labels = array( 'name' => _x('Portofoliu', 'portfolio'), 'singular_name' => _x('

现在互联网上有很多关于如何在WordPress页面上显示自定义帖子的问题。我从一开始就遵循了教程

1。我注册了一个自定义帖子

add_action('init', 'portfolio_register');

function portfolio_register() {     
    $labels = array(
        'name' => _x('Portofoliu', 'portfolio'),
        'singular_name' => _x('Portfolio Item', 'post type singular name'),
        'add_new' => _x('Adauga proiect', 'portfolio item'),
        'add_new_item' => __('Adauga un proiect la portofoliu'),
        'edit_item' => __('Edit Portfolio Item'),
        'new_item' => __('New Portfolio Item'),
        'view_item' => __('View Portfolio Item'),
        'search_items' => __('Search Portfolio'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );     
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail')
      );      
    register_post_type( 'portfolio' , $args );
}
2。我注册了分类法

register_taxonomy("Skills", array("portfolio"), array("hierarchical" => true, "label" => "Platforme", "singular_label" => "Platforma", "rewrite" => true));
<div id="primary" class="site-content">
        <div id="content" role="main">
        <?php if ( have_posts() ) : ?>  
            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', get_post_format() ); ?>
            <?php endwhile; ?>
            <?php twentytwelve_content_nav( 'nav-below' ); ?>

        <?php else : ?>
            <article id="post-0" class="post no-results not-found">
            <?php if ( current_user_can( 'edit_posts' ) ) :
                // Show a different message to a logged-in user who can add posts.
            ?>
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
                </header>
                <div class="entry-content">
                    <p><?php printf( __( 'Ready to publish your first post? <a href="%s">Get started here</a>.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
                </div>

            <?php else :
                // Show the default message to everyone else.
            ?>
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
                </header>
                <div class="entry-content">
                    <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
                    <?php get_search_form(); ?>
                </div>
            <?php endif; // end current_user_can() check ?>
            </article>

        <?php endif; // end have_posts() check ?>
        </div>
    </div>
2。我的首页代码是:

register_taxonomy("Skills", array("portfolio"), array("hierarchical" => true, "label" => "Platforme", "singular_label" => "Platforma", "rewrite" => true));
<div id="primary" class="site-content">
        <div id="content" role="main">
        <?php if ( have_posts() ) : ?>  
            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', get_post_format() ); ?>
            <?php endwhile; ?>
            <?php twentytwelve_content_nav( 'nav-below' ); ?>

        <?php else : ?>
            <article id="post-0" class="post no-results not-found">
            <?php if ( current_user_can( 'edit_posts' ) ) :
                // Show a different message to a logged-in user who can add posts.
            ?>
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
                </header>
                <div class="entry-content">
                    <p><?php printf( __( 'Ready to publish your first post? <a href="%s">Get started here</a>.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
                </div>

            <?php else :
                // Show the default message to everyone else.
            ?>
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
                </header>
                <div class="entry-content">
                    <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
                    <?php get_search_form(); ?>
                </div>
            <?php endif; // end current_user_can() check ?>
            </article>

        <?php endif; // end have_posts() check ?>
        </div>
    </div>

.,'Twentyleven'),管理员url('post new.php');?>


我在我的管理员上有自定义帖子和分类法,但是如何在我的公文包页面上显示它呢?

我遇到了这个问题。此代码适用于我:

<?php 
$args = array( 'post_type' => 'ENTER YOU POST TYPE HERE'); 
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();

the_content();

endwhile;
试试这个

<div id="primary" class="site-content">
        <div id="content" role="main">
        <?php 
        global $wp_query;
        $args = array(
            'post_type' => 'portfolio'
        );

        $temp_query = $wp_query;
        $wp_query = NULL;
        $wp_query = new WP_Query( $args );

        if ( have_posts() ) : ?>  
            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', get_post_format() ); ?>
            <?php endwhile; ?>
            <?php twentytwelve_content_nav( 'nav-below' ); ?>

        <?php else : ?>
            <article id="post-0" class="post no-results not-found">
            <?php if ( current_user_can( 'edit_posts' ) ) :
                // Show a different message to a logged-in user who can add posts.
            ?>
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
                </header>
                <div class="entry-content">
                    <p><?php printf( __( 'Ready to publish your first post? <a href="%s">Get started here</a>.', 'twentytwelve' ), admin_url( 'post-new.php' ) ); ?></p>
                </div>

            <?php else :
                // Show the default message to everyone else.
            ?>
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
                </header>
                <div class="entry-content">
                    <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
                    <?php get_search_form(); ?>
                </div>
            <?php endif; // end current_user_can() check ?>
            </article>

        <?php endif; // end have_posts() check ?>
        </div>
    </div>

.,'Twentyleven'),管理员url('post new.php');?>



  • 在我的首页中,代码是:前面的代码

    <?php if ( have_posts() ) : ?>
    
    
    
    使用 请按照WordPress抄本进行操作