不从自定义帖子类型中拉出图像或文本的功能

时间:2014-10-01 作者:cbanowsky

//Custom Post Type
register_post_type(\'inf_main_feature\', array(
      \'labels\' => array(
            \'name\'   => \'Main Featured\',
            \'singular_name\' => \'Main Featured\',
            \'add_new\' => __( \'Add New\' ),
            \'add_new_item\' => __( \'Add New Feature\' ),
            \'view_item\' => \'View Feature\',
            \'edit_item\' => \'Edit Story\',
            \'new_item\' => __(\'New Featire\'),
            \'view_item\' => __(\'View New Feature\'),
            \'search_items\' => __(\'Search Features\'),
            \'not_found\' =>  __(\'No entries found\'),
            \'not_found_in_trash\' => __(\'No entries found in Trash\'),
    ),
    \'public\' => true,
    \'exclude_from_search\' => true,
    \'show_ui\' => true,
    \'capability_type\' => \'post\',
    \'hierarchical\' => false,
    \'_edit_link\' =>  \'post.php?post=%d\',
    \'rewrite\' => array(
            "slug" => "homebox",
            "with_front" => false,
    ),
    \'query_var\' => true,
    \'supports\' => array(\'title\', \'editor\', \'page-attributes\', \'thumbnail\'),
));

 //Custom Fields

 Carbon_Container::factory(\'custom_fields\', __(\'Feature Options\', \'inf\'))
     ->show_on_post_type(\'inf_main_feature\')
->add_fields(array(
              Carbon_Field::factory(\'text\', \'feature_url\', \'The Link\'),
            Carbon_Field::factory(\'attachment\', \'main_image\', \'Main Image\')
                    ->help_text(\'Image Dimensions - 600 × 600 pixels.\')
    ));

// Main Feature
function inf_feature() {
  $args = array (
\'post_type\' => \'inf_main_feature\',
 \'posts_per_page\' => 1
);
  $feature = get_post($args)[0]->ID;
 $feature_link = get_post_meta($feature->ID, \'feature_url\', true);
 $main_boxID =  get_post_meta($feature->ID, \'main_image\', full);
  $main_image = get_post($main_boxID[0])->guid;
 ?>
我的HTML

  div class="main_feature_container"
      div class="main_feature"
      a href="php echo $feature_link"
        img src="php echo $main_image"
      /a
  /div

忘记标签<;>和<?等我对这个编辑器很在行,无法正确渲染

我无法从这个自定义帖子类型中获取图像或链接。任何帮助都将不胜感激。

1 个回复
最合适的回答,由SO网友:Imran Javed 整理而成

这样试试,可能对你有帮助。我只是从一个名为“gameshowwarriorsw”的特定帖子类型中获取特定帖子的图像。

        $gameShowWarriorsWorld = new WP_Query( \'post_type=gameshowwarriorsw&orderby=date&order=DESC&p=371\' );   
        while ($gameShowWarriorsWorld->have_posts()) : $gameShowWarriorsWorld->the_post();


        $postTitle = get_the_title();
        $postid = get_the_id();
        $postContent    = get_the_content();



    ?>

        <li>    <a href="#" onclick="return get_inzenwarriorhero(<?php echo $postid ; ?>);">
                     <?php the_post_thumbnail(array(219,143)); ?>
                </a> 
        </li>
    <?php 
        endwhile;
       wp_reset_query();
    ?>

结束