WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to display two Pages using one Template? (3 posts)

  1. mwellsworth
    Member
    Posted 6 years ago #

    Hello everyone, this is my first post here. I've hunted through the template docs and this forum for an answer to my question but with no luck. I'm hoping one of you can help me out.

    So here is the problem. I'm trying to display two Pages (two different ID's), one on top of another, on one Page (with its own ID) using one Template file. I hope that makes sense. Let me try to explain further.

    When it is all said and done I would have a Page that would be organized like below:

    Header.php
    //In the header I have a list of links to all Pages. One of the Pages is called Portfolio.

    <div id="navmenu">
         <ul>
         <li><a title="BLOG" href="<?php echo get_settings('home'); ?>">BLOG</a></li>
         <li><a title="ABOUT" href="?page_id=2">ABOUT</a></li>
         <li><a title="ABOUT" href="?page_id=5">RESUME</a></li>
         <li><a title="ABOUT" href="?page_id=8">PORTFOLIO</a></li>
         </ul>
    </div>

    Portfolio.php
    //The content of the Page would then be displayed using the layout file portfolio.php which would display two or more Pages (once again, each with unique IDs created in admin) with divisions in between them.

    -> display Page ID 1
    
    -> image or division
    
    -> display Page ID 2

    Footer.php
    //And finally the footer completing the Page.

    I've been trying to modify my Page.php Template to make Portfolio.php, but be default it only displays the content from one Page. I don't know how to modify The Loop to display individual Page IDs.

    Here is what Portfolio.php looks like right now. It displays the same page ID twice with a division in between.

    <?php
    /*
    Template Name: Portfolio
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="content" class="narrowcolumn">
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<div class="post" id="post-<?php the_ID(); ?>">
    
    		<h2>
    
    			<?php the_title(); ?>
    
    		</h2>
    
    		<div class="entry">
    
    			<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    			<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    		</div>
    
    	</div>
    
    	<?php endwhile; endif; ?>
    
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    
    </div>
    
    <img src="wp-content/themes/default/images/segue.jpg" style="margin-top: 10px; margin-bottom: 10px" align="left" height="40" width="540" />
    
    <div id="content" class="narrowcolumn">
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<div class="post" id="post-<?php the_ID(); ?>">
    
    		<h2>
    
    			<?php the_title(); ?>
    
    		</h2>
    
    		<div class="entry">
    
    			<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    			<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    		</div>
    
    	</div>
    
    	<?php endwhile; endif; ?>
    
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    
    </div>
    
    <?php get_footer(); ?>
  2. mwellsworth
    Member
    Posted 6 years ago #

    Nevermind, I solved the problem by happening upon this snippet of code:

    <?php query_posts('pagename=insert name of Page here'); ?>

    This calls whatever Page you name into memory for The Loop to use. It works for the purpose I needed.

    Here is my updated code for portfolio if anyone else has this problem:

    <?php
    /*
    Template Name: Portfolio
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="content" class="narrowcolumn">
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<div class="post" id="post-<?php the_ID(); ?>">
    
    		<h2>
    
    			<?php the_title(); ?>
    
    		</h2>
    
    		<div class="entry">
    
    			<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    			<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    		</div>
    
    	</div>
    
    	<?php endwhile; endif; ?>
    
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    
    </div>
    
    <img src="wp-content/themes/default/images/segue.jpg" style="margin-top: 10px; margin-bottom: 10px" align="left" height="40" width="540" />
    
    <?php query_posts('pagename=sketching'); ?>
    
    <div id="content" class="narrowcolumn">
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>		
    
    	<div class="post" id="post-<?php the_ID(); ?>">
    
    		<h2>
    
    			<?php the_title(); ?>
    
    		</h2>
    
    		<div class="entry">
    
    			<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    			<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    		</div>
    
    	</div>
    
    	<?php endwhile; endif; ?>
    
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    
    </div>
    
    <?php get_footer(); ?>
  3. chankailoon
    Member
    Posted 6 years ago #

    can i make the pagename to detect the current loading page title?

Topic Closed

This topic has been closed to new replies.

About this Topic