admin管理员组文章数量:1130349
I am looking to create a behavior as shown in the following link:
/
Here all posts from the same category are being displayed. Currently, it is handwritten HTML code, I want to mimic this behavior using PHP code in my single.php.
Following is the code I have written so far
<?php
$category = get_the_category();
<ul>
query_posts('cat='.$category);
if ( have_posts() ) : while ( have_posts() ) : the_post();
<li><a href="get_permalink( $id );">the_title();</a></li>
endwhile; endif;
</ul>
<br/>
?>
Can someone help in making it work?
I am looking to create a behavior as shown in the following link:
http://www.javaexperience/java-role-of-serialversionuid-in-serialization/
Here all posts from the same category are being displayed. Currently, it is handwritten HTML code, I want to mimic this behavior using PHP code in my single.php.
Following is the code I have written so far
<?php
$category = get_the_category();
<ul>
query_posts('cat='.$category);
if ( have_posts() ) : while ( have_posts() ) : the_post();
<li><a href="get_permalink( $id );">the_title();</a></li>
endwhile; endif;
</ul>
<br/>
?>
Can someone help in making it work?
Share Improve this question edited May 18, 2013 at 17:00 fuxia♦ 107k39 gold badges255 silver badges461 bronze badges asked Oct 27, 2012 at 6:39 SandeepSandeep 1771 gold badge1 silver badge6 bronze badges2 Answers
Reset to default 3Try this:
$cat = get_query_var('cat');
$PozCat = get_category ($cat);
$PozCat->id // give to us current cat id.
Then use this hook in your query:
<ul>
<?php
$cat = get_query_var('cat');
$PozCat = get_category ($cat);
//$PozCat->id
query_posts('posts_per_page=-1&cat='.$PozCat->id);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>
You can do this using Wp_query() by passing the category name as an argument:
<?php $my_query = new WP_Query('category_name=mycategory&showposts=-1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>
I am looking to create a behavior as shown in the following link:
/
Here all posts from the same category are being displayed. Currently, it is handwritten HTML code, I want to mimic this behavior using PHP code in my single.php.
Following is the code I have written so far
<?php
$category = get_the_category();
<ul>
query_posts('cat='.$category);
if ( have_posts() ) : while ( have_posts() ) : the_post();
<li><a href="get_permalink( $id );">the_title();</a></li>
endwhile; endif;
</ul>
<br/>
?>
Can someone help in making it work?
I am looking to create a behavior as shown in the following link:
http://www.javaexperience/java-role-of-serialversionuid-in-serialization/
Here all posts from the same category are being displayed. Currently, it is handwritten HTML code, I want to mimic this behavior using PHP code in my single.php.
Following is the code I have written so far
<?php
$category = get_the_category();
<ul>
query_posts('cat='.$category);
if ( have_posts() ) : while ( have_posts() ) : the_post();
<li><a href="get_permalink( $id );">the_title();</a></li>
endwhile; endif;
</ul>
<br/>
?>
Can someone help in making it work?
Share Improve this question edited May 18, 2013 at 17:00 fuxia♦ 107k39 gold badges255 silver badges461 bronze badges asked Oct 27, 2012 at 6:39 SandeepSandeep 1771 gold badge1 silver badge6 bronze badges2 Answers
Reset to default 3Try this:
$cat = get_query_var('cat');
$PozCat = get_category ($cat);
$PozCat->id // give to us current cat id.
Then use this hook in your query:
<ul>
<?php
$cat = get_query_var('cat');
$PozCat = get_category ($cat);
//$PozCat->id
query_posts('posts_per_page=-1&cat='.$PozCat->id);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>
You can do this using Wp_query() by passing the category name as an argument:
<?php $my_query = new WP_Query('category_name=mycategory&showposts=-1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>
本文标签: phpDisplay all posts in current category
版权声明:本文标题:php - Display all posts in current category 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749026530a2305193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论