Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to give my users the ability to customize the homepage of the site. For example, if somebody is not logged in only the default categories appear.

Once someone creates an account and logs in, he/she has opportunity to 'add/follow' more categories and topics (tags) and search results. These new posts will then be added to the stream on the homepage that they see.

I've looked and searched a lot for tutorials and plugins, but I haven't found a lot. There is one premium theme though that kind of has this function.

Category watching Pressboard lets you set individual homepage for each user: simply enable category watching so users can choose for themselves which topics to load.
( http://freetotry.me/pressboard/ -> settings button top right )

I want to replicate something similar like the above. But thinking about it, I'm not sure what would be the best approach.

  • adding variables to the url (http://codex.wordpress.org/Function_Reference/add_query_arg) and save the result somewhere. And perhaps use jQuery to 'normalise' to url location afterwards.
  • Enable rssfeeds for each tag, search results and category, where users can subscribe to. Store these feed values and build their homepage from those feeds.
  • Add the categories/tags etc to their user profile to follow/unfollow, save that data and adjust the query post.
  • Some other way?

Does anyone know how to achieve a custom homepage for each user?

share|improve this question
    
Btw, in case it wasn't clear, I just found out Mashable has something similar to what I would like to achieve with 'Mashable Follow'. (youtube.com/watch?v=vbLazF5KxUc&feature=player_embedded) –  user18144 Sep 3 '12 at 19:04
    
Not quite sure what's being asked here. It seems like you're trying to load multiple questions into one question post. –  Brian Fegter Sep 5 '12 at 11:19
    
Hi Brian, I basically wanted to know how to setup a custom homepage for each user, where users can define the content they want to see. Then I stumbled upon some posts that I could use as a basis and I started trying to figure it out. :) –  user18144 Sep 5 '12 at 14:27
1  
You should go back and simplify your question drastically - just add what's in your comment: "Let each user define her/his individual home/front page". Then show what you tried. –  kaiser Sep 12 '12 at 23:44
    
You want to create a custom page where user can see posts from user selected categories. Is that right? If so, I'll suggest a custom page template with a custom query based on saved data current user meta. Hope this help –  ifdion Nov 29 '12 at 23:29
add comment

1 Answer

Found and combined some code that seems to work for categories. So leaving the code if somebody else runs into the same problem. For reference. - Filter all queries with a specific taxonomy - Adding Custom User Profile data based upon Categories

The below allows a user to choose categories on this profile, after which the frontpage will allow show his selected categories.

//create the user category fields
add_action( 'show_user_profile', 'add_user_categories' );
add_action( 'edit_user_profile', 'add_user_categories' );

function add_user_categories($user ){
    ?>
    <table class="form-table">
    <tr>
        <th><label for="user_categories"><?php _e("User categories"); ?></label></th>
        <td>
            <?php
                $data = get_the_author_meta( 'user_categories', $user->ID );
                $args = array( 'hide_empty' =>0, 'taxonomy'=> 'category');
                $categories=  get_categories($args);
                if ($categories){
                    foreach ( $categories as $category ){ 
                        if(in_array($category->term_id,(array)$data)) {
                            $selected = 'checked="checked""';
                        } else {
                            $selected = '';
                        }
                        echo '<input name="user_categories[]" value="'.$category->term_id.'" '.$selected.' type="checkbox"/>'.$category->name.'<br/>';
                    }
                }
            ?>
        </td>
    </tr>
    </table>
    <?php
}

//save the user category fields 
add_action( 'personal_options_update', 'save_user_categories' );
add_action( 'edit_user_profile_update', 'save_user_categories' );

function save_user_categories( $user_id ){
    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
    update_usermeta( $user_id, 'user_categories', $_POST['user_categories'] );
}

function my_get_posts( $query ) {
    // we only need to modify the query for logged in users
    if ( !is_user_logged_in() ) return;
    $current_user = wp_get_current_user();
    // assuming that the users interest is stored as user_categories meta key
    $user_categories = get_user_meta( $current_user->ID, 'user_categories', true );
    $query->set( 'tax_query', array(
        array(
            'taxonomy' => 'category',
            'field' =>  'id',
            'terms' => $user_categories
        )
    ));
    return $query;
}
add_filter( 'pre_get_posts', 'my_get_posts' );
share|improve this answer
1  
+1 for finding the answer and sharing it with us. You should prefix your function names to avoid collisions with other people’s code. –  toscho Nov 29 '12 at 11:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.