WordPress.org

Forums

Displaying posts on other parts of site (8 posts)

  1. Microdot
    Member
    Posted 9 years ago #

    Hi there,

    Fairly new to this stuff but loving every minute of WP.

    Is it possible to display certain posts on other parts of my site? For example, if WP is here: mysite.com/blog/wordpress/ is it possible to display posts from a certain catagory on the front page here: mysite.com/index.php

    Many thanks for your help,

  2. Michael Bishop

    Posted 9 years ago #

    Short answer, yes.
    Long answer, include this in your header on your index.php at the root install.
    <?php
    require('/pathtoyourwordpressinstall/wp-blog-header.php');
    ?>

    You then should be able then to include the loop within that page.

  3. Microdot
    Member
    Posted 9 years ago #

    Many thanks for your help, although I have no knowledge of PHP (plenty of HTML though) -

    I include the:
    <?php
    require('/pathtoyourwordpressinstall/wp-blog-header.php');
    ?>

    On.. for example /myblog/wordpress/index.php - is that correct?

    And also, how do I create a loop, and where do I place it?

    Thanks again for your help,

  4. cron
    Member
    Posted 9 years ago #

    You just include the <?php
    require('/pathtoyourwordpressinstall/wp-blog-header.php');
    ?> in the <head> of the page that you want the posts to apear on. Next, as milkb said you need to call the posts from the loop. All you will ever need to know about the loop can be found here:

    http://codex.wordpress.org/The_Loop

    Cron

  5. Microdot
    Member
    Posted 9 years ago #

    Fantastic!

    I've tried it out, even customized parts and it's working great.

    Thank you very much, to both of you, for your help.

  6. Microdot
    Member
    Posted 9 years ago #

    Oops sorry about this. Trying to change the catagory using the following code, but it displays all the latest posts.. how is this code looking to you? Again, thank you for your help.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( in_category('11') ) { ?>
    <div class="post-cat-eleven">
    <?php } else { ?>
    <div class="post">
    <?php } ?>
    <h2>"><?php the_title(); ?></h2>
    <small><?php the_time('F jS, Y'); ?></small>
    <div class="entry">
    <?php the_content(); ?>
    </div>
    <p class="postmetadata">Posted in <?php the_category(', '); ?>
    </div>
    <?php endwhile; else: ?>
    Sorry, no posts.
    <?php endif; ?>

    I should also point out that I'm using the /%postname% permalink structure, I'm not sure if this has anything to do with the problem? Many thanks,

  7. moshu
    Member
    Posted 9 years ago #

    I guess it's wrong code.
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( in_category('11') ) { ?>
    <div class="post-cat-eleven"> <=== if 11, do what?
    <?php } else { ?>... etc.

    You need to put there what to do if is cat 11. Use the template tags (title, content etc. that you want to be shown there.

  8. Microdot
    Member
    Posted 9 years ago #

    Thank you so much for your help!

Topic Closed

This topic has been closed to new replies.

About this Topic