Forum Replies Created

Viewing 15 replies - 1 through 15 (of 36 total)
  • Thread Starter CounterDax

    (@counterdax)

    I’ll just keep documenting what I’ve discovered, just in case someone else needs some help with this too…

    The nested comments require a function that inserts two hidden input fields for the comment form to parse. When nested comments are turned off, or not supported in the comments template, these variables are still parsed and handled when submitting a comment. So, create a template lacking nested comments, add these two fields manually to the comment form, add WordPress’ nested comment handling javascript and the reply links manually too, and everything works. You’re still required to add the other necessities for nested comments, such as keeping the div id’s the same, adding the cancel link, etc.

    Add the following to the comment form:

    <input name="comment_post_ID" value="<?php echo $post->ID; ?>" id="comment_post_ID" type="hidden">
    <input name="comment_parent" id="comment_parent" value="0" type="hidden">

    Either use WordPress’ queue script function (along with wp_head()) as follows:
    <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
    Or add the script manually to the head or just below the end of the body:
    <script type="text/javascript" src="<?php echo get_option('siteurl'); ?>/wp-includes/js/comment-reply.js"></script>

    Manually add the reply link to the comments:
    <a class="comment-reply-link" href="?replytocom=<?php comment_ID(); ?>#respond" onclick="return addComment.moveForm('comment-<?php comment_ID(); ?>', '<?php comment_ID(); ?>', 'respond', '<?php echo $post->ID; ?>')">reply</a>

    Now to show that a comment is a reply to a previous comment:

    <?php
    if ( $comment->comment_parent ) {
    	$parent = get_comment( $comment->comment_parent );
    	$parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
    	printf( ' in reply to <a href="%1$s">%2$s</a>', $parent_link, $parent->comment_author );
    } ?>

    What’s next:
    This is quite a cumbersome way to manage all this, and I think there’s probably an easier way to pull boing-boing style non-nested nested comments off.
    The “in reply to” link now jumps the user to the original comments, lacking a link back to the comment reply. I’m now working on some simple javascript to show a ‘return to reply’ link.

    Are you sure you are handling special characters like @ correctly, both in your Javascript and in PHP? @ has special meaning in certain cases, such as in some regular expression handlers, etc.

    More info, like the scripts involved, might help someone tracing the error down.

    So, I believe you want to grab the content of a page and output it in a certain location? This is possible by creating a new WP-Query class, but this does mean you’re making an extra database request, so use sparingly.

    <?php
    // Create second WordPress loop
    $page_content = new WP_Query( 'pagename=page-slug' );
    
    while( $page_content->have_posts() ) : $page_content->the_post();
    	// Your content output goes here
    	echo '<h2>';
    	the_title();
    	echo '</h2>';
    	the_content();
    endwhile;
    
    // Don't forget to reset the post data!
    wp_reset_postdata();
    ?>

    Also see the codex entry of WP_Query

    Do watch out with using the is_front_page() function since in some cases, such as with custom front pages, it will also return true when on a custom articles front page (thus not only the cover front page)…

    In that case, you can filter for the page name, too:

    <title><?php
    if( is_page('page-slug-or-name-or-id') ) {
      echo 'unique title tag';
    } ?></title>

    Mix and match till you get what you want.

    Thread Starter CounterDax

    (@counterdax)

    Well, one way I might do it is by creating an array of all the comments based upon ‘date’=>’formatted comment’, resorting the array based on the date (timestamp) and then outputting everything in my custom comment formatting function. However, my concern is that this might be quite processing intensive (especially with many comments, CPU and bandwidth resources rise) so I was hoping there’s a better way to pull this off.

    Anyone?

    Thread Starter CounterDax

    (@counterdax)

    Solved… I used an action and a filter to turn wrap all ampersands in the title with <em> tags. That was causing the problem. I should just remove this, specify more clearly when to do this, or pull the titles from the db separately in my theme files. For now I just turned it off.
    Again, thanks so much!

    Thread Starter CounterDax

    (@counterdax)

    Yes, it is most likely the theme! I switched to the default theme and everything worked just fine! I’ll have to go over the code in my theme, carefully… but I produced it from the ground up and I have no idea how it could mess it up. First stop, check the functions.

    I really appreciate the help! You put quite a lot of effort in this problem. FIrst I’m going to fix my problem and then crawl down the support forum to see who I can help in return.

    Thread Starter CounterDax

    (@counterdax)

    Akismet and some completely unrelated plugins. I’ve already went through the process of deactivating them and checking. I really have no idea what’s going on.

    Thread Starter CounterDax

    (@counterdax)

    Quite strange… I still only see the titles, no content. I’ve tried two different computers with different RSS readers.

    For all PHP newbies: Just move `// this is where the Lead Story image gets printed
    $values = get_post_custom_values(”leadimage”);` to before the start of the image element and wrap everything up in an if statement if you want to check whether the image actually exists.

    Out of my head:

    <?php $values = get_post_custom_values("leadimage");
    if(!empty($values)) { ?>
    
    <img src=”<?php bloginfo('url'); echo '/'; echo get_option('upload_path'); echo '/';
    echo $values[0]; ?>” alt=”leadimage” id=”leadpic” /></a>
    
    <?php } // end leadimage ?>

    I see that there must be an anchor (<a href=) before the image. Don’t forget to paste that, too.

    Thread Starter CounterDax

    (@counterdax)

    Well, I did it. Haochi, I listened to your advice and I’m nearly done with coding everything as a direct connection to the DB. Thanks.

    Forum: Fixing WordPress
    In reply to: Printing my blog

    Nirwin, usually your browser filters out backgrounds and such when sending the page to the printer queue. It’s most likely a browser problem.
    Another option might be that the stylesheet is set to screen — <link rel="stylesheet" href="https://[the entire url here]/style.css" type="text/css" media="screen" /> — (which is the preferred behavior), or that there is a some styling included for the printer.

    As far as I can tell, the “leadimage” is a custom key and should thus have a value referring to the image itself (an URL).
    When you write a new post (or edit a current one), open the little area marked CUSTOM FIELDS, type leadimage in the field for key, and type an URL to an image in the value field.

    I just wonder why $values is an array…

    Thread Starter CounterDax

    (@counterdax)

    Well, I am using some WP template tags in the code, such as get_year_link() and the_permalink()… it’s going to be hard to work around that.

    The following does work… it’s an adaptation of the tagcloud widget, rewritten to display a dropdown list. It needs some cleaning up but it worked in 2.3.2 (have not tried 2.5 yet):

    Just throw the following in your functions.php template file.

    function dropdown_tag_cloud( $args = '' ) {
    	$defaults = array(
    		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
    		'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
    		'exclude' => '', 'include' => ''
    	);
    	$args = wp_parse_args( $args, $defaults );
    
    	$tags = get_tags( array_merge($args, array('orderby' => 'count', 'order' => 'DESC')) ); // Always query top tags
    
    	if ( empty($tags) )
    		return;
    
    	$return = dropdown_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
    	if ( is_wp_error( $return ) )
    		return false;
    	else
    		echo apply_filters( 'dropdown_tag_cloud', $return, $args );
    }
    
    // $tags = prefetched tag array ( get_tags() )
    // $args['format'] = 'flat' => whitespace separated, 'list' => UL, 'array' => array()
    // $args['orderby'] = 'name', 'count'
    function dropdown_generate_tag_cloud( $tags, $args = '' ) {
    	global $wp_rewrite;
    	$defaults = array(
    		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
    		'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC'
    	);
    	$args = wp_parse_args( $args, $defaults );
    	extract($args);
    
    	if ( !$tags )
    		return;
    	$counts = $tag_links = array();
    	foreach ( (array) $tags as $tag ) {
    		$counts[$tag->name] = $tag->count;
    		$tag_links[$tag->name] = get_tag_link( $tag->term_id );
    		if ( is_wp_error( $tag_links[$tag->name] ) )
    			return $tag_links[$tag->name];
    		$tag_ids[$tag->name] = $tag->term_id;
    	}
    
    	$min_count = min($counts);
    	$spread = max($counts) - $min_count;
    	if ( $spread <= 0 )
    		$spread = 1;
    	$font_spread = $largest - $smallest;
    	if ( $font_spread <= 0 )
    		$font_spread = 1;
    	$font_step = $font_spread / $spread;
    
    	// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
    	if ( 'name' == $orderby )
    		uksort($counts, 'strnatcasecmp');
    	else
    		asort($counts);
    
    	if ( 'DESC' == $order )
    		$counts = array_reverse( $counts, true );
    
    	$a = array();
    
    	$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
    
    	foreach ( $counts as $tag => $count ) {
    		$tag_id = $tag_ids[$tag];
    		$tag_link = clean_url($tag_links[$tag]);
    		$tag = str_replace(' ', '&nbsp;', wp_specialchars( $tag ));
    		$a[] = "\t<option value='$tag_link'>$tag ($count)</option>";
    	}
    
    	switch ( $format ) :
    	case 'array' :
    		$return =& $a;
    		break;
    	case 'list' :
    		$return = "<ul class='wp-tag-cloud'>\n\t<li>";
    		$return .= join("</li>\n\t<li>", $a);
    		$return .= "</li>\n</ul>\n";
    		break;
    	default :
    		$return = join("\n", $a);
    		break;
    	endswitch;
    
    	return apply_filters( 'dropdown_generate_tag_cloud', $return, $tags, $args );
    }
    ?>

    And wherever you want to display the dropdown list:

    <select name="tag-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
    	<option value="#">Most Used Tags </option>
    	<option value="<?php bloginfo('url'); ?>/?pagename=tags">All Tags</option>
    <?php dropdown_tag_cloud('number=10&orderby=count&order=DESC'); ?>
    </select>

    The function dropdown_tag_cloud() takes all the same arguments as tag_cloud() since it is actually a copy of tag_cloud() with just some minor changes.

Viewing 15 replies - 1 through 15 (of 36 total)