• jessi-ray

    (@jessi-ray)


    Hello there!

    I am trying to use WordPress as a content management system. So I’m looking for a way to display recent updates (from my update category) on a static homepage. I’ve seen some codes on here that are suppsoed to do this, however I’m not sure how they work. Basically, they tell you to call the category with php and then insert your post loop in between them. Like this:


    <?php $my_query = "showposts=3&cat=5"; $my_query = new WP_Query($my_query); ?>
    <?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>

    <div class="post">
    <h2> " title="<?php the_title(); ?>"> <?php the_title(); ?> </h2>

    </div>

    <div class="entry">

    <?php the_content(); ?>
    <p class="postmetadata">

    <?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?>
    <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>

    </p>
    </div>

    <?php endwhile; // end of one post ?>
    <?php endif; //end of loop ?>
    </p>

    Well all I'm getting is a display of a piece of PHP code and my title header images repeated twice! I am doing this by editing the page I set as the home page in the wordpress dash bored. Am I supposed to edit my index instead? Page file? Basically either I'm doing something wrong or I'm using the wrong code. D:

    If someone could answer my questions I'd be very grateful! Also, if you need to see my skin or something I'll provide that if you absolutely need it. I'm trying to keep the whole site secret until I finish everything.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • csleh

    (@csleh)

    The title, if it’s a link, should look like this:
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>

    otherwise like this:
    <h2><?php the_title(); ?></h2>

    You should be editing the template used for the Page.

    I don’t write php, but try this:

    <?php $my_query = new WP_Query('cat=5&showposts=3'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <div class="post"><h2><?php the_title(); ?></h2></div>
     <div class="entry">
    <?php the_content(); ?>
    <p class="postmetadata">
    <?php _e('Filed under:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php the_author(); ?>
    <?php comments_popup_link('No Comments ?', '1 Comment ?', '% Comments ?'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
    </p>
    </div>
    <?php endwhile; ?>

    which looks a bit different than the beginning of the bit pasted in the original post. You’ve also got an extra end </p> tag at the end.

    I have tried a number of solutions for this issue but yours is the first one that I have got to work. Apart from one thing. The entry on the static home page doesn’t recognise the <!–more–> break in the text, and therefore displays the complete text. On the Blog home page it works fine.

    Any ideas?

    Thread Starter jessi-ray

    (@jessi-ray)

    Well I’ve gotten it to work, and it does quite well actually!

    I just have one more question…. anyway I can get a link to the single post to display for comments? Also I need post pagination but I can’t seem to get that either. =/

    https://splatterheart.net/

    There’s my site… My loop is going something like this now:


    <?php $my_query = new WP_Query('cat=1&showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p class="post"><h2><?php the_title(); ?></h2></p>
    <div class="entry">
    <div class="innerpost"><p>
    <?php the_content(); ?>

    <?php _e('Filed under:'); ?> <?php the_category(', ') ?> on <?php the_time('F jS, Y') ?> <?php _e('by'); ?> <?php the_author(); ?>
    <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>

    It’s pretty much the same on all of the pages, save for the category numbers.

    I think the main question has already been answered, but in case anyone else is looking for a way to put posts on a static page without editing template files, this plugin will do it with a simple shortcode in your page’s content. For example …

    [get_posts category_name="whatever category"]

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Displaying Blog Post on a Static Page?’ is closed to new replies.