two columns of posts on homepage, one of them “favorites”

I’m using a child theme of Twenty Twelve in wordpress. Here’s where I am developing the site:

http://internalcompass.us/castle/

Read More

You’ll notice the two columns of posts on the homepage. I have one labeled recent posts and one labeled favorites. In actuality, both columns are the same – recent posts organized by date. I’d like to actually create a set of posts that populate the second column, so my client can select recommended posts or her favorite posts for that column. I’d like the first column to be recent posts.

I’m hearing crickets on the WordPress Support forum, likely because this is a pretty technical q. sooooo Any info is appreciated. I’m sure I can somehow label posts and add code to the index.html to populate the second column. I just am not yet equipped with the info to know what code to add.

Peace & thx

Related posts

2 comments

  1. I think you are hearing “crickets” because there are several component to this. You need to:

    1. Create a meta_box
    2. Save data from that meta box
    3. And build a Loop on the front

    For #1 and #2:

    function add_featured_meta_box() {
      add_meta_box("featureddiv", "Featured Post", "featured_post_meta_box", 'post', "side", "low");
    }
    add_action("do_meta_boxes", "add_featured_meta_box");
    
    function featured_post_meta_box(){
      global $post;
      $custom = get_post_custom($post->ID);
      $featured = (!empty($custom["_featured"][0])) ? $custom["_featured"][0] : ''; ?>
    <table>
        <tr>
            <td>Featured
            <td> <input type="checkbox" name="featured" <?php checked($featured,true); ?> /> </td>
        </tr>
    </table><?php
    }
    
    function save_featured_meta($postid,$post){
      global $_POST;
      // set the ID to the parent post, not the revision
      $postid = (wp_is_post_revision( $postid )) ? wp_is_post_revision( $post ) : $postid;
      $post_type = get_post_type( $postid );
      if (isset($_POST['featured'])) {
        update_post_meta($postid, "_featured", true);
      } else {
        delete_post_meta($postid, "_featured", true);
      }
    }
    add_action('save_post', 'save_featured_meta', 1, 2);
    

    And for #3:

    $args = array(
      'post_type' => 'post',
      'ignore_sticky_posts' => true,
      'meta_query' => array(
        array(
          'key' => '_featured',
          'value' => true,
        )
      )
    );
    $query = new WP_Query( $args );
    

    Barely tested. Possibly buggy. Caveat emptor. No refunds.

  2. A quick method would be to add a category favorite and filter the loop by only pulling posts from that category. The client could then check and un-check the favorite category on posts. Here is a rough of the args array for the loop.

    $args = array(
        'category_name' => 'favorite',
        'post_type' => 'post', //or whatever post type you need
    );
    
    $posts = query_posts( $args );
    if( have_posts() ): while( have_posts() ): the_post(); ?>
        <article id="post-<?php echo $post->ID; ?>" class="post type-post post-<?php echo $post->ID; ?>">
            <header class="entry-header">
                <?php echo get_the_post_thumbnail( $post->ID, 'full' ); ?>
                <h1 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
            </header>
        </article>   
    <?php
       endwhile;
       endif;
       wp_reset_query();
    ?>
    

Comments are closed.