Support » Themes and Templates » Home Page Feature Blocks – How to make them dynamic?

  • Currently, I have the following code on my home page for 3 featured blocks (the IDs refer to individual pages):

    <div id="columns">
      <div class="html_blog">
        <div class="post-title">
          <h2><?php $pageID = 164; $page = get_post($pageID); echo $page->post_title; ?></h2>
        <?php if ( has_post_thumbnail(164) ) { echo "<div class=\"pic\"><a href=\"".get_permalink(164)."\">".get_the_post_thumbnail('164', $size, $attr )."</a></div>"; } ?>
        <div class="post-excerpt">
          <p><?php $pageID = 164; $page = get_post($pageID); echo $page->post_excerpt; ?></p>
          <p><a href="<?php echo get_permalink(164); ?>">Read More</a></p>
      <div class="html_blog">
        <div class="post-title">
          <h2><?php $pageID = 180; $page = get_post($pageID); echo $page->post_title; ?></h2>
        <?php if ( has_post_thumbnail(180) ) { echo "<div class=\"pic\"><a href=\"".get_permalink(180)."\">".get_the_post_thumbnail('180', $size, $attr )."</a></div>"; } ?>
        <div class="post-excerpt">
          <p><?php $pageID = 180; $page = get_post($pageID); echo $page->post_excerpt; ?></p>
          <p><a href="<?php echo get_permalink(180); ?>">Read More</a></p>
      <div class="html_blog">
        <div class="post-title">
          <h2><?php $pageID = 187; $page = get_post($pageID); echo $page->post_title; ?></h2>
        <?php if ( has_post_thumbnail(187) ) { echo "<div class=\"pic\"><a href=\"".get_permalink(187)."\">".get_the_post_thumbnail('187', $size, $attr )."</a></div>"; } ?>
        <div class="post-excerpt">
          <p><?php $pageID = 187; $page = get_post($pageID); echo $page->post_excerpt; ?></p>
          <p><a href="<?php echo get_permalink(187); ?>">Read More</a></p>
      <div class="clr"></div>

    I was curious if, instead of hard coding the page IDs in, would it be possible to have the blocks appear if I set a custom field? For example, creating a name of “featured” and the value being a 1, 2 or 3?

    If this is possible, my concern would be if the admin forgot to erase the custom field from the page when they add a new featured page in place of one of those blocks that 2 pages might appear in the same block so I was curious if just the latest page could be placed in the block. (Alternatively, is it easy to create a mechanism/pull down menu somewhere in the theme admin that allowed one to select what page should be featured in each block?)

Viewing 6 replies - 1 through 6 (of 6 total)
  • Bump

    I am interested in this as well. I know I should run a query post and extract the values from the custom fields. It’s the conditional syntax I’m not good at. Help?



    Forum Moderator

    Thanks esmi. I have 5 features on the homepage ( I want to be able to set any post as a feature by using custom fields. So, value=1 would be the feature far left, 2 is next to it, and so on. The title is a custom field. The image is a url in the custom field, and the content for the feature is the excerpt.

    So I am thinking I need to

    -get posts
    -order by custom field feature number
    -look for custom field title
    -look for custom field image url
    -look for excerpt.

    Am I on the right track or am I going about this all wrong? Thanks.

    This is what I have so far:

    $query = new WP_Query( array (
    	'meta_key' => 'feature',
    	'orderby' => 'meta_value_num',
    	'order' => 'ASC'
    // The Loop
    while ($query->have_posts()) : $query->the_post(); ?>
    <div id="feature1">
    	<div class="featureContent">
    		<h4 class="featureHeader"><a href="<?php the_permalink(); ?>"><?php echo get_post_meta($post->ID, 'header', true); ?> >></a></h4>
    		<a href="<?php the_permalink(); ?>"><img src="<?php echo get_post_meta($post->ID, 'thumbnail', true); ?>" border=0></a><br>
    		<?php echo get_post_meta($post->ID, 'blurb', true); ?>
    <?php endwhile; ?>

    This is working. But how do I include both posts AND pages in the query? Some features are pages, and some are posts. Currently only the posts are showing.

    Do I need to create a Custom Select Query to search both pages and posts for a custom field value? That’s what I understand from this page:

    Any help would be appreciated.



    Hi Im not good with code but if its explained to me i can try and grasp it, ok heres my problem.

    Im having problems with my images, on the home page of my site, there is a feature page made up from my theme wootheme: premiumnews.

    The images are appearing pixelated please check this out if you can, any feedback would be helpful. Im using a mac computer safari browser.


Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Home Page Feature Blocks – How to make them dynamic?’ is closed to new replies.