WordPress.org

Ready to get started?Download WordPress

Forums

How do I use `the_content` and The Loop tags on sub pages? (9 posts)

  1. fredrik
    Member
    Posted 9 years ago #

    I've got a problem that I think has a very simple solution.

    I run "The Loop" twice on my blog. Once in index.php for the main feed and once in sidebar.php to publish shorter content from a special category. Look here to see what I mean: http://www.apt47.com/dev_blog/

    It work fine on the front page. But when I go into the archives - ie clicking on a permalink, commentlink or coming from another site the content output from The Loop and the tag the_contentwon't show up in sidebar.php. Like this: http://www.apt47.com/dev_blog/2005/05/15/bierut-on-bullshit/

    Any ideas on how i could change so that The Loop finds all the post even on sub pages?

  2. Kafkaesqui

    Posted 9 years ago #

    What are you doing to initiate the sidebar loop? I assume you're not just setting up a "default" post loop.

    If you haven't looked it over, I'd suggest checking out the custom loop examples found in the Codex page covering The Loop, mainly the last one displayed for "Multiple Loops Version 1" :

    http://codex.wordpress.org/The_Loop#Multiple_Loops_Version_1

  3. fredrik
    Member
    Posted 9 years ago #

    I was playing around with those but can't get it to work. This is the code that I'm using for the loop in sidebar.php

    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    <?php if ( (in_category('3')) ) { ?> <?php //Check if post is in Oddities category ?>

    <li><?php echo $post->post_content; ?></li>
    <?php } ?> <?php // ## Check if post is in Oddities category Ends ## ?>
    <?php endforeach; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

  4. Kafkaesqui

    Posted 9 years ago #

    Try this:

    <?php $my_query = new WP_Query('cat=3&showposts=10'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li><?php echo $post->post_content; ?></li>
    <?php endwhile; ?>

    Adjust the showposts value, depending on how many you want to display.

  5. fredrik
    Member
    Posted 9 years ago #

    Heh, that works like a dream. And, it's much simpler than what I had done :) Thanks. That's the second time today!

    /F

  6. bacon
    Member
    Posted 9 years ago #

    I don't mean to hijack this thread, but since it's resolved and my problem is very similar so I thought I'd just throw my question in here. I'm using the same code above to selectively insert a # of posts from a certain category. I created a page which I want to function as the index, where I can selectively post the "best of" stuff, and then also have a most recent entries. The problem is, entries display in full, where I want them to have a "Read the rest of this entry." I've looked the_loop and the_content codex stuff with no luck, I can't get the page to realize it's a multipost page (I think thats what the problem is). Check out http://www.burningvillage.com/home for the broken page and http://www.burningvillage.com for the index that properly cuts posts at <!--more-->.

    Here's some details:
    page.php code :
    <?php if ($_GET[’pagename’] = ‘home’) { ?>
    <h2>Our Hottest Content (a good place to start)</h2>
    <?php $hot_query = new WP_Query('cat=8&showposts=4'); ?>
    <?php while ($hot_query->have_posts()) : $hot_query->the_post(); ?>
    <div class="homepost">
    <h2 id="post-<?php the_ID(); ?>">" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>
    <div class="entrytext">
    <?php the_content('Read the rest of this entry »'); ?>
    </div>
    </div>
    <?php endwhile;?>
    <?php } else { ?>
    ... Thanks for your help!

  7. bacon
    Member
    Posted 9 years ago #

    *bump*

  8. moshu
    Member
    Posted 9 years ago #

    Hmmm. I am not a big expert on this, but with some help offered around here I managed something like you want to do just by having a home.php template in the theme. That will take precedence over the index, and I use a similar code BUT without any of those
    <?php if ($_GET[’pagename’] = ‘home’) { ?>...
    just using a code very similar to what Kafkaesquí gave above. (Actually he was the one who helped me out :)
    So now when I go to mysite.com/blog it is the home.php that is showing up (and I don't have to have /blog/home )
    Maybe I misunderstand what you want, but I thought to share this anyway.

  9. atow
    Member
    Posted 8 years ago #

    This is a response to bacon's question. I have a separate blog page for my site, and I solved this by adding the following in my page template:

    <?php
    global $more;

    $more = 0;
    ?>

    Within the get_the_content routine is a check to see if the entire post content should be displayed ($more = 1) or just the portion up to the <!--more--> tag ($more = 0). The $more global is set early on in the Loop in the setup_postdata function.

    You may want to store the current value of $more and then reset it after you've run through your custom Loop. That way any other plugin/WP code that checks the variable will work properly.

Topic Closed

This topic has been closed to new replies.

About this Topic