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 am trying to make a wordpress site with an idiot-proof backend CMS. I have built several relatively small wordpress sites, but now have moved on to a larger project and want to do it right.

There will be several (maybe as much as 10+) pages each with unique structures and elements (different numbers of pictures, and text-content areas). There will be maybe a couple dozen other pages with more standard layouts (just some text into a template). Ideally, I would want the "edit page" area of each 'unique' page to have its own unique set-up.

For Example, heres a few sample pages:

Home page

  • List item
  • 2 sections of text
  • 6 photos with captions (captions are split in 2 sections each for 2 fonts and a line break)

About page

  • 2 images (no captions)
  • 1 main text section
  • 1 video

Videos page

  • 2 text sections
  • 1 picture
  • any number of videos

Now its pretty clear to me that for the videos page, I should create a custom-post-type video, where the user can put in the url for a YouTube video, some descriptive text etc... and then pull all of those video posts into my videos page.

What is unclear to me is whether I should make a 'homepage' custom-post-type with only one post (the homepage) and do the same thing for other pages with unique elements/layouts.

I hope this is clear enough, I can elaborate more or create some images of what I have in mind, but this seems to be getting rather lengthy.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

In my experience, the default "Pages" is easy enough for people to understand..it is where you edit each page.

You can make a "Videos" page template for a Videos page that can show the page content at top "your text areas" and then calls a listing of all the custom post type Videos you created. I just worked on a site with CPT for videos so here is some code you can play with..it creates a taxonomy for Videos, and then the video types, and then adds some extra features to the back-end for adding videos. It is kind of long but just copy and past into your functions.php file and then edit out the bits you don't want.

*Additional Thoughts** For the 10+ pages that have the more complex layouts, a new custom-post-type would be appropriate, especially if you can think of a group of generic metafields and boxes you can use that can be put to work on each of the pages. For example: A custom post type called "Special Pages" The edit page for "Special Pages" will a set of meta-fields with some generic labeling: Images- "Image 1" "Image 2"... Text: "Text 1" "text 2"

You can add the simple-video-editor to this post type to get the Video Fields Here is a blog-post a guy made about creating just such a special Page: http://sicdigital.com/2010/07/create-custom-post-type-for-image-upload-wordpress3/

<?php
/*******************************************************************Create a Custom Taxonomy ******************************/
        add_action( 'init', 'build_taxonomies', 0 );  
        function build_taxonomies() {  
            register_taxonomy( 
            'video_types', 
            'videos',
           array( 'hierarchical' => true, 
            'label' => 'Video Types',
            'query_var' => true, 
            'rewrite' => true ) );  
        }
        // Add to admin_init function
        add_filter("manage_edit-video_types_columns", 'theme_columns'); 
        function theme_columns($theme_columns) {
            $new_columns = array(
                'cb' => '<input type="checkbox" />',
                'name' => __('Name'),
        //      'description' => __('Description'),
        //      'slug' => __('Slug'),
                'posts' => __('Posts')
                );
            return $new_columns;
        }
        /*******************************************************************Create a Custom Post Type******************************/
        add_action( 'init', 'create_post_type' );
        function create_post_type() {
        //start the post type
        register_post_type( 'videos',
        array(
        'labels' => array(
        'name' => __( 'Videos' ),
        'singular_name' => __( 'Video' ),
        'slug' =>  __( 'videos' ),
        'with_front'=>  __( false ),
        'new_item' =>  __( 'New Video' ),
        'add_new_item'=>  __( 'Add New Video' ),
        'edit_item'=>  __( 'Edit Video' )
        ),
        'public' => true,
        'has_archive' => true,
        'menu_position' => 6,
        'supports' => array('title','thumbnail',  'videoembed')
        )
        );
        //end this post type
        }/*---end create post type---*/

        // Customise edit columns for video post type

        add_filter("manage_edit-videos_columns", "prod_edit_columns");
        add_action("manage_posts_custom_column",  "prod_custom_columns");

        function prod_edit_columns($columns){
        $columns = array(
        "cb" => "<input type=\"checkbox\" />",
        "title" => "Video Title",
        "video_type" => "Video Type",
        );
        return $columns;
        }
        function prod_custom_columns($column){
        global $post;
        switch ($column)
        {
        case "video_type":
        echo get_the_term_list($post->ID, 'video_types', '', ', ','');
        break;
        }
        }
        // Make these columns sortable
        function sortable_columns() {
          return array(
          "video_type" => "video_types",
            "title" => "title"
          );
        }
        add_filter( "manage_edit-videos_sortable_columns", "sortable_columns" );
        // Filter the request to just give posts for the given taxonomy, if applicable.
        function taxonomy_filter_restrict_manage_posts() {
            global $typenow;

            // If you only want this to work for your specific post type,
            // check for that $type here and then return.
            // This function, if unmodified, will add the dropdown for each
            // post type / taxonomy combination.
            $post_types = get_post_types( array( '_builtin' => false ) );
            if ( in_array( $typenow, $post_types ) ) {
                $filters = get_object_taxonomies( $typenow );
                foreach ( $filters as $tax_slug ) {
                    $tax_obj = get_taxonomy( $tax_slug );
                    wp_dropdown_categories( array(
                        'show_option_all' => __('Show All '.$tax_obj->label ),
                        'taxonomy'    => $tax_slug,
                        'name'        => $tax_obj->name,
                        'orderby'     => 'name',
                        'selected'    => $_GET[$tax_slug],
                        'hierarchical'    => $tax_obj->hierarchical,
                        'show_count'      => false,
                        'hide_empty'      => true
                    ) );
                }
            }
        }
        add_action( 'restrict_manage_posts', 'taxonomy_filter_restrict_manage_posts' );
        function taxonomy_filter_post_type_request( $query ) {
          global $pagenow, $typenow;
          if ( 'edit.php' == $pagenow ) {
            $filters = get_object_taxonomies( $typenow );
            foreach ( $filters as $tax_slug ) {
              $var = &$query->query_vars[$tax_slug];
              if ( isset( $var ) ) {
                $term = get_term_by( 'id', $var, $tax_slug );
                $var = $term->slug;
              }
            }
          }
        }
        add_filter( 'parse_query', 'taxonomy_filter_post_type_request' );
        /*---end edit columns---*/
    /************************************************************ Simple Video Editor   and Video Thumbnails plugins   *******/
    //HOTFIX FOR VIMEO VIDEOS NOT SHOWING UP USING LINK
    function fix_vimeo_oembed_providers( $providers ) {
    $providers['#http://(www\.)?vimeo\.com/.*#i'] = array( 'http://vimeo.com/api/oembed.{format}', true );
    return $providers;
    }
    add_filter('oembed_providers', 'fix_vimeo_oembed_providers');
    /**
     * Gets the embed code for a video.
     *
     * @param $postID The post ID of the video
     * @return The embed code
     */
    function p75GetVideo($postID, $width= ''){
        global $wp_embed;
        // legacy support...
        if ( $videoURL = get_post_meta($postID, 'videoembed', true) ) return $videoURL;
        if ( $videoEmbed = get_post_meta($postID, '_videoembed_manual', true ) ) return $videoEmbed;

        $videoURL = get_post_meta($postID, '_videoembed', true);
        if ( !($videoWidth = get_post_meta($postID, '_videowidth', true)) )
            $videoWidth = get_option('p75_default_player_width');
        if ( !($videoHeight = get_post_meta($postID, '_videoheight', true)) )
            $videoHeight = get_option('p75_default_player_height');

        $height = intval ( $width * ( $videoHeight / $videoWidth ) );

        if (empty($width)){$width = $videoWidth;}
        if (empty($height)){$height = $videoHeight;}
        return $wp_embed->shortcode( array('width' => $width, 'height' => $height), $videoURL );
    }
    /**
     * Returns true if post has a video.
     *
     * @param $postID The post ID
     * @return True if post has a video, false otherwise
     */
    function p75HasVideo($postID)
    {
        return (bool) 
            (
                get_post_meta($postID, '_videoembed', true) ||
                get_post_meta($postID, '_videoembed_manual', true) ||
                get_post_meta($postID, 'videoembed', true)
            );
    }

    // Register the custom JW Media Player embed handler.

    function p75_jw_player_handler( $matches, $attr, $url, $rawattr )
    {
        static $counter = 1;

        if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) { 
            $width  = (int) $rawattr['width'];
            $height = (int) $rawattr['height'];
        } else {
            list( $width, $height ) = wp_expand_dimensions( 
                get_option('p75_default_player_width'), 
                get_option('p75_default_player_height'), 
                $attr['width'], $attr['height'] );
        }

        $flashvars = get_option('p75_jw_flashvars');
        if ( !empty($flashvars) && substr($flashvars, 0, 1)!='&' )
            parse_str( $flashvars, $vars );

        $file_loc = get_option('p75_jw_files');
            if ( substr($file_loc, -1)!='/' )
                $file_loc = $file_loc . '/';

        $res = "
    <script type='text/javascript' src='{$file_loc}swfobject.js'></script>
    <div id='videoContainer-" . $counter . "'>This text will be replaced</div>
    <script type='text/javascript'>
    var so = new SWFObject('{$file_loc}player.swf','ply','" . esc_attr($width) . "','" . esc_attr($height) . "','9','#000000');
    so.addParam('allowfullscreen','true');
    so.addParam('allowscriptaccess','always');
    so.addParam('wmode','opaque');
    so.addVariable('file','" . esc_attr($url) . "');\n";
        if ( $vars )
        {
            foreach ( $vars as $key => $val )
                $res .= "so.addVariable('$key','" . rawurlencode($val) . "');\n";
        }
        $res .= "so.write('videoContainer-" . $counter++ . "');
    </script>\n";
        return $res;
    }

    wp_embed_register_handler( 
        'p75_jw_player', 
        '#http://.*\.(flv|mp4)#i', 
        'p75_jw_player_handler' );


    // RSS feed filter to include videos

    function p75_feed_video_filter($content, $feed) {
        global $post;

        if ( p75HasVideo($post->ID) )
            return p75GetVideo($post->ID) . $content;

        return $content;
    }

    add_filter('the_content_feed', 'p75_feed_video_filter', 10, 2);


    /**
     * Plugin activation. Set default player width
     * and height if not present.
     */
    register_activation_hook(__FILE__, 'p75_sveActivate');

    function p75_sveActivate()
    {
        global $wpdb;

        // Set default player width and height if not present.
        add_option('p75_default_player_width', '670');
        add_option('p75_default_player_height', '400');
        update_option('p75_sve_version', '2.0');
    }

    /**
     * Post admin hooks
     */
    add_action('do_meta_boxes', "p75_videoAdminInit");
    add_action('admin_menu', "p75_videoAdminOptionsInit");
    add_action('save_post', 'p75_saveVideo');

    /**
     * Add video posting widget and options page.
     */
    function p75_videoAdminInit($page)
    {
        if( function_exists("add_meta_box") )
        {
            $post_types = explode(',',get_option('p75_post_types'));
            if ( in_array( $page, $post_types ) ){ add_meta_box("p75-video-posting", "Post Video Options", "p75_videoPosting", $page, "advanced"); }
        }
    }
    function p75_videoAdminOptionsInit()
    {
        add_options_page('Simple Video Embedder Options', 'Video Options', 8, 'videooptions', 'p75_videoOptionsAdmin');
    }

    /**
     * Code for the meta box.
     */
    function p75_videoPosting()
    {
        global $post_ID, $wp_embed;
        $videoURL = get_post_meta($post_ID, '_videoembed', true);
        $videoHeight = get_post_meta($post_ID, '_videoheight', true);
        $videoWidth = get_post_meta($post_ID, '_videowidth', true);
        $videoEmbed = get_post_meta($post_ID, '_videoembed_manual', true);


    ?>





        <div style="float:left; margin-right: 5px;">
            <label for="p75-video-url"><?php _e("Video URL"); ?>:</label><br />
            <input style="width: 300px; margin-top:5px;" type="text" id="p75-video-url" name="p75-video-url" value="<?php echo $videoURL; ?>" tabindex='100' />
        </div>
        <div style="float:left; margin-right: 5px;">
            <label for="p75-video-width3"><?php _e("Width"); ?>:</label><br />
            <input style="margin-top:5px;" type="text" id="p75-video-width3" name="p75-video-width" size="4" value="<?php echo $videoWidth; ?>" tabindex='101' />
        </div>
        <div style="float:left;">
            <label for="p75-video-height4"><?php _e("Height"); ?>:</label><br />
            <input style="margin-top:5px;" type="text" id="p75-video-height4" name="p75-video-height" size="4" value="<?php echo $videoHeight; ?>" tabindex='102' />
        </div>
        <div class="clear"></div>

        <div style="margin-top:10px;">
              <label for="p75-video-embed"><?php _e("Embed Code"); ?>: (<?php _e("Overrides Above Settings"); ?>)</label><br />
              <textarea style="width: 100%; margin:5px 2px 0 0;" id="p75-video-embed" name="p75-video-embed" rows="4" tabindex="103"><?php echo htmlspecialchars(stripslashes($videoEmbed)); ?></textarea>
        </div>
        <p>
            <input id="p75-remove-video" type="checkbox" name="p75-remove-video" /> <label for="p75-remove-video"><?php _e("Remove video"); ?></label>
        </p>

    <?php
        // Video preview.
        if ( $videoURL )
        {
            echo '<div style="margin-top:10px;">' . __("Video Preview") . ': (' . __("Actual Size") . ')<br /><div id="video_preview" style="padding: 3px; border: 1px solid #CCC;float: left; margin-top: 5px;">';
            echo p75GetVideo($post_ID);
            echo '</div></div><div class="clear"></div>';
        }
        else if ( $videoEmbed )
        {
            echo '<div style="margin-top:10px;">' . __("Video Preview") . ': (' . __("Actual Size") . ')<br /><div id="video_preview" style="padding: 3px; border: 1px solid #CCC;float: left; margin-top: 5px;">';
            echo stripslashes($videoEmbed);
            echo '</div></div><div class="clear"></div>';
        }
    ?>

    <p style="margin:10px 0 0 0;"><input id="publish" class="button-primary" type="submit" value="<?php _e("Update Post"); ?>" accesskey="p" tabindex="5" name="save"/></p>

    <?php
    }

    /**
     * Saves the thumbnail image as a meta field associated
     * with the current post. Runs when a post is saved.
     */
    function p75_saveVideo( $postID ) {
        global $wpdb;

        // Get the correct post ID if revision.
        if ( $wpdb->get_var("SELECT post_type FROM $wpdb->posts WHERE ID=$postID")=='revision')
            $postID = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID=$postID");

        // Trim white space just in case.
        $_POST['p75-video-embed'] = trim($_POST['p75-video-embed']);
        $_POST['p75-video-url'] = trim($_POST['p75-video-url']);
        $_POST['p75-video-width'] = trim($_POST['p75-video-width']);
        $_POST['p75-video-height'] = trim($_POST['p75-video-height']);

        if ( $_POST['p75-remove-video'] )
        {
            // Remove video
            delete_post_meta($postID, '_videoembed');
            delete_post_meta($postID, '_videowidth');
            delete_post_meta($postID, '_videoheight');
            delete_post_meta($postID, '_videoembed_manual');
        }
        elseif ( $_POST['p75-video-embed'] )
        {
            // Save video embed code.
            if( !update_post_meta($postID, '_videoembed_manual', $_POST['p75-video-embed'] ) )
                add_post_meta($postID, '_videoembed_manual', $_POST['p75-video-embed'] );
            delete_post_meta($postID, '_videoembed');
            delete_post_meta($postID, '_videowidth');
            delete_post_meta($postID, '_videoheight');
        }
        elseif ( $_POST['p75-video-url'] )
        {
            // Save video URL.
            if( !update_post_meta($postID, '_videoembed', $_POST['p75-video-url'] ) )
                add_post_meta($postID, '_videoembed', $_POST['p75-video-url'] );
            delete_post_meta($postID, '_videoembed_manual');

            // Save width and height.
            if ( is_numeric($_POST['p75-video-width']) )
            {
                if( !update_post_meta($postID, '_videowidth', $_POST['p75-video-width']) )
                    add_post_meta($postID, '_videowidth', $_POST['p75-video-width']);
            }
            else if ( empty($_POST['p75-video-width']) )
                delete_post_meta($postID, '_videowidth');

            if ( is_numeric($_POST['p75-video-height']) )
            {
                if( !update_post_meta($postID, '_videoheight', $_POST['p75-video-height']) )
                    add_post_meta($postID, '_videoheight', $_POST['p75-video-height']);
            }
            else if ( empty($_POST['p75-video-height']) )
                delete_post_meta($postID, '_videoheight');
        }

    }

    /**
     * The shortcode for embedding videos in your posts wherever.
     *
     * The shortcode accepts four parameters:
     *  id: some post ID, defaults the current post
     *  url: a URL to a video, defaults to null
     *  width: the player width, only works when specifying the URL
     *  height: the player height, only works when specifying the URL
     *
     * If you specify the post ID, it will use the video, width, and height
     * associated with the post.
     *
     * If you specify the video URL, it will use that URL to create the embedded player.
     * If width and height are specified as well, they will be used, otherwise the
     * defaults will be used as set in the options page.
     */
    function p75_video_short_code($atts, $content=null) {
        global $post, $wp_embed;

        extract(shortcode_atts(array(
            'id' => $post->ID,
            'url' => null,
            'width' => -1,
            'height' => -1
        ), $atts));

        // If a URL is passed in, use that.
        if ( null != $url ) {
            $width = (-1 != $width) ? $width : get_option('p75_default_player_width');
            $height = (-1 != $height) ? $height : get_option('p75_default_player_height');

            return $wp_embed->shortcode( array('width' => $width, 'height' => $height), $url );
        }

        // No URL was passed in.
        return p75GetVideo($id);
    }

    add_shortcode('simple_video', 'p75_video_short_code');

    function p75_videoOptionsAdmin()
    {
    ?>
        <div class="wrap">
        <h2>Simple Video Embedder Options</h2>

            <form method="post" action="options.php">
                <?php
                    wp_nonce_field('update-options');
                    if( get_option('p75_post_types') == "" ){
                        $post_type_value = 'post';
                    }else{
                        $post_type_value = get_option('p75_post_types');
                    }
                ?>

                <table class="form-table">
                    <tr valign="top">
                        <th style="white-space:nowrap;" scope="row"><label for="p75_post_types"><?php _e("Enabled for post types"); ?>:</label></th>
                        <td><input id="p75_post_types" type="text" name="p75_post_types" value="<?php echo $post_type_value; ?>" /></td>
                        <td style="width:100%;">The post types (post,page,custom_post_type) that this plugin is enabled for. Use commas to separate with no spaces.</td>
                    </tr>
                    <tr valign="top">
                        <th style="white-space:nowrap;" scope="row"><label for="p75_default_player_width"><?php _e("Default player width"); ?>:</label></th>
                        <td><input id="p75_default_player_width" type="text" name="p75_default_player_width" value="<?php echo get_option('p75_default_player_width'); ?>" /></td>
                        <td style="width:100%;">The default width of the video player if not set.</td>
                    </tr>
                    <tr valign="top">
                        <th style="white-space:nowrap;" scope="row"><label for="p75_default_player_height"><?php _e("Default player height"); ?>:</label></th>
                        <td><input id="p75_default_player_height" type="text" name="p75_default_player_height" value="<?php echo get_option('p75_default_player_height'); ?>" /></td>
                        <td>The default height of the video player if not set.</td>
                    </tr>
                    <tr valign="top">
                        <th style="white-space:nowrap;" scope="row"><label for="p75_jw_files"><?php _e("JW Player files location"); ?></label>:</th>
                        <td><input id="p75_jw_files" type="text" name="p75_jw_files" value="<?php echo get_option('p75_jw_files'); ?>" /></td>
                        <td>The location of the JW player files relative to your WordPress installation.</td>
                    </tr>
                    <tr valign="top">
                        <th style="white-space:nowrap;" scope="row"><a href="http://developer.longtailvideo.com/trac/wiki/FlashVars" title="<?php _e("What are flashvars?"); ?>" target="_blank"><?php _e("JW Player flashvars"); ?></a>:</th>
                        <td><input type="text" name="p75_jw_flashvars" value="<?php echo get_option('p75_jw_flashvars'); ?>" /></td>
                        <td>Extra parameters for JW player. For experienced users.</td>
                    </tr>
                </table>

                <input type="hidden" name="action" value="update" />
                <input type="hidden" name="page_options" value="p75_post_types,p75_default_player_width,p75_default_player_height,p75_jw_files,p75_jw_flashvars" />

                <p class="submit">
                    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
                </p>
            </form>
        </div>

    <?php
    }


    function ident_simple_video_plugin($blogopts) {
      $blogopts['simple_video_embedder'] =  array(
            'desc' => __( 'Press75 Simple Video Plugin 1.2' ),
            'readonly' => true,
            'option' => 'simple_video_embedder'
            );
      return $blogopts;
    }

    add_filter('xmlrpc_blog_options', 'ident_simple_video_plugin');

    /*-----------------------------------------------------------------------------END VIDEO PLUGINS------------*/
 ?>
share|improve this answer
    
Thank you for your answer. This code will definitely give me something to play with. This only answered a part of my question... but I found the plugin simple fields which I think should take care of the rest. –  Zach L Oct 16 '11 at 13:02
    
I went back and re-read your post. I think I understand more of what you are asking now: you have 10+ pages that will have more elaborate layouts. You do not want these page layouts to depend on the default page editor. I am going to post an additional anwer. –  endle.winters Oct 17 '11 at 17:04
    
Thanks Adam. I thought I had selected your 1st answer as correct already, and am doing so now. I'll change it accordingly when you post another answer. –  Zach L Oct 17 '11 at 17:09
    
oops,. you did. I just updated my existing answer with an extra link –  endle.winters Oct 17 '11 at 17:15
    
awesome thanks! –  Zach L Oct 17 '11 at 19:46

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.