Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • My directions were very poor. Let me try again:

    1) Under Options >> Permalinks, Set your Category Base to /category

    2) Use the following hack (modified from bloggerholic), that removes the base category from links (unless it’s a multi-page link). Find the function “get_category_link($category_id)” in category-template.php (in the wp-includes folder) and insert the following hack, like so…

    function get_category_link($category_id) {
    	global $wp_rewrite;
    	$catlink = $wp_rewrite->get_category_permastruct();
    	///////// ADD FOLLOWING LINE ///////
    	if (!(isset($_GET['paged']) && !empty($_GET['paged']))) $catlink = str_replace('/category', '', $catlink);
    	///////////////////////////////////

    3) Next, you have to fix the multi-page problem that results from the above hack. For some reason, multi-page permalinks require a Category Base. So we have to add the category base back in for the function that produces the link to page 2, next_posts(). Make the following change to the link_template.php (in the wp-includes folder):

    function next_posts($max_page = 0) {
    	//////// ADD THE FOLLOWING LINES ////////
    	$the_unmodified_link = clean_url(get_next_posts_page_link($max_page));
    	if (preg_match('/category/', $the_unmodified_link)) echo $the_unmodified_link;
    	else echo preg_replace('/yourdomain\.com/' ,'yourdomain.com/category', $the_unmodified_link);
    	/////// COMMENT OUT ORIGINAL CODE ////
    	// echo clean_url(get_next_posts_page_link($max_page));
            /////////////////////////////////////
    }

    Notes:

    1) replace yourdomain.com, with your domain, but do not prefice with www, and also escape non-alphanumeric characters (such as . and /)
    2) You can see an example of this hack working on my site, but it has two excpetions: wordpress is installed in a subdirectory, and the Category Base was changed to archive/, so the exact code I used is a little different, so the resulting links are harvardmagazine.com/web/breaking-news for page 1 and harvardmagazine.com/web/archive/breaking-news/page/2

    Hope that was more clear Charbax.

    I came up with a hack that fixes the multi-page problem. (You can see how it working here: http://harvardmagazine.com/web/breaking-news)

    1) Use a hack from bloggerholic, that removes the base category from links. You have to edit category-template.php like so:

    function get_category_link($category_id) {
    	global $wp_rewrite;
    	$catlink = $wp_rewrite->get_category_permastruct();
    	///////// ADD THIS LINE
    	if (!(isset($_GET['paged']) && !empty($_GET['paged']))) $catlink = str_replace('/category', '', $catlink);
    	//////////

    2) And then to fix multi-page links that are broken by the previous hack, I just modify the “next page” link to put the category base back in, which paged archives require to function. Make the following change to link-template.php :

    function next_posts($max_page = 0) {
    	//////ADD THE FOLLOWING LINE
    	$the_unmodified_link = clean_url(get_next_posts_page_link($max_page));
    	if (preg_match('/archive/', $the_unmodified_link)) echo $the_unmodified_link;
    	else echo preg_replace('/web/' ,'web/archive', $the_unmodified_link);
    	/////// COMMENT OUT ORIGINAL CODE:
    	// echo clean_url(get_next_posts_page_link($max_page));
    }

    And that’s it! I actually used the category base “archive/” instead category, cause it makes more sense for the second and third pages to be under archives, and the rest not. (And wordpress is located in the “web” directory to keep it separate from the rest of the website as well). You can see how it works here: http://harvardmagazine.com/web/breaking-news

    I don’t think it messes up anything else, but you might want to test it yourself as well.

    I have also run into this problem. The best way to get around the second issue you’ve raised is to use <?php bloginfo('url'); ?> on all of your links.

    The function comments_template() checks to see if the call is for a single post or page, or, as Tunneleram suggest, $withcomments is true.

    if ( ! (is_single() || is_page() || $withcomments) )
     return;
    blaisefreeman

    (@blaisefreeman)

    I use custom comment.php files, so I’m not sure what variables your theme will use, but I just add

    <?php
      $post_id = $post->ID;
      $comments = get_approved_comments($post_id);
    ?>

    to the beginning of my comments.php file. You should at least check out the function I mentioned: get_approved_comments().

    I think wordpress runs a query that performs that function before single.php is called, so calling this function directly does the same thing. That’s just speculation, though. Either way, it works for me.

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