Grow your CSS skills. Land your dream job.

WordPress, using query post on "Template pages"?

  • # December 29, 2008 at 3:02 pm

    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:

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

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

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

    Then the standard (not styled yet)

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

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

    ” rel=”bookmark” title=”Permanent Link to < ?php the_title_attribute(); ?>“>
    < ?php the_title(); ?>

    < ?php the_time('F jS, Y') ?> < ?php the_author() ?>

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

    < ?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? ;)

    # December 29, 2008 at 9:21 pm

    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

    # December 30, 2008 at 4:41 am

    Thanks but if i add the:

    Code:
    < ?php the_content('Läs mer...'); ?>

    it still doesnt break of the content

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".