• Resolved jbdev

    (@jbdev)


    Hi

    I can’t see this anywhere else, apologies If I have missed it.

    I have set up a static page as a homepage (with no sidepanel). I would like to show a ‘latest news’ section on the home page only, the latest news page would be a news blog page located somehwere else on the site.

    Ideally the ‘latest news’ section on the homepage would show a title a few lines of copy and a read more button linking to the exact article or the news blog page.

    Thanks in advance

Viewing 11 replies - 1 through 11 (of 11 total)
  • <?php
     $my_latestNews = new WP_Query('category_name=news&showpost=5');
     while($my_latestNews->have_posts()): $my_latestNews->the_post();
    ?>
       <h2><a href="<?php the_permalink()?>" rel="Bookmark" ><?php the_title()?></a></h2>
       <p><?php the_content("Read more..."); ?></p>
    <?php
     endwhile;
    ?>

    Try this.

    Thread Starter jbdev

    (@jbdev)

    sorry to be dense but how do I get this to show only on the home page if I insert in to page.php?

    use this

    <?php if(is_home()) :
    $my_latestNews = new WP_Query('category_name=news&showpost=5');
     while($my_latestNews->have_posts()): $my_latestNews->the_post();
    ?>
       <h2><a href="<?php the_permalink()?>" rel="Bookmark" ><?php the_title()?></a></h2>
       <p><?php the_content("Read more..."); ?></p>
    <?php
     endwhile;
    endif;
    ?>

    or use is_front_page() function

    Thread Starter jbdev

    (@jbdev)

    hmmm
    Have added in the code and this is bringing up nothing, please can you show where i need to enter site specific information into the code.

    Sorry very new to wordpress

    do you create a “news” category for latest News?

    Put the code before the while(have_posts()): line

    Thread Starter jbdev

    (@jbdev)

    Ah progress

    I have now have the relevant category showing on every page using the following

    <h1>Latest News</h1>
    <ul class="latest-news">
    <?php
     global $post;
     $myposts = get_posts('numberposts=3');
     foreach($myposts as $post) :
     ?>
    
    <li><span class="post-info"><?php the_title(); ?><?php the_time('F jS, Y'); ?></span><a>"></a></li>
     <?php endforeach; ?>

    2 questions
    I would like to put this in a div and show the div only on the homepage how?
    I would like to have 3 or 4 lines of each post showing as a teaser, how?

    Thread Starter jbdev

    (@jbdev)

    Progress

    I now have the ‘latestnews’ categories showing only on the front page using the follwing,

    <?php if( is_front_page() ) { ?>
    <div class="latestnews">
    <h1>Latest News</h1>
    <ul class="latest-news">
    <?php
     global $post;
     $myposts = get_posts('numberposts=3');
     foreach($myposts as $post) :
     ?>
        <li><span class="post-info"><?php the_title(); ?><br/><?php the_time('F jS, Y'); ?></span><a href="<?php the_permalink(); ?>"></a></li>
     <?php endforeach; ?>
    </ul>
    </div>
    	<?php } ?>

    I would like to show 3 lines of copy from each post, any ideas?

    Thread Starter jbdev

    (@jbdev)

    Thanks for your help chinmoy29 I now the following code working

    <?php if( is_front_page() ) { ?>					<!--This controls the small boxes div on the homepage-->
    <div class="coverboxes">
    <?php $posts = get_posts( "category=4&numberposts=2" ); ?>
    <?php if( $posts ) : ?>
         <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
           <div class="post">
    
              <p class="post-info-home"><span class="coverbox_header"><?php the_title(); ?></span></p>
              <div class="post-title-home">
           </div>
           <div class="entry">
              <?php the_excerpt(); ?>
              <em><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>">Read more</a></em>
           </div>
         </div>
       <?php endforeach; ?>
    <?php endif; ?>
    </div>
    <?php } ?>

    This code does not show the image in the post is there any way of pulling this into the homepage above the excerpt. Help great;y appreciated

    I tried<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>' ) ); ?> but it doesn’t work.

    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>' ) ); ?>

    Its have no error. Did you put this <!--more--> in your post? If you don’t use that tag, the ‘Continue reading>>’ would not be came. Go to EDITOR through admin and put the “more” tag.

    Place `function new_excerpt_length($length) {
    return 10;
    }
    add_filter(‘excerpt_length’, ‘new_excerpt_length’);` in your functions.php

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Latest News on static hompage’ is closed to new replies.