Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • I think I may have something. Following my idea above and keesiemeijer’s point about the comments_template needing a $post object. The methodology is

    1. Create a new hidden custom post-type to which the comments are bound.
    2. Provide for basic post instance creation.
    3. By default the comments for will loop back to the post-types default url and not the referring page. Therefore we need to provide filters for get_comments_link.
    4. A wp_rewrite rule addition is needed to deal with paged comments
    5. Minimal wrapper to comments_template

    The key is creating some sort of deterministic link between a single term and a single post. The following is a proof of concept.

    define( 'CAW_TYPE', 'caw_stubb' );
    
    //ACTIONS
    add_action( 'init', 'caw_init', 100);
    
    //FILTERS
    add_filter( 'get_comment_link', 'caw_comment_link', 1, 3 );
    
    //INIT Function -- setup post type and wp_rewrite riles
    function caw_init() {
    
    	$singular = 'Comments Stub';
    	$plural = 'Comments Stubs';
    
    	$args = array(
    		'label' => $plural,
    		'labels' => array( 'name' => $plural, 'singular_name' => $singular, 'add_new' => 'Add '.$singular, 'add_new_item' => 'Add New '.$singular, 'edit_item' => 'Edit '.$singular, 'new_item' => 'New '.$singular, 'view_item' => 'View '.$singular, 'search_items' => 'Search '.$plural, 'not_found' => 'No '.$singular.' found', 'not_found_in_trash' => 'No '.$singular.' found in Trash', 'parent_item_colon' =>  $singular.': ' ),
    		'description' => 'Hidden post type used to bind any comment to',
    		'public' => false,
    		'capability_type' => 'post',
    		'supports' => array( 'title', 'trackbacks', 'custom-fields', 'comments' ),
    		'query_var' => false
    		);
    
    	register_post_type( CAW_TYPE, $args );
    
    	caw_add_rewrite_rules($rules);
    }
    
    //ADD wp_rewrite rules for all public taxonomies
    function caw_add_rewrite_rules($rules) {
    	$taxes = get_taxonomies( array(), 'objects');
    	foreach ( $taxes as $tax ) {
    		if ( $tax->public ) {
    			add_rewrite_rule(
    				$tax->rewrite['slug'].'/([^/]+)/comment-page-([0-9]{1,})/?$',
    				'index.php?'.$tax->query_var.'=$matches[1]&cpage=$matches[2]',
    				'top');
    		}
    	}
    	flush_rewrite_rules();
    }
    
    //FILTER get_comments_link to redirect from the hidden post types uri to the uri
    //uri of the dynamically generated term page.
    function caw_comment_link($link,$comment,$var) {
    	global $post;
    
    	if ( get_post_type() == CAW_TYPE ) {
    		$meta = get_post_custom();
    		$postlink = get_permalink($comment_post_ID);
    		$termlink = get_term_link( intval($meta['caw_term_id'][0]), $meta['caw_taxonomy'][0] );
    		$link = str_replace( $postlink, $termlink, $link );
    	}
    	return $link;
    }
    
    //RETURN the hidden post associated with a specific term object. Optionally
    //create that post if it does not already exist
    function caw_getstubb_term($term, $create=true) {
    	$oldposts = get_posts( array( 'name' => $term->taxonomy.'-'.$term->term_id, 'post_type' => CAW_TYPE ));
    	if ( count($oldposts) == 1 ) {
    		return $oldposts[0];
    	} elseif ( $create) {
    		$newpostid = caw_addstubb_term($term);
    		if ( !is_wp_error($newpost) ) {
    			return get_post($newpost);
    		} else {
    			return false;
    		}
    	} else {
    		return false;
    	}
    }
    
    //CREATE hiiden post associated with a specific term object. Record the parent term using
    //the post custom fields
    function caw_addstubb_term($term) {
    
    	$newpost = wp_insert_post(
    		array(
    			'post_title' => $term->name,
    			'post_name' => $term->taxonomy.'-'.$term->term_id,
    			'post_status' => 'publish',
    			'post_type' => CAW_TYPE
    			)
    		);
    
    	add_post_meta($newpost->ID, 'caw_taxonomy', $term->taxonomy, true);
    	add_post_meta($newpost->ID, 'caw_term_id', $term->term_id, true);
    
    	return $newpost;
    }
    
    //DISPLAY COMMENTS function. Retrieves hidden post & runs comments_template.
    // $file and $seperate are passed directly to comments_template.
    function caw_comments_template($term, $file='', $seperate=true, $create=true) {
    	global $post, $withcomments;
    	if ( isset($post) ) $oldpost = $post;
    	$post = caw_getstubb_term($term, $create);
    	$withcomments = "1";
    	comments_template( $file, $seperate);
    	if ( isset($oldpost) ) $post = $oldpost;
    }

    This is still very generic as it adds the possibility of comments on all public taxonomies. Ideally the creation of the hidden posts would be hooked into the creation/deletion of the original terms. However, I had to do this for a site redesign where those terms were already in
    existence.

    I was looking to do something similar. I haven’t solved it yet, but I did do some digging into the comments table. It appears that each comment is bound to an object in the wp_posts table. So I can see how comments can be added to any post inside a loop (whether its on a single page of not), but I can’t see how comments can be added when outside the loop — unless a specific post_id is supplied to bind them to.

    Theoretically it would be possible to create a hidden post type which mirrored the taxonomy terms. Any comments on a dynamic term page would then be bound to the equivalent instance of the hidden post type. It’s not something I’ve tried yet; I’m still hoping for an easier solution to present itself.

    Further to what Mike posted – one of the options for register_post_type is show_ui, set that to true and WordPress will automatically add the wp-admin menu for you. It’ll also handle all the add, deletion, etc for you.

    [Updated to add reference Mike’s post]

    That sounds something like a Custom Post Type (http://codex.ww.wp.xz.cn/Post_Types). The API allows you to define a new type of post/page of your own description and WordPress handles all standard UI and everything.

    You could have a “company” post type and set-up default Custom Fields to contain standard information. You are also able to set up custom taxonomies around them. Best of all it all appears under the Dashboard just like the post and page areas.

    It sounds a lot of work, but the backend handles pretty much everything.

    I had a problem with identical symptoms – the database upgrade would hang after a certain point. I looked into the code and found that it was the function pre_schema_upgrade() that was hanging. Specifically the MySQL statement:

    SELECT o1.option_id FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 ON o2.option_name = o1.option_name AND o2.option_id > o1.option_id

    (line 1685 of wp-admin/includes/upgrade.php)

    The upgrade code is looking for duplicated entries in the options database table to remove.

    When I ran that request in phpAdmin I got a result with 6 million lines, whereas there were only 400 odd lines with distinct option_name values. I added the work distinct after SELECT on that line forcing it to remove duplicate results. That seemed to work and allowed the upgrade to proceed as usual.

    I have the same issue – WP embedded within a larger site – but haven’t resolved it yet.

    I suspect it may be possible to use symbolic links so that the files are linked to different locations.

    The very quick and dirty way would be to dispense with themes entirely. It’s something I’ve always done – more for lack of time to themeize my site than anything else. What you can do is to put $wp_template_redirect = false; before your call to wp-blog-header.php. That will cause php to continue processing index.php looking for a wp rotor rather than looking in the themes directory.

    I then use output escaping

    ob_start();
    …wp-rotor, etc
    $results = ob_get_contents();
    ob_end_clean();

    to write the output of wordpress to the $results variable. I can then pipe that into my standard site wide template system. In fact I use output buffering several times to capture the various header and sidebar outputs.

    It’s not perfect and I really should use themes, but I found that it makes wordpress easier to embed within an existing site.

    Forum: Fixing WordPress
    In reply to: SQL error question
    Thread Starter jmkprime

    (@jmkprime)

    It isn’t really the Err 28 that is the problem (solving the cause of those is out of my hands). I just don’t want to these error reports to appear to the readers. What I’d really like to do is to be able to capture these reports and give instead feed the readers a standard “We care currently experience server difficulties , please come back late” message instead.

Viewing 8 replies - 1 through 8 (of 8 total)