问题是,我试图用一个“got to this Portfolio”按钮,只在拇指中显示文章的拇指和标题。类似这样:
<section>
<div class="portfolio">
<div class="row">
<?php
$args = array( \'post_type\' => \'portfolio\', \'posts_per_page\' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo \'<div class="col-md-4">\';
echo \'<h4>\';
the_title();
echo \'</h4>\';
// The Thumb
echo \'</div>\';
endwhile;
?>
</div>
</div>
</section>
是的,h4没有显示,idk为什么。。。
WordPress管理面板中没有显示对自定义类型的thumb支持的另一件事是函数。php代码:
/* Custom Post Type Start */
function create_posttype() {
register_post_type( \'portfolio\',
// CPT Options
array(
\'labels\' => array(
\'name\' => __( \'portfolio\' ),
\'singular_name\' => __( \'portfolio\' )
),
\'public\' => true,
\'has_archive\' => false,
\'rewrite\' => array(\'slug\' => \'portfolio\'),
)
);
}
// Hooking up our function to theme setup
add_action( \'init\', \'create_posttype\' );
/* Custom Post Type End */
/*Custom Post type start*/
function cw_post_type_portfolio() {
$supports = array(
\'title\', // post title
\'editor\', // post content
\'author\', // post author
\'thumbnail\', // featured images
\'excerpt\', // post excerpt
\'custom-fields\', // custom fields
\'comments\', // post comments
\'revisions\', // post revisions
\'post-formats\', // post formats
);
$labels = array(
\'name\' => _x(\'portfolio\', \'plural\'),
\'singular_name\' => _x(\'portfolio\', \'singular\'),
\'menu_name\' => _x(\'portfolio\', \'admin menu\'),
\'name_admin_bar\' => _x(\'portfolio\', \'admin bar\'),
\'add_new\' => _x(\'Add New\', \'add new\'),
\'add_new_item\' => __(\'Add New portfolio\'),
\'new_item\' => __(\'New portfolio\'),
\'edit_item\' => __(\'Edit portfolio\'),
\'view_item\' => __(\'View portfolio\'),
\'all_items\' => __(\'All portfolio\'),
\'search_items\' => __(\'Search portfolio\'),
\'not_found\' => __(\'No portfolio found.\'),
);
$args = array(
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' ),
\'labels\' => $labels,
\'public\' => true,
\'query_var\' => true,
\'rewrite\' => array(\'slug\' => \'portfolio\'),
\'has_archive\' => true,
\'hierarchical\' => false,
);
register_post_type(\'portfolio\', $args);
}
add_action(\'init\', \'cw_post_type_portfolio\');
/*Custom Post type end*/
最合适的回答,由SO网友:rudtek 整理而成
从函数中删除以上所有代码。php并使用:
function cw_post_type_portfolio() {
$supports = array(
\'title\', // post title
\'editor\', // post content
\'author\', // post author
\'thumbnail\', // featured images
\'excerpt\', // post excerpt
\'custom-fields\', // custom fields
\'comments\', // post comments
\'revisions\', // post revisions
\'post-formats\', // post formats
);
$labels = array(
\'name\' => _x(\'portfolios\', \'plural\'),
\'singular_name\' => _x(\'portfolio\', \'singular\'),
\'menu_name\' => _x(\'portfolio\', \'admin menu\'),
\'name_admin_bar\' => _x(\'portfolio\', \'admin bar\'),
\'add_new\' => _x(\'Add New\', \'add new\'),
\'add_new_item\' => __(\'Add New portfolio\'),
\'new_item\' => __(\'New portfolio\'),
\'edit_item\' => __(\'Edit portfolio\'),
\'view_item\' => __(\'View portfolio\'),
\'all_items\' => __(\'All portfolios\'),
\'search_items\' => __(\'Search portfolios\'),
\'not_found\' => __(\'No portfolios found.\'),
);
$args = array(
\'supports\' => $supports,
\'labels\' => $labels,
\'public\' => true,
\'query_var\' => true,
\'rewrite\' => array(\'slug\' => \'portfolio\'),
\'has_archive\' => true,
\'hierarchical\' => false,
);
register_post_type(\'mla_portfolio\', $args);
}
add_action(\'init\', \'cw_post_type_portfolio\');
/*Custom Post type end*/
我编辑了几行内容,包括删除重复问题和使用函数调用中未包含的实际$supports数组。我还将您的posttype从普通portfolio更改为mla\\U portfolio,因此您需要将wp\\U查询的代码更改为正确的引用。
h4不起作用的原因是the_title()
而不是get_the_title()
.
更新
添加的查询代码:
<section>
<div class="portfolio">
<div class="row">
<?php
$args = array( \'post_type\' => \'mla_portfolio\', \'posts_per_page\' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo \'<div class="col-md-4">\';
echo \'<h4>\'.get_the_title().\'</h4>\';
echo \'<a href="\' . get_permalink() . \'">\' . get_the_post_thumbnail() . \'</a>\';
echo \'</div>\';
endwhile;
?>
</div>
</div>
</section>