Tag Archives: wordpress

Fixing the “Warning: array_merge() [function.array-merge]:” error in WordPress’s WP-Ecommerce plugin

When I first installed the WP-Ecommerce plugin on a website this morning and tried to go to the products page, I got this error:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /public_html/wp-content/plugins/wp-e-commerce/wpsc-core/wpsc-functions.php on line 622

Thankfully, it is actually very easy to fix this error. All you need to do is add (array) to the correct line of code in the plugin’s functions.php file.

Find this line in your wp-e-commerce/wpsc-core/wpsc-functions.php file:

$args = array_merge($wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page')));

And change it to this:

$args = array_merge((array)$wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page')));

 

That did the trick for me and hopefully will work for you too. Let me know if you have any questions or run into issues with this.

Get and display the most recent comments from your WordPress blog

Here is the code that I use to get and display the most recent comments from my WordPress blog:

<?php
$recent_comments = get_comments( array(
  'number'    => 5,
  'status'    => 'approve',
  'type'    => 'comment'
) );

foreach ($recent_comments as $comment)
{
?>
<li>
<a href="<?php echo get_permalink($comment->comment_post_ID);?>" title="<?php echo $comment->comment_author;?> on <?php echo get_the_title($comment->comment_post_ID); ?>">
<?php echo get_avatar( $comment->comment_author_email, '55' ); ?>
</a>
<p><b>
<?php echo($comment->comment_author); ?>
 said:</b></p>
<p>
<?php echo($comment->comment_content); ?>
</p>

<span style="font-size:12px;font-weight:bold;font-style:italic;">
<a href="<?php echo get_permalink($comment->comment_post_ID);?>#comment-<?php echo $comment->comment_ID;?>" title="<?php echo $comment->comment_author;?> on <?php echo get_the_title($comment->comment_post_ID); ?>">
<?php echo get_the_title($comment->comment_post_ID); ?>
</a>
</span>
</li>
<?php
}
?>
</div>

Let me know if you have any questions or need help customizing the code.

How to change your WordPress website’s password using phpMyAdmin

Here is the way that I use to change my WordPress site’s password if I am unable to log in or reset the password to the dashboard.

Log into phpMyAdmin.

Open your WordPress database.

Select the wp_users table and click Browse.

 

 

Now click Edit on the user whose password you want to change.

You will change the password in the row user_pass.

You will notice that WordPress stores the passwords as MD5 Hash rather than plain text.

This means that you will need to use an MD5 generators online to generate your password. I use JavaScript MD5. Simply type your password in the tool and generate MD5 results.

Copy and paste the code you get from the converter into the user_pass field and click Go to save the new password.

Let me know if you run into any issues or have any questions.

WordPress Tricks: How to exclude a certain category of posts from the loop

Use this line of code to control which categories of posts do and don’t show up in the loop for particular pages on your WordPress site:

<?php
if (is_page('recipes')) {
 $catID=4;
}
elseif (is_home()) {
 $catID=-4;
}
if ($catID) {
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 query_posts("cat=$catID&paged=$paged");
} ?>

Copy and paste that code into your index.php or page.php template file, just before the loop is called.

This line of code will display all posts in category 4 on the recipe page, and not on the main blogroll page.

Simply change the page IDs (or slugs, either one will work) and the category IDs to control which pages show which category of posts.

To exclude a category of posts from the loop on a certain page, simply put a negative sign ( – ) in front of the category ID you want to exclude from that page, and the page will show posts from all categories except for that one.

If you want to specify which page each category of posts show up on, you would use this:

<?php
$catID = 0;
if (is_page('Books')) {
 $catID=1;
}
elseif (is_page('Videos')) {
 $catID=4;
}
elseif (is_page('CDs')) {
 $catID=5;
}
if ($catID) {
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 query_posts("cat=$catID&paged=$paged");
} ?>

 

Let me know if you have any questions, need more help,  or run into any problems.

Displaying Snippets of Code Correctly in WordPress Posts

Anyone who has ever tried to insert a line or block of code into their WordPress posts knows firsthand how frustrating it can be to get the code to display correctly – without funny characters, or lines running off the page, etc. Here is the method I use to get blocks of code to display correctly in a post.

Copy and paste this code into your stylesheet:

pre  {
font-family: courier,"courier new",monospace;
font-size: 12px;
overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
/* width: 99%; */
word-wrap: break-word; /* Internet Explorer 5.5+ */
  }

Now, the next time you add a line of code to your posts, simply highlight the code, and select “Preformatted” rather than “Paragraph” in the drop down menu at the top of your post box.

Or – if you prefer to work with the HTML directly, add the tags <pre> and </pre> around the line or block of code that you are trying to style.

And of course, you can further customize the way codes display in your WordPress posts by adding background color, borders, etc. to the <pre> element in your stylesheet.

Let me know if you have problems or questions.

WordPress: How to show a div on only certain pages

Here is the code you can use to show a <div> on only the pages that you want it to be shown on:

<?php if( is_page(home) ) { ?> 
<div> This is the div that will only show up on the page named 'Home' </div> 
<?php } ?>

You can also have it show up on every page except for a particular page:

<?php if( !is_page(home) ) { ?>
<div> This is the div that will only show up any page that is NOT named 'Home' </div> 
<?php } ?>

Let me know if you have any questions or trouble with this at all.