WordPress.org

Ready to get started?Download WordPress

Forums

The Loop, Front page, Pages and excerpts (5 posts)

  1. datakid
    Member
    Posted 1 year ago #

    Hi,

    I've got a child theme in which I want to have three specific and static pages (or at least their excerpts and featured images) as part of the front page.

    I have a frontpage.php, and it's set as the static front page in the site's settings. All good so far.

    The problem comes when I switch permalink structures and/or when I switch from dev on localhost (Ubuntu 12.04.1) to dev on hosted solution (no idea what it's running, but mostly via cPanel/ftp)

    <?php $args=array('order' =>'asc','post_type' =>'page','post__in' => array(6,8,10), );
    	$page_query = new WP_Query($args); ?>
    	<?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    		<div class="section">
    			<?php if ($page_id==6) { ?> <div id="front-box-left">
    			<?php } elseif ($page_id==8) { ?> <div id="front-box-center">
    			<?php }	else { ?> <div id="front-box-right">
    			<?php } ?>
    			<?php the_post_thumbnail() ?>
    			<h2><a href="<?php the_permalink();?>" id="front-box-header"><?php the_title();?></a></h2>
    			<span id="front-box-text"><?php the_excerpt();?></span>
    			</div>
    		</div>
    
    <?php endwhile; ?>

    But for some reason I'm not getting any css id love: all three page excerpts are coming up <div id="front-box-right">

    This is annoying. The are otherwise rendering correctly, but in the wrong order?

  2. datakid
    Member
    Posted 1 year ago #

    Sorry, I should add that I have just now discovered that it was also a problem on the local dev machine - for some reason I got lucky on the post ordering and didn't see that the bug was there.

    Also, now that I think clearly (it's hard over here in Kiribati ok!) it's got nothing to do with permalinks either (since even permalinked pages still have a $page_id) - the problem is that I'm a shit php coder and have missed something obvious or simple.

    Sorry for the misdirect.

  3. datakid
    Member
    Posted 1 year ago #

    Ok, I've just discovered is_page() and I've also just discovered that it's not working for me :(

    <?php $args=array('order' =>'asc','post_type' =>'page','post__in' => array(6,8,10), );	$page_query = new WP_Query($args); ?>
    
    		<?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    		<div class="section">
    					<?php if ( is_page('6') ) { echo "BING" ?> <div id="front-box-left">
    					<?php } elseif ( is_page('8') ) { ?> <div id="front-box-center">
    					<?php }	else { ?> <div id="front-box-right">
    					<?php } the_post_thumbnail() ?>
    					<h2><a href="<?php the_permalink();?>" id="front-box-header"><?php the_title();?></a></h2>
    					<span id="front-box-text"><?php the_excerpt();?></span>
    					</div> <!-- #left-center-right css id -->
    			</div> <!-- #section -->
    
    		<?php endwhile; ?>
  4. datakid
    Member
    Posted 1 year ago #

    OH! Is it failing because the frontpage is not page 6? Should I be asking it to test if the post within the while loop is page 6...

  5. datakid
    Member
    Posted 1 year ago #

    OK!, I finally got it working using this hack around:

    <div id="content" role="main">
    		<img src="http://192.168.0.250/kit.edu.ki/wp-content/uploads/2012/10/KIT_web_image2.jpg" width="769" height="472">
    
    		<?php $args=array('order' =>'asc','post_type' =>'page','post__in' => array(6,8,10), );	$page_query = new WP_Query($args); ?>
    
    		<?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    		<div class="section">
    					<?php if ( get_the_ID()==6 ) { ?> <div id="front-box-left">
    					<?php } elseif ( get_the_ID()==8 ) { ?> <div id="front-box-center">
    					<?php }	else { ?> <div id="front-box-right">
    					<?php } the_post_thumbnail() ?>
    					<h2><a href="<?php the_permalink();?>" id="front-box-header"><?php the_title();?></a></h2>
    					<span id="front-box-text"><?php the_excerpt();?></span>
    					</div> <!-- #left-center-right css id -->
    			</div> <!-- #section -->
    
    		<?php endwhile; ?>
    
    	</div><!-- #content -->

    I tried with the_ID() but that didn't work either - but get_the_ID does, and that's sufficient

Topic Closed

This topic has been closed to new replies.

About this Topic