Wordpress 按类别显示除所选帖子外的所有帖子
我已经在主页上显示了“主页”类别的帖子。点击“阅读更多”第一篇文章。 它显示了第一篇文章的所有细节 现在我想用“Readmore”显示“first post”下面的所有帖子 这是我的代码,它显示了一些其他类别的帖子Wordpress 按类别显示除所选帖子外的所有帖子,wordpress,Wordpress,我已经在主页上显示了“主页”类别的帖子。点击“阅读更多”第一篇文章。 它显示了第一篇文章的所有细节 现在我想用“Readmore”显示“first post”下面的所有帖子 这是我的代码,它显示了一些其他类别的帖子 <?php $categories = get_the_category(); $catID = the_category_ID($echo=false); //Current selected category ID $catPost = get_posts('c
<?php
$categories = get_the_category();
$catID = the_category_ID($echo=false); //Current selected category ID
$catPost = get_posts('cat=$catID&posts_per_page=3');
foreach ($catPost as $post) : setup_postdata($post);
?>
<h1><a><?php the_title(); ?></a></h1>
<?php the_excerpt(); ?>
<p class="postinfo">Written by: <?php the_author_posts_link(); ?>
Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>
Categories: <?php the_category(', '); ?></p>
<hr />
<?php endforeach;?>
帖子页面
试试这个方法
<?php
global $post;
if(is_category() || is_single()){
foreach(get_the_category() as $category)
{
$current = $category->cat_ID;
$current_name = $category->cat_name;
//query_posts("cat=". $current);
$myposts = get_posts(array('category__in' => array($current)));
//$myposts = get_posts('numberposts=50&category='.$current);
//query_posts(array('category__in' => array(11)));
}
}
foreach($myposts as $post) :
setup_postdata($post);
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a>
</li>
<?php endforeach; ?>
试试这个方法
<?php
global $post;
if(is_category() || is_single()){
foreach(get_the_category() as $category)
{
$current = $category->cat_ID;
$current_name = $category->cat_name;
//query_posts("cat=". $current);
$myposts = get_posts(array('category__in' => array($current)));
//$myposts = get_posts('numberposts=50&category='.$current);
//query_posts(array('category__in' => array(11)));
}
}
foreach($myposts as $post) :
setup_postdata($post);
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a>
</li>
<?php endforeach; ?>
您的意思是按类别或当前类别显示所有帖子。否。只想显示所选类别的帖子。不是所有的分类都是的。当前类别的帖子如get_帖子('category_name=CATEGORYNAME&posts_per_page=5');或者使用wp_查询,比如$getpost=newwp_查询('category_name=my_second_category','posts_per_page'=>3);?>我如何动态地使用它?你的意思是按类别或当前类别显示所有帖子。否。只想显示所选类别的帖子。不是所有的分类都是的。当前类别的帖子如get_帖子('category_name=CATEGORYNAME&posts_per_page=5');或者使用wp_查询,比如$getpost=newwp_查询('category_name=my_second_category','posts_per_page'=>3);?>我如何动态地使用它?是的,这是我想要的,但是我想显示除所选帖子以外的所有帖子。我有4篇帖子。我选择了Post-2,想显示Post-1、Post-3和Post-4。您在Post参数中使用了'numberposts'吗?这个答案非常有用。如何显示除所选帖子以外的所有帖子。是的,这是我想要的,但我想显示除所选帖子以外的所有帖子。我有4篇帖子。我选择了Post-2,想显示Post-1、Post-3和Post-4。您在Post参数中使用了'numberposts'吗?这个答案非常有用。如何显示除所选帖子外的所有帖子。