Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Nevermind the trailing slash, lol =P
    Well, then that is really strange… As you have your blog installed in your own server, maybe the problem is due to some configuration of your php? Or have you made any modifications to the original installation/theme since you have installed wordpress?

    First, try going to options>general in your admin panel and check if your Blog Address is set to https://127.0.0.1/wordpress/. If it is set to https://127.0.0.1/wordpress/bla, your page will display if you write https://127.0.0.1/wordpress/bla/?page_id=2

    Then, make sure that the index.php in your template page includes The Loop. Something like:

    <?php while (have_posts()) : the_post(); ?>
    <?php the_title(); ?>
    <?php the_excerpt() ?>
    <?php endwhile; ?>

    And if you have a page.php and category.php, make sure that they include The Loop too.

    The Loop
    Template Hierarchy

    Thread Starter ClaudiaM

    (@claudiam)

    Lol… I had read that before, but I forgot to try it because I thought I couldn’t use multiple query_posts tags. But anyway, I’ve tried and it worked! Thanks a lot! ??

    So, this is what I did to show the latest entry of each category on the index page (it will work if you do it in the normal Pages too):

    First, as the categories were 4 and I wanted the posts to be displayed differently (for example, three of the categories were inside a table and the other one not), I have inserted one loop for each of them. For example, to show category 1 I wrote:

    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category(1) ) { ?> // make it show only posts from the category nr. 1
    <?php the_title(); ?>
    <?php the_excerpt() ?>
    <?php } else {
    }; ?>
    <?php endwhile; ?>

    To make each of the loops display only one post, I added <?php query_posts('cat=CATID&showposts=1'); ?> before each of them. CATID is to be replaced by the id of the category. So, my end result was something like this:

    <!-- category 1 -->
    <?php query_posts('cat=1&showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category(1) ) { ?> // make it show only posts from the category nr. 1
    <?php the_title(); ?>
    <?php the_excerpt() ?>
    <?php } else {
    }; ?>
    <?php endwhile; ?>
    <!-- category 2 -->
    <?php query_posts('cat=2&showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category(2) ) { ?> // make it show only posts from the category nr. 1
    <?php the_title(); ?>
    <?php the_excerpt() ?>
    <?php } else {
    }; ?>
    <?php endwhile; ?>
    <!-- category 3 -->
    <?php query_posts('cat=3&showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category(3) ) { ?> // make it show only posts from the category nr. 1
    <?php the_title(); ?>
    <?php the_excerpt() ?>
    <?php } else {
    }; ?>
    <?php endwhile; ?>
    <!-- category 4 -->
    <?php query_posts('cat=4&showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category(4) ) { ?> // make it show only posts from the category nr. 1
    <?php the_title(); ?>
    <?php the_excerpt() ?>
    <?php } else {
    }; ?>
    <?php endwhile; ?>

    If one of the categories has child categories that you want to include in the loop, the query strings remain the same (as they include the child categories too) but you have to add the numbers of these categories to the in_category condition. For example, if the categories 10 and 11 were sub-categories of 4:

    if ( in_category(4) || in_category(10) || in_category(11) )

    Well, that’s it!

    Thread Starter ClaudiaM

    (@claudiam)

    I think I couldn’t use that because there are other html elements between each post, and I can’t put them inside The Loop… and I’m not handy enough in php to create my own tweak. But thank you, anyway!

    As for the other code, I added it where you told, but it didn’t affect anything on the page. The latest update is still a blank space and I have two posts from the category ‘stock’, when there was supposed to be only one.

    Anyway, I was thinking of something simple, like a query you can add to the beggining of the loop, like:

    <?php while ($onepost->have_posts()) : $onepost->the_post(); ?>

    And then define a custom query that would make it display only one post, like:

    $onepost = new WP_Query('showposts=1');

    But this doesn’t work either =P

    Thread Starter ClaudiaM

    (@claudiam)

    I’ve tried it now, but it didn’t work ??

Viewing 5 replies - 1 through 5 (of 5 total)