坦率地说,这个问题不应该存在,它在网络上已经被回答了数百次。。
我将回答最棘手的部分-查询本身。其他一切都很简单HTML
和PHP
. 你也可以在下面我提供的链接中找到例子。如果你做不到PHP
和HTML
你自己,你不应该问这个问题,你应该学习PHP
和HTML
(这很容易掌握)。
$args = array(
\'post_type\' => \'your-post-type-name\',
\'posts_per_page\' => -1, //-1 means "get all posts", 5 would mean "get 5 posts" etc
\'meta_query\' => array(
array(
\'key\' => \'show_on_home_page\',
\'value\' => true,
\'compare\' => \'IN\', //Possible values: \'=\' \'>\' \'<\' etc
)
),
//In order to order by custom meta, you will need to make sure it exists
\'meta_query\' => array(
array(
\'key\' => \'home_page_posts_order_sequence\',
\'compare\' => \'exists\',
//Specifying type is VERY recommended, otherwise it might go wrong
\'type\' => \'numeric\',
)
),
\'orderby\' => array( \'home_page_posts_order_sequence\' => \'DESC\' );
// DESC: descending order ASC: ascending order
);
$query_results = new WP_Query( $args );
Read more from here.