大佬教程收集整理的这篇文章主要介绍了php-在两页上显示WordPress帖子,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的网站上有三页.我们称它们为home,page2和page3.
我的“主页”页面设置为静态首页.我的“ page2”设置为博客页面.
我想要的是以下内容:
和
仅显示具有特定类别的帖子的PHP代码(或者在我的情况下,实际上显示不包括两个类别的帖子)如下:
<?PHP query_posts($query_String . '&cat=-3,-8'); ?>
<?PHP if (have_posts()) : ?>
<?PHP while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?PHP the_ID(); ?>">
<h3><a href="<?PHP the_permalink() ?>" rel="bookmark"
title="PeRMANent Link to <?PHP the_title_attribute(); ?>">
<?PHP the_title(); ?></a></h3>
<?PHP the_excerpt('Read the rest of this entry »'); ?>
</div><!-- /.post-->
现在,在我的page.PHP中,我具有以下代码来显示具有一个类别的帖子:
<?PHP
// BEGIN IF PAGE is newspaper articles page
if ( is_page('newspaper') ) {
//BEGIN POST REGION
query_posts($query_String . '&cat=8'); ?>
<?PHP if (have_posts()) : ?>
<?PHP while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?PHP the_ID(); ?>">
<h3><?PHP the_title(); ?></h3>
<?PHP the_content('Read more »'); ?>
</div><!-- /.post-->
<?PHP endwhile; ?>
<?PHP else : ?>
<?PHP endif; ?>
<?PHP
} //end if is_page
?>
但是它没有在报纸页面(或本问题的第3页)中显示适当的帖子.但是,它确实适用于文章页面(主index.PHP博客页面).
编辑:我也尝试了以下@L_618_44@(但不起作用).我把它放在index.PHP文件中:
<?PHP
if ( is_page('newspaper') || is_home() ) { // START if is home
?>
<?PHP if (have_posts()) : ?>
<?PHP while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?PHP the_ID(); ?>">
<h3><a href="<?PHP the_permalink() ?>" rel="bookmark"
title="PeRMANent Link to
<?PHP the_title_attribute(); ?>">
<?PHP the_title(); ?></a></h3>
<!--<p><?PHP the_time('F jS, Y') ?> <?PHP //the_author() ?></p>-->
<?PHP the_excerpt('Read the rest of this entry »'); ?>
</div><!-- /.post-->
<?PHP endwhile; ?>
<?PHP else : ?>
<?PHP endif; ?>
<?PHP
} //end if is_home() or is_page()
?>
同样,这会在博客主页面上显示帖子,但在报纸页面上不会显示任何帖子…
因此,问题很简单(我认为).如何在博客主页面以外的其他页面上显示帖子?
谢谢!
阿米特
解决方法:
而不是排除类别并排除页面并更改标准的wordpress循环,请使用一个新查询,如下所示:
<?PHP $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?PHP while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><a href="<?PHP the_permalink() ?>" title="<?PHP the_title(); ?>">
<?PHP the_title(); ?></a></h3>
<?PHP the_excerpt('Read the rest of this entry »'); ?>
<?PHP endwhile; ?>
可以在标准WP循环内使用它,并且可以在页面/帖子或页面模板中多次使用,而不会发生冲突. (启用PHP执行以在页面/帖子编辑器中使用它). @L_450_86@
这也可以很好地用于使用页面模板来创建带有博客文章的不同页面:Page Templates « WordPress Codex,但不要忘记,WP也使用类别页面,具体取决于您的主题:Category Templates « WordPress Codex.
以上是大佬教程为你收集整理的php-在两页上显示WordPress帖子全部内容,希望文章能够帮你解决php-在两页上显示WordPress帖子所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。