php - 如何显示自定义帖子类型的其他字段并显示特色缩略图选项?

标签 php html wordpress css

'我能够显示我制作的 Wordpress 自定义帖子插件中的标题和主要内容,并且能够使用标题和内容对其进行循环,但无法让其他字段显示公司和其他详细信息。

我也无法显示特色缩略图选项,尽管我在我的插件中提到了它

我的自定义插件

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

    $labels = array(
        'name' => ('portfolios') , 
        'singular_name' => ('portfolio'), 
        'add_new' => ('Add New') , 
        'add_new_item' => ('Add New Portfolio') ,  
        'edit_item' => ('Edit Portfolio') , 
        'new_item' => ('New Portfolio'), 
        'view_item' => ('View Portfolio'), 
        'search_items' => ('Search Portfolio'), 
        'not_found' => ('No Portfolio found'), 
        'not_found_in_trash' => ('No Portfolio found in trash'), 
        'parent_item_colon' => ('Parent Portfolio'),
        'menu_name' => ('Portfolio')
        );

    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'description' => 'Portfolio works',
        'support' => array('title', 'editor','thumbnail', 'custom-fields','trackbacks','post-formats', 'page-attributes', 'comments'),
        'taxonomies' => array('category'),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        //'menu_icon' => '',
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archieve' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'register_meta_box_cb' => 'portfolio_meta_boxes',
        );

    register_post_type( 'portfolio', $args);
}





add_filter( 'pre_get_posts', 'alphabetize_portfolios' );

function alphabetize_portfolios( $query ) {
    if ( is_post_type_archive('portfolio') ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC' );
        $query->set( 'nopaging', true );
    }
    return $query;
}
add_action( 'save_post', 'save_portfolio_meta_data' );
function portfolio_meta_boxes() {
    add_meta_box( 'portfolio_url_meta', __('Portfolio URL'), 'portfolio_url_meta_box', 'portfolio', 'normal', 'high' );
    add_meta_box( 'portfolio_company_meta', __('Company'), 'portfolio_company_meta_box', 'portfolio', 'normal', 'high' );
}

function portfolio_url_meta_box() {
    if ( function_exists('wp_nonce_field') ) 
        wp_nonce_field('portfolio_url_nonce', '_portfolio_url_nonce'); 
?>
    <p><label for="_portfolio_url">Portfolio URL</label> 
    <input type="text" name="_portfolio_url" 
        value="<?php echo esc_html( get_post_meta( get_the_ID(), '_portfolio_url', true ), 1 ); ?>" /></p>

<?php
}

function portfolio_company_meta_box() { 
    global $post; 
    if ( function_exists('wp_nonce_field') ) wp_nonce_field('portfolio_company_nonce', '_portfolio_company_nonce'); 
?> 
    <p><label for="_portfolio_company">Company</label> 
    <input type="text" name="_portfolio_company" 
        value="<?php echo esc_html( get_post_meta( get_the_ID(), '_portfolio_company', true ), 1 ); ?>" /></p>
    <p><label for="_portfolio_company_country">Country</label> 
    <input type="text" name="_portfolio_company_country" 
        value="<?php echo esc_html( get_post_meta( get_the_ID(), '_portfolio_company_country', true ), 1 ); ?>" /></p>


<?php
}
function save_portfolio_meta_data( $post_id ) {
    // ignore autosaves
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
        return $post_id;

    // check post type
    if ( 'portfolio' != $_POST['post_type'] )
        return $post_id;

    // check capabilites
    if ( 'portfolio' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
        return $post_id;

    // check nonces
    check_admin_referer( 'portfolio_url_nonce', '_portfolio_url_nonce' );
    check_admin_referer( 'portfolio_company_nonce', '_portfolio_company_nonce' );

    // Still here? Then save the fields
    if ( empty( $_POST['_portfolio_url'] ) ) {
        $storedcode = get_post_meta( $post_id, '_portfolio_url', true );
        delete_post_meta( $post_id, '_portfolio_url', $storedurl );
    }
    else 
        update_post_meta( $post_id, '_portfolio_url', $_POST['_portfolio_url'] );

    if ( empty( $_POST['_portfolio_company'] ) ) {
        $storedname = get_post_meta( $post_id, '_portfolio_company', true );
        delete_post_meta( $post_id, '_portfolio_company', $storedcompany );
    }
    else 
        update_post_meta( $post_id, '_portfolio_company', $_POST['_portfolio_company'] );

    if ( empty( $_POST['_portfolio_company_country'] ) ) {
        $storedemail = get_post_meta( $post_id, '_portfolio_company_country', true );
        delete_post_meta( $post_id, '_portfolio_company_country', $storedcountry );
    }
    else 
        update_post_meta( $post_id, '_portfolio_company_country', $_POST['_portfolio_company_country'] );



}
?>

**single-portfolio.php**

<div class="row portfolio">
          <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 portfoliobox">
            <div class="thumbnail">
            <a href="#">
            <img src="<?php echo get_template_directory_uri(); ?>/img/responsive-webness.png" class="img-responsive" alt="" />
            </a>

            <p><?php the_title(); ?></p>
            </div><!-- .thumbnail -->
          </div>

          <div class="col-lg-8 col-md-8 col-sm-6 col-xs-12 ">

            <div class="thumbnail">
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <p><?php the_content(); ?></p>
        <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
            <p><?php the_title(); ?></p>
            </div><!-- .thumbnail -->
          </div>

page-portfolio.php

<div class="row portfolio">
          <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 portfoliobox">
            <div class="thumbnail">
            <a href="#">
            <img src="<?php echo get_template_directory_uri(); ?>/img/responsive-webness.png" class="img-responsive" alt="" />
            </a>

            <p><?php the_title(); ?></p>
            </div><!-- .thumbnail -->
          </div>

          <div class="col-lg-8 col-md-8 col-sm-6 col-xs-12 ">

            <div class="thumbnail">
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <p><?php the_content(); ?></p>
        <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
            <p><?php the_title(); ?></p>
            </div><!-- .thumbnail -->
          </div>

single-portfolio.php

<div class="row portfolio">
          <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 portfoliobox">
            <div class="thumbnail">
            <a href="#">
            <img src="<?php echo get_template_directory_uri(); ?>/img/responsive-webness.png" class="img-responsive" alt="" />
            </a>

            <p><?php the_title(); ?></p>
            </div><!-- .thumbnail -->
          </div>

          <div class="col-lg-8 col-md-8 col-sm-6 col-xs-12 ">

            <div class="thumbnail">
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <p><?php the_content(); ?></p>
        <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
            <p><?php the_title(); ?></p>
            </div><!-- .thumbnail -->
          </div>

最佳答案

你看过这个documentation吗? ?看起来您需要使用 the_meta() 或另一个受支持的标签。

关于php - 如何显示自定义帖子类型的其他字段并显示特色缩略图选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23913607/

相关文章:

javascript - 打印无效后增加表格宽度

php - 限制上传除一种文件格式之外的所有文件格式

php - 如何使用php for循环将多个值插入数据库

html - Firefox无法动态识别音频文件

php - WordPress the_content 不适用于自定义帖子类型

php - WordPress 重定向到静态index.html 页面,同时保持子页面完整?

php - Mysql Server 运行但 Laravel 项目中的 Artisan 不这么认为

javascript - 当我单击操作下拉菜单时,选项显示在滚动条中,为什么?

user-interface - 使用 HTML5 的新输入类型显示表单错误

php - Genesis Framework - 如何更改自定义 header css 代码?