1

I have a number of pages, and on each I would like to display the latest post from the category which matches that page.

So I have page 1, 2 and 3, and on page 1, I'd like the latest post from category A. 2 -> B, 3 -> C, and so on.

I have been trying to code this myself, but I can't find a solid enough CMS resistant way of linking the page to the post category. Thus if someone changes the page, I'd lose the post.

I have found the plugin, http://wordpress.org/extend/plugins/list-category-posts/ which seems to do what I want, however adding a shortcode to my page, just displays the shortcode and doesn't do anything. I assume this is because it supports WP 3.1.4 and I'm running 3.2.1.

Can I code this functionality myself, or will I need to create a link table in the database? I'd rather use the WP framework, but if I can't crack this, I'll just write a script to do it in plain old php and just include it, which I don't want to do.

1 Answer 1

1

I have managed to solve this problem by creating my own code.

In my content-excerpt.php template part, I have included the following,

if(!is_page('Home')){

    $page = get_page(get_the_ID());
    $custom = get_post_custom($page->ID);
    // I have added a custom field on the page, which contains the category id

    $custom_post = get_posts(array('numberposts'=>1, 'category'=>$custom['Category Link'][0], 'post_type'=>'post', 'post_status'=>'publish'));
    $post = $custom_post[0];
}

Which I can then use in the normal way, with things like the_title()

Hope someone finds this handy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.