1

(It might not be the first time this question is asked, but every time I found someone else asking it elsewhere, the post was very old and the method used wasn't efficient anymore.)

► I'd like to be able to show the last article of a specific category (let's say the category is "news") on my homepage (it's a wordpress page).

I've already made a custom template for it, but I just don't know what to call to display the last article. Important : It isn't the only thing I want to display. In fact I would need to display the article on the right side of the page (so far I've tried setting up a table with two columns and putting it in the right one, but this may not be the best method).

The best thing would be to be able to display the article "raw", what I mean here is that if I put links in the post, clicking on the <a> tag in the homepage will directly take me to the reffered link and not to the post itself.

Let me know if you guys need anything else :)

1

Alright, I think I found my answer.

As I've said, I created a new php template in my theme named "New Index" and associated my homepage to it. This template was at first a copy of the original index.php

Now here is the code I added for it to make what I wanted :

<?php $the_query = new WP_Query( 'posts_per_page=1&category_name=news' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

<div id="last_news">
    <div id="last_news_title"><?php the_title(); ?></div>
    <div id="last_news_time"><?php the_time('j F Y'); ?></div>
    <div id="last_news_content"><?php the_content(); ?></div>
</div>

<?php 
    endwhile;
    wp_reset_postdata();
?>

This may not be the optimal solution though, I'd be curious to hear tips about it.

  • Glad that you solved your own question. Make sure that you click the checkmark next to your answer to indicate that this question is resolved. – Ethan Jinks O'Sullivan Sep 4 '16 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.