_OMEGA_
Member
Posted 3 months ago #
Hi all, I searched on the forum and unfortunately haven't found what I'm exactly looking for.
I would like to modify the single.php file to have a list of only the titles of a specific category (ID = 10) in a single wordpress page.
I'd like to create something like this:
_OMEGA_
Member
Posted 3 months ago #
I tried something like this, it prints the right category but 2 times each title:
<?php
foreach((get_the_category()) as $category)
{
$postcat= $category->cat_ID;
$catname =$category->cat_name;
}
?>
<?php $categories = get_categories("child_of=$postcat");
foreach ($categories as $cat)
{ ?>
<?php query_posts("cat=5&posts_per_page=-1"); ?>
<?php while (have_posts()) : the_post(); ?>
<ul>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?></a>
</li>
</ul>
<?php endwhile; ?>
<?php } ?>
instead of the fixed category id 5 in here:
<?php query_posts("cat=5&posts_per_page=-1"); ?>
possibly try:
<?php query_posts("cat=".$cat->term_id."&posts_per_page=-1"); ?>
_OMEGA_
Member
Posted 3 months ago #
Ok, but in this way it prints the titles of all the categories, instead I'm trying to have only the title of the category 5.
a list of only the titles of a specific category (ID = 10)
your code does not fit this description;
what exactly do you want to show?
_OMEGA_
Member
Posted 3 months ago #
I want to print on a page only and all the titles (of the posts) of the category 5.
_OMEGA_
Member
Posted 3 months ago #
Any hint? sorry for the bump...
do you have the page template part in place?
it might help if you could post a link to this page to illustrate what you have so far.
if you have problems there, please paste the full code of your page template into a http://pastebin.com/ and post the link to it here.
as the main code for the loop, this is all you should need:
<?php query_posts("cat=5&posts_per_page=-1"); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?></a>
</li>
<?php endwhile; wp_reset_query(); ?>
</ul>
_OMEGA_
Member
Posted 3 months ago #
Hey, thank you.
I copied and pasted your code and......it works like a charm. Thank you very much