• Hi

    I was just wondering if anyone could advise?

    I am creating a website which is going to have a ‘latest news’ section. What I need to do is display the top 3/4 latest news stories on the homepage which will click through to the full story. I want this to be done automatically if possible, so that the user doesn’t need to edit the homepage by adding the content again.

    I was just wondering if anyone knew of a news plug-in which would enable me to do this?

    Any help appreciated.

    Regards
    Andrew

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi Andrew,

    I have developed Latest News function for a website but haven’t made it into a plugin. If you don’t find anything out there that can do the job let me know. I don’t think it would be much work to make my code into a plugin and it would be an interesting challenge.

    Regards,
    James

    Thread Starter andyk1916

    (@andyk1916)

    Hi James

    That would be excellent. I will keep digging the plug-ins (to save you time) but may well take you up on your offer.

    Cheers.

    Regards
    Andrew

    It should be really easy to do this using a combination of get_posts (for the news stories) and query_posts (to exclude the news stories from the main Loop) in the theme’s index.php template file. All that would then be needed is to file all the news stories under a pre-agreed category.

    Thread Starter andyk1916

    (@andyk1916)

    Thanks esmi, but I am not the best with coding, more of a designer, so would struggle to do as you suggest.

    Thanks again for your help though.

    Lets assume that all of the news posts are going to be filed under the News category (id=7), yes? Then you could use:

    <?php
    // grab & display the most recent posts in the News category
    $args= array(
    	'category_name' => 'News',
    	'numberposts' => 4
    );
    $newsposts = get_posts($args);
    foreach($newsposts as $post) : setup_postdata($post); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
    <?php endforeach;
    // End News posts display
    
    /* Now exclude the News posts from the main posts display.
    The id of the News category is 7 in this example. */
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'category_name' => -7,
    	'paged' => $paged
    );
    query_posts($args);
    
    // Now back to the standard Loop
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    [...]
    Thread Starter andyk1916

    (@andyk1916)

    Thanks for that. I will give it a go.

    Your help is much appreciated!

    No problem. If you need any more help implementing this, just post a new topic in the How-To or Themes forum.

    Well, for what it’s worth my approach is slightly different. I have used a custom post type rather than using a specific category. The downside is this requires more code to configure the custom post type while the upside is it makes the template simpler as there is no need to exclude posts from the main loop.

    I have also used WP_query instead of get_posts to output the custom loop. This was to avoid having to filter out the post metadata (author/comments and so on) as I think that is included if you use get_posts.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Website News Writing Plugin’ is closed to new replies.