WordPress.org

Ready to get started?Download WordPress

Forums

Titles list of a category in a page (10 posts)

  1. _OMEGA_
    Member
    Posted 2 years 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:

    • title 1
    • title 2
    • title 3
  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    consider creating a page template:

    http://codex.wordpress.org/Pages#Page_Templates

  3. _OMEGA_
    Member
    Posted 2 years 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 } ?>
  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    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"); ?>
  5. _OMEGA_
    Member
    Posted 2 years 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.

  6. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    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?

  7. _OMEGA_
    Member
    Posted 2 years ago #

    I want to print on a page only and all the titles (of the posts) of the category 5.

  8. _OMEGA_
    Member
    Posted 2 years ago #

    Any hint? sorry for the bump...

  9. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    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>
  10. _OMEGA_
    Member
    Posted 2 years ago #

    Hey, thank you.
    I copied and pasted your code and......it works like a charm. Thank you very much

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.