Php 如何在Wordpress主页上显示帖子,按上次更新的顺序排列
我想在主页上按上次更新的顺序显示帖子,如何为其设置正确的功能,以及在wordpress中将该功能粘贴到哪里?创建您的插件并将此功能粘贴到插件文件中Php 如何在Wordpress主页上显示帖子,按上次更新的顺序排列,php,wordpress,webpage,Php,Wordpress,Webpage,我想在主页上按上次更新的顺序显示帖子,如何为其设置正确的功能,以及在wordpress中将该功能粘贴到哪里?创建您的插件并将此功能粘贴到插件文件中 function wpb_lastupdated_posts() { // Query Arguments $lastupdated_args = array( 'orderby' => 'modified', 'ignore_sticky_posts' => '1' ); //Loop
function wpb_lastupdated_posts()
{
// Query Arguments
$lastupdated_args = array(
'orderby' => 'modified',
'ignore_sticky_posts' => '1'
);
//Loop to display 5 recently updated posts
$lastupdated_loop = new WP_Query( $lastupdated_args );
$counter = 1;
$string .= '<ul>';
while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post();
$string .= '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>';
$counter++;
endwhile;
$string .= '</ul>';
return $string;
wp_reset_postdata();
}
//add a shortcode
add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');
use this shortcode : [lastupdated-posts]
函数wpb\u lastupdated\u posts()
{
//查询参数
$lastupdated_args=数组(
'orderby'=>'modified',
“忽略粘贴的帖子”=>“1”
);
//循环显示5篇最近更新的文章
$lastupdated\U loop=新的WP\U查询($lastupdated\U参数);
$counter=1;
$string.='';
而($lastupdated_loop->have_posts()&&$counter<5):$lastupdated_loop->the_post();
$string.='- ('.get_the_modified_date()。)
';
$counter++;
结束时;
$string.='
';
返回$string;
wp_reset_postdata();
}
//添加一个短代码
添加快捷码(“lastupdated-posts”、“wpb\u lastupdated\u posts”);
使用此短代码:[最近更新的帖子]
创建插件并将此函数粘贴到插件文件中
function wpb_lastupdated_posts()
{
// Query Arguments
$lastupdated_args = array(
'orderby' => 'modified',
'ignore_sticky_posts' => '1'
);
//Loop to display 5 recently updated posts
$lastupdated_loop = new WP_Query( $lastupdated_args );
$counter = 1;
$string .= '<ul>';
while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post();
$string .= '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date() .') </li>';
$counter++;
endwhile;
$string .= '</ul>';
return $string;
wp_reset_postdata();
}
//add a shortcode
add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');
use this shortcode : [lastupdated-posts]
函数wpb\u lastupdated\u posts()
{
//查询参数
$lastupdated_args=数组(
'orderby'=>'modified',
“忽略粘贴的帖子”=>“1”
);
//循环显示5篇最近更新的文章
$lastupdated\U loop=新的WP\U查询($lastupdated\U参数);
$counter=1;
$string.='';
而($lastupdated_loop->have_posts()&&$counter<5):$lastupdated_loop->the_post();
$string.='- ('.get_the_modified_date()。)
';
$counter++;
结束时;
$string.='
';
返回$string;
wp_reset_postdata();
}
//添加一个短代码
添加快捷码(“lastupdated-posts”、“wpb\u lastupdated\u posts”);
使用此短代码:[最近更新的帖子]
有三种方法可以做到这一点
function shortcode_latest_homepage_posts(){
$lquery = new WP_Query(array('order' => 'DESC'));
if($lquery->have_posts()){
while($lquery->have_posts()){
$lquery->the_post();
the_title();
the_content();
}
}
wp_reset_postdata();
}
add_shortcode('latest_posts', 'shortcode_latest_homepage_posts');
function latest_homepage_posts(){
$lquery = new WP_Query(array('order' => 'DESC'));
if($lquery->have_posts()){
while($lquery->have_posts()){
$lquery->the_post();
the_title();
the_content();
}
}
wp_reset_postdata();
}
add_action('latest_post', 'latest_homepage_posts');
<?php do_action('latest_post');?>
<?php
$lquery = new WP_Query(array('order' => 'DESC'));
if($lquery->have_posts()){
while($lquery->have_posts()){
$lquery->the_post();
the_title();
the_content();
}
}
wp_reset_postdata();
?>
或
3.只需将此代码添加到您希望在模板中显示帖子的位置,该模板为home.php或front-page.php等主页指定或制作
<?php do_action('latest_post');?>
<?php
$lquery = new WP_Query(array('order' => 'DESC'));
if($lquery->have_posts()){
while($lquery->have_posts()){
$lquery->the_post();
the_title();
the_content();
}
}
wp_reset_postdata();
?>
有三种方法可以做到这一点
function shortcode_latest_homepage_posts(){
$lquery = new WP_Query(array('order' => 'DESC'));
if($lquery->have_posts()){
while($lquery->have_posts()){
$lquery->the_post();
the_title();
the_content();
}
}
wp_reset_postdata();
}
add_shortcode('latest_posts', 'shortcode_latest_homepage_posts');
function latest_homepage_posts(){
$lquery = new WP_Query(array('order' => 'DESC'));
if($lquery->have_posts()){
while($lquery->have_posts()){
$lquery->the_post();
the_title();
the_content();
}
}
wp_reset_postdata();
}
add_action('latest_post', 'latest_homepage_posts');
<?php do_action('latest_post');?>
<?php
$lquery = new WP_Query(array('order' => 'DESC'));
if($lquery->have_posts()){
while($lquery->have_posts()){
$lquery->the_post();
the_title();
the_content();
}
}
wp_reset_postdata();
?>
或
3.只需将此代码添加到您希望在模板中显示帖子的位置,该模板为home.php或front-page.php等主页指定或制作
<?php do_action('latest_post');?>
<?php
$lquery = new WP_Query(array('order' => 'DESC'));
if($lquery->have_posts()){
while($lquery->have_posts()){
$lquery->the_post();
the_title();
the_content();
}
}
wp_reset_postdata();
?>