Support » Fixing WordPress » Have "posts" only appear on a specific "page"

  • Hello all,

    I’m currently programming an entirely WordPress powered site. WordPress will be the CMS for every page on the site. However the client wants a blog on one specific page (not the home page). How do I program this functionality into WordPress?

    I currently have an “If page_id variable = XX, post the loop” but it’s only pulling the PAGE content, not my posts.

    The logic I have is:

    <?php
    
    $page = $_GET['page_id'];
    
    if($page == '18'){
    
    		<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    
    				<h2 class="post_title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    				<div class="post_content"><?php the_content();?></div>
    
    			</div>
    
    			<?php endwhile; ?>
    
    			<?php endif; ?>
    		</div>
    
    }

    But this is outputting the content of the PAGE, not the list of posts. Can anyone tell me how to achieve this functionality?

Viewing 13 replies - 1 through 13 (of 13 total)
  • You can assign a blog page in Admin->Settings->Reading

    Set ‘Front page displays:’ to ‘A static page’. Assign a page with your front page template as the ‘Front page’. Assign a blank page as the ‘Posts page’ for the Blog.

    See the Codex Creating a Static Front Page for more detail.

    Thread Starter thebrandon

    (@thebrandon)

    When I do what you said, I get this error:

    Safari can’t open the page.
    Too many redirects occurred trying to open “http://localhost/wp_debug/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.

    Is the error on your Blog page, or the Front page. I think it must be on the front page. Please put the template for the front page in a pastebin and post a link to it here.

    Thread Starter thebrandon

    (@thebrandon)

    Header.php:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="generator" content="Revive Media Services" />
    <meta name="keywords" content="northwest florida construction, homes, houses, destin, fl, company, build, custom, blog"/>
    <meta name="description" content="Blog page of Chi-Mar Construction, a Northwest Florida construction company specializing in custom built homes."/>
    <title>Sowell Tractor Co. | </title>
    <link href="css/reset.css" rel="stylesheet" type="text/css" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="shadowbox.css">
    <link rel="stylesheet" href="nivo-slider.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/reset.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    <!--[if IE]> <link href="<?php bloginfo('template_url'); ?>/ie_only.css" rel="stylesheet" type="text/css"> <![endif]-->
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    </head>
    <body>
    
    	<div id="container">
    
    		<div id="top">
    			<a href="index.php"><img src="<?php bloginfo('template_url'); ?>/img/top.png"/></a>
    		</div>
    
    		<div id="content_container">
    
    			<div id="menu_bar">
    			<ul>
    				<?php
    				//dump all of the page data into the $pages array
    				$pages = get_pages('sort_column=menu_order');
    
    				foreach ($pages as $pages_array) {
    					$link = '<li><a href="'.get_page_link($pages_array->ID).'" title="'.$pages_array->post_title.'">';
    					$link .= $pages_array->post_title;
    					$link .= '</a></li>';
    					echo $link;
    				}
    				?>
    			</ul>
    			</div>
    
    			<div class="clear"></div>

    Index.php:

    <!--Get WordPress Header (header.php)-->
    	<?php get_header(); ?>
    
    		<?php $p = $_GET['page_id']; ?>
    
    		<?php if(empty($p)){ ?>
    
    			<div id="welcome_bubble">
    				<h2>Welcome!</h2>
    				<p>Welcome to Sowell Tractor Co Inc. Locally owned and operated...  A golden rule dealer since 1974</p>
    			</div>
    
    			<div id="inventory_bg">
    
    				<div id="inventory_buttons">
    					<ul>
    						<li><a href="#"><img src="<?php bloginfo('template_url'); ?>/img/new_inventory.jpg" alt="new inventory"/></a></li>
    						<li><a href="#"><img src="<?php bloginfo('template_url'); ?>/img/used_inventory.jpg" alt="used inventory"/></a></li>
    					</ul>
    				</div>
    
    			</div>
    
    			<div id="two_col">
    
    				<div id="two_col_left">
    					<p><strong>Sowell Tractor Company</strong> is located in Panama City, Florida. We are a full line dealer for the Kubota line of utility wheel tractors and implements, diesel ATV utility work and play vehicles, lawn, garden, turf maintenance and construction machinery as well as full line Stihl hand held power products and full line Snapper lawn, garden, turf maintenance and ATV type vehicles. We also carry in stock other various "short line" goods such as specialty implements, accessories and attachments, emergency power generators, utility and equipment trailers as well as all other items and or units relating to our industry and the products we sell. Prompt special order availability on most any item needed that we do not have in stock. We provide full parts, repair and warranty, service plus pick up and delivery as needed on all product lines carried in stock.</p>
    				</div>
    
    				<div id="two_col_right">
    					<img src="<?php bloginfo('template_url'); ?>/img/tractor.jpg" alt="tractor"/>
    				</div>
    
    			</div>
    
    			<div class="clear"></div>
    
    		</div>
    
    		<?php }else{ ?>
    
    		<div id="post_container">
    
    		<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    
    				<h2 class="post_title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    				<div class="post_content"><?php the_content();?></div>
    
    			</div>
    
    			<?php endwhile; ?>
    
    			<?php endif; ?>
    		</div>
    
    		</div>
    
    	<?php } ?>
    
    	<div class="clear"></div>
    
    <?php get_footer(); ?>

    If you post large chunks of code here, the moderators will delete it per the forum rules. In the future, use the pastebin.

    Thread Starter thebrandon

    (@thebrandon)

    Will do. Sorry about that. I’m used to the code tags having a height.

    I can’t be sure, but it looks like you are trying to combine what should be a template for the static front page with the normal index.php template.

    Try making a template named frontpage.php using the code from the if(empty($p)) test, as below (I can’t be sure how many ending divs are needed!):

    <?php
    /*
    Template Name: Front Page
    */
    ?>
    
    <!--Get WordPress Header (header.php)-->
    	<?php get_header(); ?>
    
    			<div id="welcome_bubble">
    				<h2>Welcome!</h2>
    				<p>Welcome to Sowell Tractor Co Inc. Locally owned and operated...  A golden rule dealer since 1974</p>
    			</div>
    
    			// Rest of code from first if (empty($p))
    
    	<div class="clear"></div>
    
    <?php get_footer(); ?>

    Assign that as the template for the front page and see if that page works. If so, modify index.php by taking out the test for the empty $p.

    Thread Starter thebrandon

    (@thebrandon)

    I set the index to what you posted. Still gives the same error:

    Safari can’t open the page.
    Too many redirects occurred trying to open “http://localhost/wp_debug/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.

    The “Reading” settings say:
    Front page displays a Static Page. Front page: Home, Posts page: blog

    I’m sorry, I don’t know why it is trying to open wp_debug.

    You might have better luck if you start a new thread with the title ‘Too many redirects trying to open wp_debug’.

    Thread Starter thebrandon

    (@thebrandon)

    wp_debug is the name of the folder I have it in. That’s just my wordpress debug folder on my server.

    Have you tried switching to a different theme or disabling all plugins?

    Thread Starter thebrandon

    (@thebrandon)

    Yes. Even using the default WP theme it happens.

    When you tried the default theme, did you copy any of your code into the default theme folder, or is the theme ‘clean’?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Have "posts" only appear on a specific "page"’ is closed to new replies.