• Resolved xboxer360com

    (@xboxer360com)


    Hi,

    I’m currently working on a site that will have 4 featured posts on the home page with a excerpt from the post and an image. I know how to use custom fields so I wont need the image code but I don’t know how to get the results I need.

    An example of that I’m after is here: https://www.vg247.com/ (See the top 3 images with a text overlay – I dont need the overlay though)

    I know it needs to be from 1 catergory.. Can anyone help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter xboxer360com

    (@xboxer360com)

    Ok I sussed how to do it but I’m having problems with my css…

    Basically all the featured boxes will only use 1 css style I need the boxes to use seperate css styles due to the spacing..

    Heres what I’m currently doing:

    <?php query_posts("showposts=4&category_name=Portfolio"); $i = 1; ?>
    
          	<?php while (have_posts()) : the_post(); ?>
    	<div class="featureportfolio">
    	<?php $values = get_post_custom_values("thumb");
    	if (isset($values[0])) { ?>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    	<img src="<?php $values = get_post_custom_values("thumb"); echo $values[0]; ?>" alt="<?php the_title(); ?>" class="left" width="200px" height="81px" style="border-bottom:9px solid #8bc200" /></a>
          <?php } ?>
    	<div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php the_title(); ?></a></div>
    
        	</div>
    
          <?php endwhile; ?>

    and my css `.featureportfolio {
    width:200px;
    height:214px;
    float:left;
    border-bottom:9px solid #8bc200;
    margin-top:20px;
    }`

    Basically I need my first 3 boxes to have margin-right:20px; and the last box not to use any margin-right.

    Is there anyway I can get the php to add the number of the post to the end of the class? ie <div class="featureportfolio1"> so it knows that <div class="featureportfolio4"> doesnt have a margin right?

    Most easy way not the best way.
    Replace
    <div class="featureportfolio">
    with
    <div class="featureportfolio<?php echo $i++;?>">

    Thread Starter xboxer360com

    (@xboxer360com)

    That worked perfectly! thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘4 Featured posts on home page with images’ is closed to new replies.