Php 如何仅在头版而不是Wordpress索引的子页面上运行此代码?
我想在头版普通帖子的下方显示一个名为“特色”的特定类别的最后5篇修改帖子,但不显示在后续子页面上。我用这段代码来显示最后五篇文章。除了这5篇文章也在子页面上运行外,所有内容似乎都运行良好Php 如何仅在头版而不是Wordpress索引的子页面上运行此代码?,php,wordpress,Php,Wordpress,我想在头版普通帖子的下方显示一个名为“特色”的特定类别的最后5篇修改帖子,但不显示在后续子页面上。我用这段代码来显示最后五篇文章。除了这5篇文章也在子页面上运行外,所有内容似乎都运行良好 function modified_postsbycategory() { // the query $the_query = new WP_Query( array( 'category_name' => 'featured', 'orderby' => 'modified', 'post
function modified_postsbycategory() {
// the query
$the_query = new WP_Query( array( 'category_name' => 'featured', 'orderby' => 'modified', 'posts_per_page' => 5 ) );
// The Loop
if ( $the_query->have_posts() ) : ?>
<?php
while ( $the_query->have_posts() ) :
$the_query->the_post();
get_template_part( 'template-parts/content', 'modified' );
// End the loop.
endwhile;
// If no content, include the "No posts found" template.
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
<?php wp_reset_postdata(); ?>
<?php
}
// Add a shortcode
add_shortcode('categoryposts', 'modified_postsbycategory');
函数已修改\u postsbycategory(){
//询问
$the_query=new WP_query(数组('category_name'=>'特色','orderby'=>'修改','posts_per_page'=>5));
//环路
如果($the_query->have_posts()):?>
你能帮帮我吗
PS:请检查代码,如果发现任何错误,请纠正我。我只是一个学习者,不是专家。在Wordpress首页可以是
- 你最近的帖子 或
- 静态页面
<?php if (is_home()){ ..... } ?>
否则
<?php if (is_front_page()){ ..... } ?>
在Wordpress首页可以是
- 你最近的帖子 或
- 静态页面
<?php if (is_home()){ ..... } ?>
否则
<?php if (is_front_page()){ ..... } ?>
你只需要检查一下它是否是头版
<?php if (is_front_page()){ ?>
你只需要检查一下它是否是头版
<?php if (is_front_page()){ ?>