• Resolved Marijn

    (@marijn-bent)


    Hello everybody,

    I work at the following project:
    https://cl.ly/image/1e1X271T0k3P

    I want the three most recent post all in different div’s. How can I do this? The first one is easy:

    <div id="firstfield">
    <ul>
    <?php
    global $post;
    $args = array( 'numberposts' => 1, 'offset'=> 1 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<li><?php $excerpt = get_the_excerpt( $deprecated ) ?></li>
    <?php endforeach; ?>
    </ul>

    Right?

    Regards,
    Marijn

Viewing 10 replies - 16 through 25 (of 25 total)
  • Thread Starter Marijn

    (@marijn-bent)

    Yeaah! It works now! Both of you thanks for the great help!

    esmi

    (@esmi)

    Glad we all managed to get there in the end. ??

    Thread Starter Marijn

    (@marijn-bent)

    Just a couple of last questions :-);
    The excerpt won’t show up. There is a empty line under the permalink. Is there a little fix for that?
    Further, the most important one, which styles can I use to style the box around it? The post-id will change if you have a new post. Can’t I use post_on_page1 or something to style it :)?

    Thanks!

    esmi

    (@esmi)

    The excerpt won’t show up.

    Change <li><?php $excerpt = get_the_excerpt( $deprecated ) ?></li> to <li><?php the_excerpt();?></li>

    Can’t I use post_on_page1 or something to style it :)?

    <?php query_posts( $query_string . '&posts_per_page=3' );
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div <?php post_class();?> id="post-<?php the_ID();?>">

    to:

    <?php query_posts( $query_string . '&posts_per_page=3' );
    $c = 0;
    if (have_posts()) : while (have_posts()) : the_post();
    $c++;
    $class = ' post-num-' . $c;?>
    <div <?php post_class( $class );?> id="post-<?php the_ID();?>">

    That should add ‘post-num-1`, ‘post-num-2’ etc to the classes on the enclosing div.

    Thread Starter Marijn

    (@marijn-bent)

    Thanks, works exactly how you describe. But how can I style it now like this image:
    https://cl.ly/image/1e1X271T0k3P?

    I thought that I, if the code above describe how many post I want and how I mention them, the following code display the post so I could place them were I want.

    <div class="post-num-1">
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<ul>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<li><?php the_excerpt();?></li>
    	</ul>
    </div>
    
    <div class="post-num-2">
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<ul>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<li><?php the_excerpt();?></li>
    	</ul>
    </div>
    
    <div class="post-num-3">
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<ul>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	<li><?php the_excerpt();?></li>
    	</ul>
    </div>

    Or have you an other solution?

    esmi

    (@esmi)

    You cam still place each posts where you want it using CSS – .post-num-1 etc

    Thread Starter Marijn

    (@marijn-bent)

    I tried it, but i get the following problem:

    .post-num-1 {
    	background-color: #FFF;
    	float:left;
    	width: 65%;
    	margin-left:40px;
    }
    
    .post-num-2 {
    	background-color: #FFF;
    	width: 40%;
    	float: left;
    }
    
    .post-num-3 {
    	background-color: #FFF;
    	width: 40%;
    	float:left;
    }
    
    .staticcustomfield {
    	width:25%;
    	height:50px;
    	background:#FFF;
    	float:right;
    }

    Basic CSS to have all the elements on the right place. What I get:
    https://cl.ly/image/2M2G0r203u3x

    The footer is between the field now, and if I look in ‘Inspect element’ from Chrome:
    https://cl.ly/image/0b1l1Z3g2h0c

    The content-area (and also the site-main) haven’t a height, but I cant set it to xx pixels because it isn’t dynamic.

    esmi

    (@esmi)

    CSS without the context of the site that it’s being used in is really rather meaningless. But what you are obviously dealing with now is a pure CSS issue – not a WordPress one. Try a dedicated CSS resource such as https://www.css-discuss.org/

    Thread Starter Marijn

    (@marijn-bent)

    Thanks, I will look at it!

    Thread Starter Marijn

    (@marijn-bent)

    Hi,

    I discovered the error. The following code works:

    .post-num-1 {
    	background: white;
    	float: left;
    	width: 70%
    }
    
    .post-num-2 {
    	background: white;
    
    }
    
    .post-num-3 {
    	background: white;
    }
    
    .staticcustomfield {
    	background: white;
    	float: right;
    	width: 30%;
    }

    But the post-num-2 and 3 are wrong placed. If I give them a width, it goes wrong. Can you help me with this last thing?

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘The three most recent posts in different div's, how?’ is closed to new replies.