scriptygoddess

14 Sep, 2008

New Theme

Posted by: Jennifer In: Announcements

Finally decided on a theme. I do have some thoughts for making one of my own, but I still have no time to do it. (And when I do have time, I'm usually too exhausted to want to work on it) SO, I've been shopping around for something to use in the interim. This one does the job. Simple, clean, yet still pretty cool, IMHO. :)

Thank you to Bytes For All for the free theme. :)

Comments Off on New Theme

Here's a method you can use with the validation jQuery plugin to make sure a field (like a password field) includes at least one number.

$.validator.addMethod("atleastonedigit", function(pass) {
if (pass == "") {
return true;
}
return ((/[0-9]+/).test(pass));
}, "This field must contain at least one number");

13 Aug, 2008

Scriptygoddess Forums

Posted by: Jennifer In: Announcements

Just wanted to post that I've created a forum for shopping carts, scripts, etc. here:
scriptygoddess.com/discussion

I've just started filling some forums/categories in there – so if you want to see a specific forum for something – let me know. I thought it might make sense to create a forum for topics that needed more of a discussion – something that I didn't think was as easily accomplished with single threads in a blog post… Anyway, hopefully it will be useful and helpful. We'll see how it goes.

Comments Off on Scriptygoddess Forums

24 Jul, 2008

Show full post if there is no excerpt

Posted by: Jennifer In: Bookmarks

As the title said – needed to show the excerpt if there was one, or the *full* post if there wasn't (not the shortened version wordpress "fakes")

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
if (get_the_excerpt() == "") {
echo apply_filters('the_content',get_the_content());
} else {
echo apply_filters('the_content',get_the_excerpt());
echo '<p><a href="'.get_permalink().'">Read more...</a></p>';
}

Updated 8/11/08 Made some changes to the code. Excerpts were coming in unformatted, also removed some extra stuff I don't think I needed in there…

14 Jun, 2008

Moving a WordPress Install

Posted by: Jennifer In: WordPress|WordPress Hacks

One of my clients recently purchased new servers and wanted to migrate all their sites to the new servers. Some of these sites were wordpress powered. Thankfully, I found this article that made the move a breeze.

The critical thing I want to save for my future reference is the following sql lines from that post:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

See the post on My Digital Life for the full instructions :)

Updating to add… There's another SQL line that will be helpful if you have any custom fields that have direct paths to images or files on your old server…

UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.old-domain.com', 'http://www.new-domain.com');

Same project I just mentioned below – something funky was going on with WordPress not sending emails. I had a server admin looking at the server and I'd submit a comment on the corporate blog and no emails would get sent. I even tried using a plugin that forced wordpress to use SMTP, still would not send emails from the blog.

I found on the support forums where someone mentioned a hack to get WordPress to use sendmail. In wp-includes folder open the file pluggable.php. Around line 362 is the following:

// Set to use PHP's mail()
$phpmailer->IsMail();

Change that to:
// Set to use PHP's mail()
//$phpmailer->IsMail();
$phpmailer->IsSendmail();

As soon as I did that – voila – it started sending emails.

(yes, I know, I'm modifying core code again. Tell me how to make this a plugin and I will!)

I had a site I was using WordPress for – and it actually involved two separate installs. One install was set up as the main content management for the site. Pages were obviously the pages of the site. Posts were for news and Press Release articles. A separate install was for the "corporate blog."

I had one page where I listed the news and PR items, and I was asked to also list the latest blog posts on that page as well. Since the blog was actually an entirely different install, this presented the problem. The critical issue here is that both WordPress installs are in the same database – just with different prefixes. This makes the problem pretty easy to deal with.

So just to go over the other aspect of the page – listing the news and Press Releases – that is simple. I get the id of the categories (lets say that news has an id of '5' and PR has and id of '6') on the page template I create especially for that page I have the following:

<h3>News</h3>
<?php
global $post;
//category=5 - this is the id for news
$myposts = get_posts('numberposts=5&category=5');
foreach($myposts as $post) :
?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
<em><?php the_time('F jS, Y') ?></em></p>
<?php endforeach; ?>
<h3>Press Releases</h3>
<?php
global $post;
//category=6 - this is the id for Press Releases
$myposts = get_posts('numberposts=5&category=6');
foreach($myposts as $post) :
?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
<em><?php the_time('F jS, Y') ?></em></p>
<?php endforeach; ?>

Now to pull in the post content from the other blog – you need to a swap in the prefix you're using for the other install (where I have "BLOGPREFIX" below). Also had to manipulate the URL given by "get_permalink()". See my note below in the code.

<h3>Blog Posts</h3>
<?php
$querystr = "SELECT * FROM BLOGPREFIX_posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC limit 5";
$blogposts = $wpdb->get_results($querystr, OBJECT);
if ($blogposts): ?>
<?php foreach ($blogposts as $post): ?>
<?php setup_postdata($post); ?>
<?php /*
Normally you use the_permalink() to display the URL -
but that would show the post as if it was part of the
current blog. In my case, the blog was actually set up
as a subdomain. There may be a better way to do this but
I just stripped out the domain and replaced it with the
blog's subdomain. See below */
$newpermalink = str_replace("http://www.MYDOMAIN.com","http://BLOG.MYDOMAIN.com",get_permalink()); ?>
<p><a href="<?php echo $newpermalink; ?>"><?php the_title(); ?></a><br />
<em><?php the_time('F jS, Y') ?></em></p>
<?php endforeach; ?>
<?php else : ?>
<p> Not Found</p>
<?php endif; ?>

That will pull the last 5 blog entries – with the title linked to the post and the date below it.

13 May, 2008

Proportional Scaling Calculator

Posted by: Jennifer In: Javascript|Scripts

I'm sure this has been done before since it's pretty simple – I just couldn't find it quick enough when I needed it. And since it is so simple, it was easier to just create my own personal little calculator than dig around, find one, bookmark. (or worse yet, do the math on a little sticky note next to my computer) ;P

This calculator will let you enter in the original width and height of an image (or document, video or whatever). Then you enter the width (or height) of the size you need it scaled to (down or up). And it will tell you what the other side needs to be.

For example: I have an 800×600 image – I need it scaled down to fit in a 256 width area… what height will I need to make it? This tool will answer your question.

Proportional Scaler Calculator

03 May, 2008

Phone number validation with jquery

Posted by: Jennifer In: Javascript|jquery

One of the things I've been playing around with a lot recently is jquery. Why I didn't jump on this bandwagon sooner, I'm not sure, but I am kicking myself for it. So I am still a bit of nub on the jquery front – but I like to think I pick things up quickly. 😀

So one thing I am now using jquery regularly for is form validation. Previously, form validation used to mean a lot of script writing, not to mention a fair amount of dread.

Now it's quite painless.

My current usage of that plugin is pretty basic until I get a better handle of it. But one thing that I have been requested a number of times, is to add validation for a phone number – which is not included in that plugin. I'm not sure this is the "right" or best way to do it – but it does work. :)

The functions are basically the same as those provided here with some minor modifications and altered to be used with the jquery plugin.

First of course you include the jquery javascript file:
<script language="javascript" type="text/javascript" src="/js/jquery.min.js"></script>

Then the validation plugin:
<script type="text/javascript" src="/js/jquery.validate.pack.js"></script>

Then you add the function to check the phone number:
<script type="text/javascript">
$.validator.addMethod("phone", function(phone_number, element) {
var digits = "0123456789";
var phoneNumberDelimiters = "()- ext.";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;
s=stripCharsInBag(phone_number,validWorldPhoneChars);
return this.optional(element) || isInteger(s) && s.length >= minDigitsInIPhoneNumber;
}, "Please enter a valid phone number");

Some "helper" functions:
function isInteger(s)
{ var i;
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
function stripCharsInBag(s, bag)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

Then the line that makes the jquery run:
$(document).ready(function() {
$("#myform").validate();
});
</script>

To use the jquery validation plugin – I was just adding "required" as a class to those fields that were required. Like this:
<input type="text" name="FirstName" class="required" />

You can check email structure by also adding the class "email".
<input type="text" name="EmailAddress" class="required email" />

And now, using the code above, if you add the class "phone" – it will check a phone number.
<input type="text" name="PhoneNumber" class="required phone" />

(My code above allows for some additional characters beyond just numbers – so that it will accept parens around the area code – dashes or periods between the numbers and "e" "x" "t" characters as well – in case someone needs to include an extension.)

Typical disclaimer – like I said – I'm still a nub at jquery. There may be a better/easier way to do the above, so as always feel free to chime in if you know what that better/easier way is…

Updated 5/5/08 I do see a "phone" method in the "additional-methods.js" file… but I needed it do things a little differently… (like allowing extension numbers etc.)

Updated 5/29/08 Had some issues with the method not allowing phone fields to be optional and only checking the values if something was entered (when optional). Fixed that now.

Updated 7/1/08 As JT noted in the comments with regex this can be simplified. JT provided the following code:
function isValidPhoneNumber(ph) {
if (ph == null) {
return false;
}
var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");
// 10 is the minimum number of numbers required
return ((/\d{10,}/i).test(stripped));
}

So to update the jquery:
$.validator.addMethod("phone", function(ph, element) {
if (ph == null) {
return false;
}
var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");
// 10 is the minimum number of numbers required
return ((/\d{10,}/i).test(stripped));
}, "Please enter a valid phone number");

And then you can loose the other "helper" functions. (Thanks JT!!)

Awhile back, I had a project where I created a nice clean (X)HTML page including navigation using UL and LI tags. A few months later the client decided they wanted to add a dropdown menu to the navigation. No problem, I thought. We just add the embedded lists to the navigation – style it with CSS – and use the Suckerfish dropdown menu technique. Easy Peasy.

Except when I implemented it, the drop down menus were showing up BEHIND the rest of the content instead of "above/over it".

There was a lot of other things going on in the page, I have a simple example that demonstrates the issue.

I'm sure it makes sense somehow, if I had a better grasp of what "position: relative" does to the document – beyond that "position: relative" allows items INSIDE a relatively positioned block to be absolutely positioned WITHIN it (which is why I had done that). The side effect though is that it does that crazy thing with the menu.

Oh the HOURS and HOURS to figure that out…. /sigh.

Here is the same page – with just that one line (position: relative) removed.

I've now seen this problem crop up a few times. In one case, I was working with a design that I had not originally created and even though there were no "position: relative" in any of the css files – the only way to get the menu to be ABOVE the content was to explicitly declare "position: static" inside the div tag itself. (Even just declaring it in the css wouldn't fix it – somewhere else it must have still been getting overridden)

While I'm at the point where I can't even imagine designing a page using a table based layout anymore, I still get hit with some CSS sticking points that I just don't get. So if you have more insight on this feel free to elaborate in the comments. I'm just so glad I was able to get the menu working!

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements