15
Jul/10
0

Including Custom Search Results In A WordPress Page

One website required certain pages to contain custom search results.

To do this I needed to have the following code. The main tricks here are to create a second query as well as the main page query using the WP_Query method, and that the parameter for such a query needs an s=… to let it know the phrase being supplied is a search term.

The get_post_meta() method allows extraction from the main page extra parameter list.

<?php

$query_string = get_post_meta($post->ID, ‘organism_class’, true) ;
$search = new WP_Query( "s=$query_string&showposts=5" ) ;
$search_posts = $search->query( "s=$query_string&showposts=5" ) ;

while ($search->have_posts()) : $search->the_post();
?>

<h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
<?php the_content(); ?>

<?php endwhile; ?>

27
May/10
2

OpenOffice: Recovery Window keeps popping up for a deleted file

Calc, the OpenOffice.org spreadsheet program can sometimes crash for me when doing cut and paste. On one occasion I deleted the file I was working on.

Since then the recovery window pops up every time the program gets started and fails because the item doesn’t exist.

The solution is to delete the OpenOffice.org recovery file. Its located at the following subdirectory of the user data directory.

AppData\Roaming\OpenOffice.org\3\user\registry\data\org\openoffice\Office\Roaming.xcu

26
May/10
0

Making your page Meta Tag the post title in WordPress

The META tag can be used to provide additional information to search engines. Google doesn’t use meta tags directly to increase page rank but a helpful description can be useful in deciding what gets used as a page summary on another site, making something thats more appealing to the user than whatever bit of the page is displayed along with a link.

You can include this in WordPress using the following in the header.php file in your template.

<meta name="description" content="<?php the_title() ; ?> " />

25
May/10
0

Windows 7: Deleting or Rename Files still appear in Windows Explorer until they are refreshed

I was experiencing a problem with Windows 7 Explorer in that deleting a file left behind a ghosted out version of the file in Explorer with the same name. I couldn’t actually do anything with this file as it was actually deleted (or moved if I had renamed it) but it was still listed until the folder was refreshed through the magic of the F5 key.

Finally when having to rename a load of these files I’d had enough. Googling the answer pointed me to some Microsoft forums which gave technologically advanced answers like registry editing and someone even suggesting recreating your user profile. This was from Microsoft!

Somewhere in one of the threads someone pointed out that this only happened when accessing the Documents through a ‘Library’. Libraries in Windows 7 are a useful feature to my personal account as they are a useful way of accessing a spread apart music or video collection via a single access point, especially given an external disc. But it seems some sort of caching issue creeps up with accessing folders in the Library.

The problem I had was that accessing something as u:\users\rishistar\My Documents\test\ still resolved to a Libraries path so I right clicked on each library and deleted each one. I don’t use them on my work account so this was fine for me. YMMV.

As a coda I did have to re-create my favourite shortcuts in the top left of the Explorer pane but that was no big deal.

20
May/10
0

Selecting MySQL rows within a Time Range for a Java Program

Earlier I discussed selecting rows from a table within a specified date range. What if you need to select rows from within a time range?

Again a SELECT statement with a WHERE clause is needed. The  method below will give the statement for the start and end times of the statement. Unlike the earlier example this has a DateFormat to supply the String required to generate the SQL statement.

GregorianCalendar calStart = new GregorianCalendar() ;
 calStart.set( Calendar.HOUR_OF_DAY, 18 ) ;
 calStart.set( Calendar.MINUTE, 1 ) ;
 String sql = "SELECT * FROM " + dbh.userTable.tableName +
          " WHERE status=1 AND "
          + SQLStrings.getWhereBetweenDates( "signup_time", calStart ) ;

.....

public static String getWhereBetweenDates( String columnName, GregorianCalendar calStart)
{
    GregorianCalendar now = new GregorianCalendar() ;
    StringBuffer sb = new StringBuffer( columnName + " BETWEEN " ) ;
    SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ) ;
    String beforeDateString = df.format( calStart.getTime() ) ;
    String afterDateString = df.format( now.getTime() ) ;
    sb.append( beforeDateString + " AND " + afterDateString ) ;
    return sb.toString() ;
}

Note that the DateFormat String here was determined by what was present in the MySQL database for that particular column. YMMV – so if there are problems maybe check your database table to see what particular format that column takes.

Filed under: Java, MySQL
6
May/10
0

Selecting MySQL Rows with a Timestamp Column on a Single Day or Month from your Java Program

You have a MySQL database table with a Timestamp column, and you need to select entries for a single day, month or year. As indicated in previous posts, you can construct MySQL statements that allow you to access items from a certain date/month/year.

This can be achived using the following.

String sql =
“SELECT * FROM orders WHERE day(time_outgoing)=” + day ;
Statement st = con.createStatement() ;
ResultSet rs = st.executeQuery(sql) ;

Something similar can be done for months and years, and Java’s Calender class provides fields for moth access. However note that the java.util.Calender fields for months are indexed from 0, so the actual integer value of Calender.MAY is 4 and not 5.

int month = Calender.MAY ; //want entries for may

//increase the month by 1 to access values

String sql =
“SELECT * FROM orders WHERE month(time_outgoing)=” + (month+1) ;
Statement st = con.createStatement() ;
ResultSet rs = st.executeQuery(sql) ;

OR

SELECT *
FROM optout75308
WHERE logtime
BETWEEN “2010-05-21″
AND “2010-05-22″
AND (
contact_method = ‘ODWBPRESS1′
OR contact_method = ‘SERV2OWDBy’
)

6
May/10
0

Reading a TimeStamp Value from a MySQL Database in your Java Program

So, you’ve written your database table to have a Timestamp column in it. Often this can be used to log when an entry is created or updated. This post will detail a couple of things that may be useful in doing more than just having it logged.

Java provides a java.sql.Timestamp class that can be used to read and alter timestamp values.

So if your database column is called signup_time, it can be read out as follows

import java.sql.Timestamp;

        Statement st = con.createStatement() ;
        ResultSet rs = st.executeQuery(  “SELECT * FROM subscribers”  ) ;
        StandardSubscriptionUser users[] = new StandardSubscriptionUser[ count ] ;
        rs.beforeFirst() ;
        while( rs.next() && count>0 )
        {

               signupTime = rs.getTimestamp("signup_time") ;

        }

The Timestamp class is a subclass of java.util.Date. However there is not quite a match between how java.util.Date and java.sql.Timetamp store the time. This means that a Timestamp object should not be used where Date objects are required in functions. As the API says “The inheritance relationship between Timestamp and java.util.Date really denotes implementation inheritance, and not type inheritance.”

However it does mean that the standard Date API methods can be used to do things with the Timestamp object, meaning there is a set of standard methods to manipulate and access the values with.

30
Apr/10
1

Selecting MySQL Rows with Timestamp Column in a date range from a Java Program

You have a MySQL database table with a Timestamp column, and you need to select a range of dates in which you need to select entries from.

As ever a SELECT statement with a WHERE clause is needed. The following will give you a range of dates from the first to the last. Note that without times specified it is the start of each day. So although 2008-08-31 is specifed no entries on that date will actually be included in the returned results.

String sqlWhereDate =
                " order_placed BETWEEN \”1995-05-01\” AND \”2008-08-31\” ” ;

String sql = “SELECT * FROM orders WHERE ” + sqlWhereDate ;

Tagged as:
4
Apr/10
0

Netbeans Editor Code Folds

Some times its handy to be able to hide sections of code in the Netbeans editor window.

// <editor-fold desc="This section of the code deals with the item.">
 Your code goes here...
// </editor-fold>

These are just the basics. More information is available from the Netbeans page.

31
Mar/10
0

WordPress on the frontpage – displays category content, but not title

So here’s an interesting one. Often I have sites with a page where there is a subcategory with a few of the latest entries fully featured on the front page. The following code, when I tried it, did not display the title for the subcategory entries. Instead of the subcategory post title I got the main page title.

<?php
 $newsposts = get_posts('numberposts=2&category=4');
 foreach($newsposts as $newspost_single) :
 setup_postdata($newspost_single);
?>
 <div>
 <h3><?php the_title(); ?></h3>
 <?php the_content(); ?>
 <hr>

 </div>
<?php endforeach; ?>

The fix? To change the $newspost_single variable to $post. Not sure why this is the fix, and I should see if it counts as a bug, but it worked for me.

Filed under: Wordpress