我试图简单地将所有项目纳入特定类别(例如“网站”或“特色”)中。
使用时:
$args = array(
\'post_type\' => \'project\',
\'category_name\' => \'websites\',
\'posts_per_page\' => 10,
);
未返回任何内容。
简单使用时:
$args = array(
\'post_type\' => \'project\',
);
我确实收到了回复的帖子(项目),只是不是我想要的类别。
以下是我的完整代码:
function gmb_register_project_section () {
$args = array(
\'post_type\' => \'project\',
\'category_name\' => \'websites\',
\'posts_per_page\' => 10,
);
$post_query = new WP_Query($args);
if ($post_query->have_posts()) :
$output = \'<div class="gmb_custom-project-module">\';
while ($post_query->have_posts()) {
$post_query->the_post();
$output .= \'<a href="\'. get_permalink(). \'"><article class="gmb_project-item" style="background: url(\\\'\'. get_the_post_thumbnail_url(). \'\\\') no-repeat center center;"><div class="inner"><h2>\'.
get_the_title(). \'</h2><div class="gmb_arrow-icon"><?xml version="1.0" encoding="iso-8859-1"?><svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><g><g><path d="M506.134,241.843c-0.006-0.006-0.011-0.013-0.018-0.019l-104.504-104c-7.829-7.791-20.492-7.762-28.285,0.068 c-7.792,7.829-7.762,20.492,0.067,28.284L443.558,236H20c-11.046,0-20,8.954-20,20c0,11.046,8.954,20,20,20h423.557 l-70.162,69.824c-7.829,7.792-7.859,20.455-0.067,28.284c7.793,7.831,20.457,7.858,28.285,0.068l104.504-104 c0.006-0.006,0.011-0.013,0.018-0.019C513.968,262.339,513.943,249.635,506.134,241.843z"/></g></g></svg></div></div></article></a>\';
}
wp_reset_postdata();
$output .= \'</div>\';
endif;
return $output;
}
// Register shortcode
add_shortcode(\'gmb_project_section\', \'gmb_register_project_section\');
我使用的是Divi主题,带有一个代码模块,允许您将短代码输入到。
提前谢谢Ben