• Resolved empulse

    (@empulse)


    I’m using the following code to pull in my 2 most recent posts, and I’d like the date to be included on the line that the_title is on.. <?php the_date();> works, but it makes the date a link, which looks awful. How would I pull in the date from the article on that same line, but just have it as standard formatted text?

    <?php
    $args = array( 'numberposts' => 2, 'category' => 7,);
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?>     &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   <?php the_date(); ?></a></h2>
    	<?php the_excerpt();?>
    <?php endforeach; ?>
        </div>

    Thanks in advance for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php the_date(); ?></h2>

    depending on the existing styles, this might effect the formatting/layout of the date.

    Thread Starter empulse

    (@empulse)

    Found the error, thanks alchymyth =)

    I just had to close the hook with the_permalink and the_title.

    For anyone running into this in the future, this code works fine for me.

    <?php
    $args = array( 'numberposts' => 2, 'category' => 7,);
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a>     <?php the_date(); ?></h2>
    	<?php the_excerpt();?>
    <?php endforeach; ?>
    Thread Starter empulse

    (@empulse)

    alchymyth; what would be the proper way to add space between the_title and the_date…. Judging from your post using   is not proper.

    ~ Brandon

    what would be the proper way to add space between the_title and the_date….

    nothing wrong with row of ‘non-breaking-spaces’ …

    possibly using a html span tag for the date, and styling that in style.css;

    example:

    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a> <span><?php the_date(); ?></span></h2>

    h2 span { margin-left: 30px; }

    (or padding-left; not tested)

    Thread Starter empulse

    (@empulse)

    <span> works perfectly… Nice and clean. Thank you =)

    This is where I’m at

    <?php
    $args = array( 'numberposts' => 3, 'category' => 7,);
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a>   <span><?php the_date(); ?></span></h2>
    	<?php the_excerpt();?>
    <?php endforeach; ?>

    Now I know I’m abusing having your attention. . . . But while I got it, I figure I’d ask my last question in regards to this project… Currently this is returning the last 3 posts and excerpting each of them. How would I go about ONLY excerpting the newest post, but still pulling in the previous 2 titles/dates without and excerpt? The things I’ve tried don’t work… Granted I know nothing about php.

    Thanks again for all your help, even if you can’t answer this last question. I’m grateful!

    Thread Starter empulse

    (@empulse)

    Solved myself…

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

    works perfectly for doing this. Anyone who runs into this issue can find more info here, under “Post Lists with Offset”.

    Thanks again alchymyth!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display Post Date, but not as a link… ??’ is closed to new replies.