Richard Castera - Explorations in Software Development
Richard Castera - Explorations in Software Development
Browsing Category
Resources Scripts

Drupal – Use hook_form_alter() to set redirect path on the form

March 2, 2010 2 Comments

One popular use of this hook is to change the destination of a form submission. Here is how it is accomplished:

PHP
1
2
3
4
5
6
7
8
9
10
11
<?php
function YOURMODULE_form_alter($form_id, &$form) {
  switch ($form['#id']) {
    case 'node-form':
       if ($form['type']['#value'] == 'story') {
         $form['#redirect'] = 'new/url';
       }
     break;
  }
}
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Excellent Analytics – Import Google Analytics into Excel

March 1, 2010 2 Comments

I ran into this nice Excel Plugin that lets you import web analytics data from Google Analytics into a spreadsheet. It’s an open source project and 100% free to download and use for individuals and businesses.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

WordPress – List Scheduled Posts

February 28, 2010 2 Comments

If you ever wanted to show you readers posts that are scheduled to be published, here’s how to do it.

PHP
1
2
3
4
5
6
7
8
<?php
$result = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($result->have_posts()) {
    while ($result->have_posts()) : $result->the_post(); ?>
        <?php the_title(); ?>
    <?php endwhile;
}
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

CSS – Cross Browser Opacity

February 27, 2010 1 Comment

A little hack to set Cross-Browser opacity.

CSS
1
2
3
4
5
6
7
.setOpacity {
      opacity: .75; /* Standard: FF gt 1.5, Opera, Safari */
      filter: alpha(opacity=75); /* IE lt 8 */
      -ms-filter: "alpha(opacity=75)"; /* IE 8 */
      -khtml-opacity: .75; /* Safari 1.x */
      -moz-opacity: .75; /* FF lt 1.5, Netscape */
}
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

WordPress – Disable Auto Save

February 24, 2010 1 Comment

WordPress’s Auto-Save feature is a really nice but there are some drawbacks… this feature increases your database usage. So for those of you that are on really bad shared hosting accounts or just want to turn it off, here’s a quick way of doing it.

Open and insert the following line in your wp-config.php file.

PHP
1
define('WP_POST_REVISIONS', false);

Another method is to remove all of the entries from the database from time to time. You can do tun this query to do it:

PHP
1
DELETE FROM wp_posts WHERE post_type = "revision";
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Prototype JS – Determine if an object exists in the page loaded

February 23, 2010 No Comments

I’m so use to using jQuery that I usually don’t have to look up documentation on how to use certain functions. They almost come naturally because it’s so English-like! Unfortunately Magento uses Prototype as it’s native choice of Javascript Frameworks. I sure wish they would have chosenjQuery! I think they would have more people jumping on their platform. I’m sure they have a good choice for it. Anyway, here’s how to check:

JavaScript
1
2
3
if ($('id_of_element') != undefined) {
    alert('Object exists.');
}
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – Check if a User is logged in

February 23, 2010 6 Comments

You may want to check if a user is logged in with Magento, possibly to display a link or promotional item. Here’s how to do it:

PHP
1
2
3
4
5
6
7
8
<?php
if ($this->helper('customer')->isLoggedIn()) {
    echo("Anonymous user");
}
else {
    echo("Authenticated user");
}
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Magento – How to Display the Product SKU

February 23, 2010 4 Comments

Magento is a pretty flexible platform. That flexibility comes with a price though; You have to be knowledgeable of the functions that are available to you to utilize. Finding or knowing them is a challenge though. Here is one of those such functions that you may need to display the product Sku on a category page.

PHP
1
<?php echo($_product->getSku()); ?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts Web Server

How to Create a Custom 404 Error page with .htaccess

October 20, 2009 2 Comments

Everyone’s encountered those standard 404 error pages that yield little or no information. Most new systems have this feature built in by default and often times are pretty fancy with informative to funny graphics and lots of options on what to do next but, if your working on updating an old site not using dynamically based web pages then, your going to have to add one manually. For your user’s experience, it’s better to provide a helpful error message and links to where they can continue on their quest for information. You don’t want to scare your visitors away do you? Here’s how to add your own custom 404 error page to your website:

If you don’t already have an .htaccess file in your servers root, go ahead and create one. Now you need to instruct .htaccess where your custom error page is. In this example, I have the 404 document which I created with my editor that provides lots of useful information for users to continue browsing my site. Now add this line to your .htaccess file and that’s it!

Apache
1
ErrorDocument 404 /404.html
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts Web Server

Disallow hotlinking while allowing requests from robots.txt and favicons

October 18, 2009 No Comments

We all hate Leechers. Here’s how to stop them in their tracks from stealing your images and your bandwidth!

Apache
1
2
3
4
5
6
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(^/robots\.txt|\.ico)$
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp|pdf)$ [F,L]
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Page 4 of 11« First...«3456»10...Last »

About me

Hello, my name is Richard Castera. I have more than 12 years of experience architecting, implementing, leading and launching large scale, high performance software products in a fast-paced agile environment.

Popular Posts

Magento – Display new products on the home page

May 20, 2009

How to Fix “Internet Explorer Cannot Open the Internet Site- Operation Aborted” Error

May 9, 2009

PHP – Convert Array to Object with stdClass

July 5, 2009

Categories

  • Home Automation
  • Resources
  • Scripts
  • SEO
  • Thoughts
  • Web Server

Tags

Apache Apple Bash CSS Drupal Free home automation htaccess Java Javascript Magento PHP raspberry pi SEO SQL thoughts Wordpress

© 2019 copyright Richard Castera // All rights reserved