Mar
02
2012
0

WordPress Pages & Posts not showing

If when you load the wordpress admin none of your pages & posts are showing, do the following:

  1. Edit wp-config.php and add
    define('WP_ALLOW_REPAIR', true);
    
  2. Open the database repair URL
    HOSTNAME/wp-admin/maint/repair.php

This should force an upgrade of the database. Remember to remove the line from wp-config after running the upgrade.

Written by Pete in: wordpress |
Aug
04
2011
0

Load WordPress Admin to Blank Page

When you load yoursite.com/wp-admin you just get a blank page.

Open functions.php and remove the white space at the top and bottom.

Written by Pete in: wordpress |
Jul
07
2011
0

Find Most Recent Comments

To find the most recent comments in WordPress use the following code:


$number=30; // number of recent comments desired
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo sprintf(__('%1$s on %2$s'), get_comment_author_link(), '' . get_the_title($comment->comment_post_ID) . ' - ') . $comment->comment_date;
endforeach;
endif;

Written by Pete in: wordpress |
Jul
07
2011
0

Find the most recent posts from a specific category

In WordPress sometimes you will want to show the most recent post from a specific category.

To do this use the following code:


global $post;
//change the category=1442 to the category number you want to pull the content from
//change numberposts=1 to the number of posts you want to return from the category
$myposts = get_posts('numberposts=1&category=1442&order=DESC');
foreach($myposts as $post) :
setup_postdata($post);
$catpost= " ". get_the_title() ."";
endforeach;

echo $catpost;

Written by Pete in: wordpress |
Jul
07
2011
0

Store the_permalink() as a variable

The wordpress function the_permalink() automatically echos the content to the screen.

Sometimes you want to store this value in a variable.

In this case use:


$string = get_permalink();

Written by Pete in: wordpress |
Jul
07
2011
0

Store the_title() in a variable

The wordpress function the_title() automatically echos the content to the screen.

Sometimes you want to store this value in a variable.

In this case use:


$string = get_the_title();

Written by Pete in: wordpress |
Apr
23
2011
0

Unable to locate WordPress Content directory (wp-content)

When you try to update/install a WordPress plugin you get the following error:

“Upgrade Plugin: Unable to locate WordPress Content directory (wp-content)”

Add the following code to the end of your wp-config.php file:
if(is_admin()) {
add_filter('filesystem_method', create_function('$a', 'return "direct";' ));
define( 'FS_CHMOD_DIR', 0751 );
}

Written by Pete in: wordpress |
Sep
16
2010
0

WordPress Super Cache 403 Forbidden

When trying to access cached pages in WordPress you receive a 403 Permission Denied or 403 Forbidden error.

To fix you must add the following line to your wp-config.php (Add it above the WP_CACHE define.) Then clear your cache.
umask( 0022 );

If your PHP runs as a different user to Apache and permissions are strict Apache may not be able to read the PHP generated cache files.

Written by Pete in: wordpress |
Oct
08
2008
0

How to highlight sourcecode in WordPress

The SyntaxHighlighter Plus plugin allows you to highlight different types of code within your wordpress posts:

CSS example

pre {
white-space: pre-wrap;       /* css-3 */
white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
white-space: -pre-wrap;      /* Opera 4-6 */
white-space: -o-pre-wrap;    /* Opera 7 */
word-wrap: break-word;       /* Internet Explorer 5.5+ */
}

PHP example

<?php
$block = module_invoke('block', 'block', 'view', 7);
print $block['content'];
?> 

The module states it works upto WordPress 2.5 however it is working without any problems on 2.6.

It supports the following languages (the alias for use in the post is listed next to the name):

  • Bash — bash, sh
  • C++ — cpp, c, c++
  • C# — c#, c-sharp, csharp
  • CSS — css
  • Delphi — delphi, pascal
  • Java — java
  • JavaScript — js, jscript, javascript
  • PHP — php
  • Python — py, python
  • Ruby — rb, ruby, rails, ror
  • SQL — sql
  • VB — vb, vb.net
  • XML/HTML — xml, html, xhtml, xslt
Written by Pete in: wordpress |

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes