WordPress Architecture as a CMS – Posts & Pages

There is an awesome plugin by @scribu called Posts 2 Posts. It allows you to manually associate different post types (or the same post type) with each other. I use it quite a bit for bigger CMS type projects and even pluginized a common pattern I found myself writing on a few sites.

Here’s an example to do what you need with Posts 2 Posts

<?php
WPSE45561_Pages_Posts::init();

class WPSE45561_Pages_Posts
{
    private static $ins = null;

    public static function init()
    {
        add_action('plugins_loaded', array(__CLASS__, 'instance'));
    }

    public static function instance()
    {
        is_null(self::$ins) && self::$ins = new self;
        return self::$ins;
    }

    protected function __construct()
    {
        add_action('p2p_init', array($this, 'connections'));
    }

    public function connections()
    {
        p2p_register_connection_type(array(
            'name'      => 'page_to_posts',
            'from'      => 'page',
            'to'        => 'post',
            'admin_box' => array(
                'show'    => 'from', // only show on pages
                'context' => 'advanced', // put admin box in main col, instead of side
            ),
        ));
    }
}

Getting connected posts on the front end is simple as well. Somewhere in the loop:

<?php
$connected = p2p_type('pages_to_posts')->get_connected($post->ID);
if($connected->have_posts())
{
    while($connected->have_posts())
    {
        $connected->the_post();
        // normal loop stuff here
    }
}

If you don’t want to use that plugin, there are a few options.

  1. Associate a category with a given page, pull posts in from that category. You can either make this static or add a meta box to do that.
  2. Associated posts with pages via some sort of multi select (again, in a meta box).

I can provide you some example code for the above two options, but I’d strongly suggest you check out Posts 2 Posts.