0

I need to have a page, that displays the latest post in the category 'news' or sub category 'news->nen-news'. And I need to be able to link to from the main navigation (news->news article).

My news posts are normal posts with a category of 'news' ( or sub category of news->nen-news).

I have tried to do a page-news-article.php template and then call in the latest news post which works okay. But then the breadcrumbs are wrong because the url is /news/news-article instead of /category/news/news-article/ .

I need the correct url so the breadcrumbs are right:- home > news > news-article .

Many thanks.

1
  • If it's a single page then why don't you hard-code the breadcrumb to the correct url into the template – Sudeep K Rana Feb 25 '14 at 7:22
0

You need to create a page of post. It is quick and very easy

HERE IS HOW

STEP 1

Copy your page.php template and rename it to something like page-pop.php

STEP 2

Open up the template and add the following header right at the top to tell wordpress it is a page template

<?php
/**
 * Template Name: Page of Posts
 */
get_header(); ?>

Step 3

You need to modify the loop so that it will display the selected category's posts . We are going to make use of WP_Query to create a custom query in which we will call posts from the specific category

This is how your new loop and query should look like. Here you make use of the cat parameter in WP_query to retrieve posts from the category ID given. Just change 1 to the category ID you need to get posts from

<?php

// The Query
$the_query = new WP_Query( 'cat=1&posts_per_page=10' );

// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

?>

STEP 4

Now save the template, create a new page and assign this template to it. You should now have a page that displays posts from your desired category

Also, see the following

1
  • I managed to find another solution - but the tutorial was relevant and I am sure would work 100% - so you get the tick ;] – user1683285 Feb 26 '14 at 15:09

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.