Support » Themes and Templates » Get latest blog content for page-template

  • Resolved DkDesign


    Fairly new to WP so bear with me if you can.

    I am building a custom theme for a friends band. The Front Page is a static page (called “home”) with a custom page-template (callled “home-page.php”).

    I am using another static page (called “blog”) with a separate page-template I made (called “blog-page.php”). I made this “blog” page the post page under settings>reading.

    Everything is working fine, but I want to add a section on the static front page that displays a preview of the latest blog post as well as the title (I want it to display the first 15 lines of the latest post content with a link to the full post).

    I am having a really hard time finding the right code to put in the home-page.php template (Front page template) that will allow me to get the title and content from the latest post.

    Also if anyone knows how to get the content with a character or line limit that would also be very very helpful!

Viewing 3 replies - 1 through 3 (of 3 total)
  • OK, so I think I figured it out right after posting this useing:

    <?php query_posts(‘showposts=1’); ?>

    before the loop.

    Still looking for a way to only get a certain character limit (or a work around).

    Also I was wondering if anyone knows a way to get only text and exclude any images or embedded video, code, iframes, ect. Dont know if this is possible or not, but if anyone has any ideas it would be great!

    You can make use of

    <?php the_excerpt(); ?>

    instead of

    <?php the_content(); ?>

    something like

    <?php query_posts('showposts=1'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <div class="post-teaser">
        <h2><a href="<?php the_permalink() ?>" title="Link to <?php the_title_attribute(); ?>"><?php the_title();?></a></h2>
        <?php the_excerpt(); ?>
    <?php endwhile; endif; ?>
    <?php wp_reset_query(); ?>

    Thank you egado! I knew it was something simple that I just hadn’t stumbled upon yet.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get latest blog content for page-template’ is closed to new replies.