Removing Images from a WordPress Post

WordPress No Comments »

Today I ran across a unique need to remove images from a WordPress post in a specific post loop.  Because there is no way to do a “read more” excerpt while taking strict control of the raw content from the_content() I was limited to capturing and manipulating the content from PHP’s output buffer.  My solution: obtain the output from the_content() and remove the image tags from the post using preg_replace().

Here is the solution:

.
.
.
<?php
   ob_start();
   the_content('Read the full post',true);
   $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
   ob_end_clean();
   echo $postOutput;
?>
.
.
.



No Comments - Post Your Comment »
Digg!

jquery.suggest 1.2

PHP, Web Development No Comments »

A few people have contacted in the past about what I did to get IDs to work on Peter’s Script over at vulgarisoips.com (see the original post here).

Peter’s script works great; but for my needs I had to add an ID to the suggestion as a way to relate the selected value back to a dB entry.

First, I needed a way to tell the script where to add the results to in the DOM instead of having the script add the object automatically.  I created a new option called attachObject which allowed me to control the object in the DOM.  This allowed me to do this:

$('#name').suggest('/suggest/client',{dataContainer:'#cid', attachObject:'#sresults', onSelect: myFunction );

Note how above I use #sresults as my object to attach the suggestion results to.  In my edits if you leave out the attachObject it will still build the <ul> object for you without any issues.

Next, I needed a way to have the ID go along with the representation values (ex. a hash-like key, value relationship).  To do this I added two other options to the script: one called dataContainer and one called dataDelimiter which I set to a default value of tab (\t).  The dataContainer is an ID of an input box which holds the database ID of the selected object in the suggest box.  The dataDelimiter is the delimiter for the payload which contains the key values pairs separated by the dataDelimiter.  (Note: the “row” delimiter is still a new line character).

In my XHTML I have this:

<input type="hidden" name="cid" id="cid" value="-1"/>
<input type="text" id="name" size="30" maxlength="128"/>
<div id="suggestResults"></div>

(and I use the script stub above…)

On the server I have /suggest/client do something similar to this:

.
.
.
$stmt->execute();
foreach( $stmt->fetchAll(PDO::FETCH_OBJ) as $row ) {
echo "{$row->displayName}\t{$row->tmpid}\n";
}

NOTE: I do make an assumption your keys will always be unique; as I append a s_ to the key to construct the necessary <li> items (need to keep them unique for DOM reasons).

Here is the original version of Peter’s script: Original Version 1.1 (in text)

Here are my updates (let us call it v1.2):Updated Version 1.2 (in text)

In hindsight there are definitely better ways to do this but this solution is working great still (this idea and solution go back to August of 2007); and I will always suggest “working effectively in production” is always better than how it “should be.”

No Comments - Post Your Comment »
Digg!

How to fix the Curl Error: error setting certificate verify locations

CentOS5, Web Development No Comments »

Today I had a new server running CentOS5 have trouble with a known good authorize.net library using curl.  It was producing the following error:

error setting certificate verify locations: CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none

After some research I found it was based on the inability for the apache user to access the ca-bundle.crt file. You will find solutions on the web suggesting adding curl_setopt($link, CURLOPT_SSL_VERIFYPEER, FALSE); to your script to disable the peer verification — I suggest you not do this and simply fix the permissions for your CA file.

Execute this:

/bin/chmod 755 /etc/pki/tls/certs

Solved!

No Comments - Post Your Comment »
Digg!

Cellpadding and Cellspacing in CSS (part 2)

CSS, XHTML No Comments »

Here is a follow up to the cellpadding and cellspacing post I made a while back. The cellpadding and cellspacing can be completely controlled in CSS. I realized today; I spoke only about collapsing the borders and not creating spacing (or the equivalent of cellspacing equal to something other than 0).


Here are some HTML4 and CSS/XHTML equivalents:



HTML4: <table cellspacing="0" cellpadding="0">
CSS: table { border-collapse: collapse; } table tr td { padding: 0px; }



HTML4: <table cellspacing="2" cellpadding="0">
CSS: table { border-collapse: separate; border-spacing: 2px; } table tr td { padding: 0px; }



HTML4: <table cellspacing="2" cellpadding="2">
CSS: table { border-collapse: separate; border-spacing: 2px; } table tr td { padding: 2px; }



You may want to place these definitions into a CSS class so you can quickly reference your table definition in XHTML:



CSS:

table.info { border: 1px solid #ccc; border-collapse: separate; border-spacing: 2px; }
table.info tr th { font-weight: normal; text-align: right; }
table.info tr td { font-weight: bold; padding: 2px; }




HTML:

<table class="info">
<tr><th>First Name:</th><td>Chris</td></tr>
<tr><th>Last Name:</th><td>Schuld</td></tr>
</table>



Here is what it will look like:

First Name: Chris
Last Name: Schuld



No Comments - Post Your Comment »
Digg!

Cellpadding and Cellspacing in CSS

Web Development 1 Comment »

Those of us who learned HTML early in the game are familiar with HTML table parameters cellpadding and cellspacing.  In a positive way they were deprecated in HTML4 so you must use CSS to control the padding and spacing now.

Here is how you do it in CSS:

border-collapse: collapse;

A nice line to place in your global CSS file (if you use one) is:

table { border-collapse: collapse; }

1 Comment »
Digg!

Common Web Banner Sizes

Web Development No Comments »

I never can find this information when I need it so I am writing it down:

Here are the common web banner sizes:

  • Banner - 468px X 60px
  • Leaderboard - 728px X 90px
  • Skyscraper - 120px X 600px
  • Wide Skyscraper - 160px X 600px
  • Large Rectangle - 336px X 280px
  • Rectangle - 300px X 250px
  • Square - 250px X 250px
  • Small Square - 200px X 200px

I took the name of these sizes from google as they were kind enough to name them

No Comments - Post Your Comment »
Digg!

Web Development Links

Web Development No Comments »

Lorem Ipsum - http://www.lipsum.com/

Color Schemer Online - http://www.colorschemer.com/online/

No Comments - Post Your Comment »
Digg!

Missing phpize?

Fedora, PHP No Comments »

In an attempt to add the PECL Upload Progress package, I received the following error:

[root@zebra cbschuld]# pecl install uploadprogress-beta
downloading uploadprogress-0.3.0.tgz ...
Starting to download uploadprogress-0.3.0.tgz (4,677 bytes)
.....done: 4,677 bytes
3 source files, building
running: phpize
sh: phpize: command not found
ERROR: `phpize' failed

Hmmm, it turns out I never added the package php-devel (oops). If you are missing phpize on your machine add it with:

yum install php-devel
No Comments - Post Your Comment »
Digg!
Original Design by j david macor.com. Original WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in