Results 1 to 2 of 2

Thread: Page Template: List of posts, sorted by array of categories?

  1. #1
    tewonawonga's Avatar
    tewonawonga is offline Hello World
    Join Date
    Jun 2010
    Location
    Denver, CO
    Posts
    18

    Default Page Template: List of posts, sorted by array of categories?

    Hey everyone. Long time no post—guess that's a sign that my PHP skills are improving at least a little.

    I'm trying to build a custom page template that outputs an array of categories with a list of posts for each, something like this:

    <h3>Category 1</h3>
    <ul>
    <li>Post 1 in category 1</li>
    <li>Post 2 in category 1</li>
    </ul>
    <h3>Category 2</h3>
    <ul>
    <li>Post 1 in category 2</li>
    <li>Post 2 in category 2</li>
    </ul>


    ...and so on. I've used James Wilkes' Category Post List plugin and it's working great (you can see the results here, all snazzified with jQuery Accordion: http://debbiekoenig.com/recipe-index/)

    BUT, my client would like to have the option of substituting a custom field for the post title too. Instead of hacking away at the plugin by James—which is built around a complex shortcode setup—I figured it's time that I write something simpler for myself.

    Can anyone point me in the direction of a good tutorial or help me get started? Thanks in advance!

  2. #2
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

    Of the top of my head, perhaps this works.
    If you know on which page the "shortcode" is run you can filter get_the_title function and return the postmeta value instead.
    if(is_page(x) ... )//so the replace aint run on all posts and pages
    add_filter('the_title','replace_with_post_meta')

    function replace_with_post_meta($title,$post_id){
    $new_title=get_post_meta($post_id,'metakey',true);
    $title=$new_title?$new_title:$title;
    return $title;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •