View Single Post

  #4 (permalink)  
Old 17-08-2007, 08:38 PM
alexleonard alexleonard is offline
Frontpage User
Recent Blog: Irish Sailing Academy
 
Join Date: Aug 2007
Posts: 7
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
alexleonard is a jewel in the roughalexleonard is a jewel in the roughalexleonard is a jewel in the roughalexleonard is a jewel in the rough
Send a message via Skype™ to alexleonard
Default

I would suggest that you don't necessarily need the execphp plugin. It's handy, but I've found it to be buggy at times, and it can also clash with some of the XHTML correction from the TinyMCE plugin.

I would suggest that it might be worth making these kind of alterations within your theme. It gives you more control and you won't bash your head off the keyboard when things aren't working right.

On our website I have set the home page as a static page, therefore using the "page.php" file as per the template hierarchy used in Word Press.

I wanted to display our most recent portfolio item, and the method done to achieve this is the same as what you are looking for. Here's the code that I've dropped into my page.php template file and I'll break it down below.

Code:
<?php if (is_page('4')) { ?>
<h1 class="hright">Recent Work</h1>
<?php query_posts('cat=8&show_posts=1&posts_per_page=1'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post-wrap home-portfolio" id="post-<?php the_ID(); ?>">
    <h3 class="post-title"><?php the_title(); ?></h3>
        <div class="story-content">
        <?php the_content('Continue Reading &raquo;'); ?>
        <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
        </div><!-- end post content -->
</div><!-- end post -->
<?php endwhile; endif;  
} // end if is_page 4! ?>
So, as my page ID is "4", I have said if the page is page 4 show 1 post from category 8 (which is our portfolio category) after the beginning of "The Loop" we get the display of the_title and the_content.

In your case, you'll need to start the same if (is_page('x')), which you'll need to follow with 2 or 3 uses of the loop.

The first loop use will probably look like:
Code:
<?php query_posts('show_posts=1&posts_per_page=1'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content('Continue Reading &raquo;'); ?>
With the second loop looking like:

Code:
<?php query_posts('show_posts=5&posts_per_page=1'); ?>
 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_excerpt('Continue Reading &raquo;'); ?>
Now, I'm being a little rough here, but hopefully you catch my drift. Obviously the excerpt usage would need to exclude the most recent post as that is being reproduced in full. There are ways of doing this explained fully in the codex.

Comments can be a good laugh. I've found that the inbuilt word press comment fetching is a little basic for my HTML structural desires. I've been using the Get Recent Comments plugin to help with this.

Dropping the sidebar can be done easily as well using if statements.

To give a full picture, here's a condensed version of my page.php file:

Code:
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <div id="post-<?php the_ID(); ?>">
   <?php the_content(); ?>
  </div><!-- end post -->
<?php endwhile; else: ?>
 <h2 class="title"><?php _e('Not Found'); ?></h2>
 <p><?php _e("Sorry, but the page you're looking for couldn't be found. Double check your URL or you should try searching for it."); ?></p>
<?php endif; ?>

<?php if (is_page('4')) { ?>
<h1 class="hright">Recent Work</h1>
<?php query_posts('cat=8&show_posts=1&posts_per_page=1'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>">
   <h3 class="post-title"><?php the_title(); ?></h3>
    <?php the_content('Continue Reading &raquo;'); ?>
</div><!-- end post -->
<?php endwhile; endif;  
} // end if is_page 4! ?>

<!-- Begin Sidebar -->
<?php 
include(TEMPLATEPATH . '/sidebar-page.php'); 
?>

<?php get_footer(); ?>
Reply With Quote