• Hi,

    I have the following on every page of my site:

    <?
    include('test.php');
    ?>

    And in ‘test.php’ I have:

    <li><?php query_posts('showposts=1&cat=1'); ?><?php while (have_posts()) : the_post(); ?><?php the_content_rss('', TRUE, '', 10); ?><?php endwhile;?>
    </li>

    It basically displays a snippet of news.
    However, this only seems to display the content when in ‘index.php’ or ‘archive.php’ nowhere else, why is this?

    Many thanks for any assistance.

Viewing 15 replies - 1 through 15 (of 18 total)
  • You will need to provide way more info than that…
    What is “every page”? Pages made in WP? Other template files? Files outside of WP?
    Don’t expect any help if you don’t provide proper information.

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    OK.
    The ‘every page’ bit wasn’t particularly essential info, the fact is it won’t work on ‘page.php’ which every WP page uses on my site and IT DOES work on ‘index.php’ and ‘archive.php’.
    Is there any reason for this?

    >> You will need to provide way more info than that…
    What else do you need?

    Probably, the simple fact that Pages are not meant to display posts…?

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    … ??

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    So there is no way around this, displaying posts on a page?

    Surely it has been done in the past?

    Anyone???

    Yes, it has been done. Is that test.php in the theme folder?
    If yes, you can try using this to include it:
    <?php include (TEMPLATEPATH . "/test.php"); ?>

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    It is included OK, I mean it displays all the other content of ‘test.php’ across the pages of my site, it just doesn’t like to show the snippet of the post ??
    So instead of: <? include('test.php'); ?>
    I should use : <?php include (TEMPLATEPATH . "/test.php"); ?> ?

    That’s the recommended include code for file located in the theme folder.
    However, if it displays the other code that is in the file, then there must be something else.
    Why do you need to include the Loop via a file instead of having it in every file – which means you can customize it for different views?

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Yes, there is something else, just a little HTML to make sure the ‘test.php’ file was ok, but the Loop wasn’t ??

    I’m a bit confused. Can I show a post in my ‘page.php’ pages?

    You can but why would you?
    Also, any normal page.php should have its own Loop already. Are you replacing it or adding another Loop?

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    >> You can but why would you?

    Because in every page on my site, I want to display 1 news item in the bottom left corner.

    I’m using the existing Loop in my ‘page.php’ I assume:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;
    '); ?>
    
    				<?php wp_link_pages(array('before' => '<strong>Pages:</strong> ', 'after' => '
    ', 'next_or_number' => 'number')); ?>
    
    		<?php endwhile; endif; ?>

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Would it make more sense if I just did an SQL Query direct to the WP database?

    I seem to be getting nowhere here.

    For what you want there is a plugin:
    https://guff.szub.net/2005/01/27/get-a-post/

    On a more general note: when you have 2 Loops not properly coded in the same template file they might “kill” each other. Read the Codex about using multiple Loops in the same template file. Yes, including it is considered the same file.

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    … brb

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    OK, got it *almost* working.

    Do you know how to select the most recent post from a specific category using this plug-in?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Displays post info on Home Page, but nowhere else :(’ is closed to new replies.