treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress, using query post on "Template pages"?

  • Hi!

    I want to show all posts in the "Nyheter" category in my Template Page, i´ve made the custom page by doing the standard Wordpress template identifier thingy:


    <?php
    /*
    Template Name: Nyheter
    */
    ?>


    Works great, then i´ve added the header and all Wordpress includes.
    Before the loop i´ve added the:


    <?php query_posts('category_name=Nyheter'); ?>


    Then the standard (not styled yet)


    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <div class=\"post\" id=\"post-<?php the_ID(); ?>\">
    <h2><a href=\"<?php the_permalink() ?>\" rel=\"bookmark\" title=\"Permanent Link to <?php the_title_attribute(); ?>\">
    <?php the_title(); ?></a></h2>
    <p><?php the_time('F jS, Y') ?> <?php the_author() ?></p>

    <?php the_content('Read more...'); ?>

    </div>

    <?php endwhile; ?>


    <?php endif; ?>


    This will include the posts, but the post as a whole, or rather: all the content shows up, it doesnt break with a "Read more" text as it should, i use the same query post, 100% the same code on the index file and on the index file it works great, but not in my custom page.

    Anyone that know what the problem is? ;)
  • I think because the index page is designed to have the read more link in it. a custom page is designed to show the entire post. You can use this code to display just the title of the post and it will make that title a link

    <?php $recent = new WP_Query("cat=14&showposts=0"); while($recent->have_posts()) : $recent->the_post();?>
    <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    <?php endwhile; ?>

    it works off of the category id. So you would have to change the category number. in this case above it's 14
  • Thanks but if i add the:
    <?php the_content('Läs mer...'); ?>
    it still doesnt break of the content