Styling WordPress Pages as Inline List without CSS

/* Posted May 3rd, 2011 at 2:41pm [Comments: none]    */
/* Filed under General    */

WordPress has a number of great built-in functions that you can use throughout your theme, but you’re pretty much limited to accepting any list of pages output as ul lists. But what if you don’t want a vertical top to bottom unordered list? Would it be possible using CSS to style the list so that the entire list appears on one line and reads left to right? Yes, you can definitely add the CSS inline property to the list to make this happen. While this works, there is one small problem. I wanted to make my list of pages look like a navigation block with a simple vertical bar character separator. Really simple, like this:

About Me | Contact Me | You Get | The Point

This type of navigation-looking output of all your WordPress pages does not use a list at all, so using the built-in function wp_list_pages is out of the question. There is no way to get an output without each page being wrapped in li tags. So instead, I found a great alternative function that works very much like this one but allows me to control the output called get_pages.

In your WordPress theme where you want to output all your pages horizontally in one line, use this simple function that I came up with to style it exactly as I wanted it to look in the example above.

?php
$pages = get_pages('exclude='); // you can add page IDs to exclude if you want
for ($i = 0; $i  count($pages); ++$i)
{
  if ($i != 0)
    echo ' | ';
  echo 'a href="'.get_page_link($pages[$i]-ID).'"'.$pages[$i]-post_title.'/a';
}
?

That’s it! You can easily tweak the separator character (in this case I used the vertical bar but you can use bullets, », etc). No messy SQL to write (which I was just about to do before I stumbled on this function in the WordPress Codex) and the code is very easy to understand. Look at the documentation if you want to do fancier things like sorting the page results. By default it is simply sorted alphabetically which was OK for my needs. Using this, you can even add a “Home” link to the beginning of the list like many navbars do, something not possible with the built-in WordPress page listing function. This also beats hard-coding the page URLs since it reduces the theme’s portability when applied to other websites. If you’ve got a few websites using the same theme, then you’ll appreciate why this sort of broad compatibility is quite critical.

If you have knowledge of an even better way to do this, you are welcome to share it in the comments for everyone’s benefit.

Tags:

Android Saving Persistent Data Between Application Sessions

/* Posted April 21st, 2011 at 2:39pm [Comments: none]    */
/* Filed under General    */

There are a few ways to save data persistently between launches of your Android application. One way is to actually use a database, but I felt this was overkill for my needs since I only needed to store two numbers. The other way is to save it as an Android application preference, which only needs a few lines of code. To do this, you simply make use of the SharedPreferences object which can be accessed within any Activity. It will store the data to the Android OS referenced by a key that uses your application name as its prefix by default (there is another call you can make if you want to specify the name and I believe this is so you can share persistent data between two different apps but that’s not needed here). You can then retrieve it at any time.

Place the call to save the data in the onPause function which gets called right before the Activity is closed and you can access the saved again in any other function.

public class MyApp extends Activity {
    private SharedPreferences mPrefs;
    private int mMonth;
    private int mYear;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mPrefs = getPreferences(MODE_PRIVATE);
        mMonth = mPrefs.getInt("month", 1);
        mYear = mPrefs.getInt("year", 2011);
    }

    protected void onPause() {
        super.onPause();
        SharedPreferences.Editor ed = mPrefs.edit();
        ed.putInt("month", mMonth);
        ed.putInt("year", mYear);
        ed.commit();
    }
}

Note that you will be able to specify a default value in getInt as the second argument when you retrieve a saved preference because the first time it ever gets called it won’t exist yet. In this sample code, the month value defaults to 1 and the year defaults to 2011. Once data is saved the very first time, these default values won’t be used again.

On a side note–if you are using month data–don’t use 1 because it’s actually February if you are using the Calendar class and not January as expected, so use the Calendar.JANUARY enumeration.

Tags:

Android Function to Fetch HTML Page from Any URL

/* Posted April 19th, 2011 at 2:38pm [Comments: none]    */
/* Filed under General    */

Making use of the Internet connectivity on the Android platform often means having to access web pages and reading the data from it for your application. To achieve this, I wrote a function that takes in any URL to fetch the HTML contents from. What this function will give you is the HTML source code for a website. It will then be up to your app to parse the data properly to retrieve the information you need. I used regular expression matching to strip out the unnecessary bits and get right down to the content I wanted to display.

Here is a simple function that I use below. It did end up a bit slow accessing the URLs I sent it, so I eventually put the HTML processing on my own web server and then had my Android application simply fetch the data from there. You may get a dialog pop up in your app when using this if the access takes too long. It’s fine usually on wi-fi, but 3G can be a bit slow sometimes. As with any code, test before you deploy to see if it suits your needs. At the very least, you have a basis to use for tweaking in case you want to build in some slow response handling.

public String getURLContent(String url)
{
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);
        ResponseHandlerString resHandler = new BasicResponseHandler();
        String page = httpClient.execute(httpGet, resHandler);
        return page;
    } catch (ClientProtocolException e) {
        return "";
    }  catch (IOException e) {
        return "";
    }
}

Tags:

Why No Comments Are Showing on isoHunt

/* Posted April 7th, 2011 at 2:36pm [Comments: none]    */
/* Filed under General    */

I’ve received many inquiries on the comments disappearing on isohunt.com so I thought I would address the issue here publicly for everyone’s benefit. There is nothing broken. Isohunt.com isn’t functioning improperly and your browser isn’t messed up. This is 100% purely intentional as a result of the legal battle that isoHunt has been fighting with US courts. This is also the reason why US users were left with a gimped isoHunt Lite version of the website (see more on how to fully access isohunt.com here).

This is what isoHunt has to say about the user comments not showing:

True that we have disabled comments in Lite for legal reason, but ratings (with thumbs up, down) are still displayed, and it is factored in in the combined torrent search ranking, which includes seeds/leechers, ratings, search relevance and age. Many of you complain about missing sort and that is really uncalled for, the combined ranking is better in most cases especially with more spam trackers misreporting seeds/leechers stats. This ranking again is the same default ranking used on regular isoHunt which you come to love.

As you can see they’ve acknowledged that the comments don’t show in Lite and they’ve done their best to keep is as functional as possible. I’ve been able to access their comments fully using my trick to view the full version website. If you don’t like their change, stop using isoHunt Lite.

I also tried to access their website directly from my US IP and it seemed to be working fine and even gave me the full version to use. This is because they’ve earned a short reprieve while they are appealing their case. I did get different results though (results were better through proxy). Their note on lifting the ban:

Regular isoHunt interface available again for US with a twist: until we are able to appeal the US court injunction, categories and top searches are disabled. Lite is still available if you want it.

Hopefully this puts the issue to rest for most of you. If you’re browsing through proxy it does get a little laggy, so be patient and refresh if nothing shows up after a while. And don’t complain because it’s better than nothing.

Tags:

Hide or Disable the Admin Bar in WordPress 3.1

/* Posted March 28th, 2011 at 2:34pm [Comments: none]    */
/* Filed under General    */

Recently, I wrote about how to fix the blank admin bar in your theme on a newly upgraded WordPress 3.1 installation. This is a great new feature introduced in WordPress 3.1 that lets you get access to commonly used tasks in the dashboard, even while you are viewing your website. However it’s not for everybody and it’s possible you may want to hide or disable the admin bar.

This is a per user setting, so you must look for the Users menu on the admin sections sidebar and click “Your Profile.” There is an option just below the top like this:

disable wordpress admin bar

You have the option to disable it separately in the dashboard and while viewing your site. Simply uncheck the options where you want to hide the admin bar and save your settings.

Tags:

Fix Blank Admin Nav Bar in Theme on WordPress 3.1

/* Posted March 22nd, 2011 at 2:32pm [Comments: none]    */
/* Filed under General    */

If you’ve recently upgraded to the latest release of WordPress, then you’ll notice a nifty new admin navigation bar at the top of your dashboard in the admin section of your website. I really like this feature as you can quickly navigate to some of the more used functions like creating a new post/page, jumping to comments, or getting to the widgets page. The best part is getting access to all your websites from the navbar in a multisite WordPress 3.1 installation.

When you’re logged in, you’re supposed to see this new admin bar in the dashboard as well as when your viewing your live site. This is set by default in the user profile. Unfortunately, in my custom theme I was seeing blank whitespace where the admin navbar should have been at the top of the theme. Initially I did not know this new feature carried over to the site view so imagine the hour or so I spent digging through my CSS trying to figure out why my theme had a 28 pixel gap at the top. When I saw the bar on a site with a different theme, I realized it was my theme that had a problem.

After some research, I discovered that the admin bar code is hooked on the wp_footer function. Since any good-behaving theme should call wp_head in the header.php and wp_footer in the footer.php, this was supposed to be a seamless upgrade. Unfortunately, I had neglected to make the call in my own custom theme. If you are experiencing the same issue where a blank space appears at the top with no dashboard navbar, then check your theme’s footer.php for the call to wp_footer and if it’s not there add it in.

Here’s the code. Just add it in anywhere in your theme’s footer.php file:

?php wp_footer(); ?

This fixed the problem for me.

Tags:

Adding www to WordPress 3.0+ Multisite/MU Root Domain

/* Posted March 8th, 2011 at 1:28pm [Comments: none]    */
/* Filed under General    */

If you’ve used the multisite option on WordPress 3.0 and greater, you’ll notice that you may have your ‘www’ stripped from your main blog root domain. Supposedly, WordPress 3.0 was supposed to automatically handle your ‘www’ if you had specified it properly when you made the initial installation.

But what about the rest of us who neglected to do so? It’s an easily overlooked step, and fortunately it’s easily correctable… if you’re willing to brave through digging your MySQL database and editing one line PHP code. With pre-WP 3.0 blogs you were able to specify the main site URL, but that option is gone in 3.0. So what you’ll need to do is dig around in your WordPress database and modify your wp-config.php.

We’ll take it one at a time.

Launch your myphpadmin panel and navigate to your WordPress database. Inside, there will be two tables you’ll need to modify: wp_blogs and wp_options. Alternatively, you could run a text string search for ‘mydomain.com’ through the myphpadmin interface and get those tables to appear.

Browse the table wp_blogs by clicking on it and click on the pencil icon next to edit the field of the root domain that you wish to change.

add www wordpress multisite

This will bring up a window to edit the field, you should see ‘mydomain.com’. Simply replace that with ‘www.mydomain.com’ as specified here.

add www to root domain wordpress 3.0

Do the same for the wp_options table, editing the siteurl and home entries in the table. Make similar changes, replacing any instance of http://mydomain.com with http://www.mydomain.com.

add www to root domain wordpress 3.0

You’re in the home stretch now. Close myphpadmin and edit your wp-config.php file in the root directory of your WordPress installation folder. Modify the line:

define( 'DOMAIN_CURRENT_SITE', 'mydomain.com' );

to

define( 'DOMAIN_CURRENT_SITE', 'www.mydomain.com' );

and you’re done!

This fix requires no fussing with the .htaccess file. I tried this originally with just making the changes in the WordPress MySQL database only, but I ended up getting a “The page isn’t redirecting properly” error in Firefox. It turns out I was missing one critical modification in wp-config.php, which I’ve pointed out above.

Hopefully that solved any headaches for you and allowed you to add ‘www’ in your root domain of your multisite WordPress installation.

Tags:

Remove DOS ^M Line Endings in Vim

/* Posted March 4th, 2011 at 2:27pm [Comments: none]    */
/* Filed under General    */

I do most of my work in Vim since it’s the easiest to use without a mouse. Moving between keyboard and mouse can be tiring, especially when coding, so Vim is particularly good at keeping your hands in a stationary position. Granted, the learning curve can be quite high, but there isn’t anything Vim can’t do that any normal text editor can.

If you encounter code from someone else with the annoying ^M DOS style line endings, you can first try a dos2unix command. If that doesn’t solve your problem simply open up the file in Vim and do a search and replace for all instances of ^M with an empty string.

The problem arises in how to actually input the caret character ^ and it’s actually done by holding down the control key and pressing V. Because the ^M is a control character, not a normal one, you need to escape it as a control character. The caret is just the indicator on the screen that you’re using a control character.

Remember the command for global string replacement is this:

:%s/search/replace/g

Thus the command you want to type to do a replacement in Vim is:

:%s/^M//g

But the keystrokes required to get the ^M are actually:

Ctrl-V, Ctrl-M

This puts the escape for the control character and allows you to properly identify the DOS line endings and remove them from the end of line. See? Vim can do anything!

Related posts:

Tags:

CityVille Cheat: Boost Build Layout Adds +131%!

/* Posted February 22nd, 2011 at 2:22pm [Comments: none]    */
/* Filed under General    */

cityville boost build bakery with 131% boost

Developing good cheats or strategies in CityVille is crucial for getting the upper hand against your neighbors and friends if you want to level up quickly and buy up all the high priced buildings and decorations you wish you could afford. For those who can’t be bothered, you can follow along with me as I learn and play. I have just started and will be occasionally posting good CityVille cheats that worked. There is also a great guide called CityVille Secrets that I recommend if you want to get a serious advantage.

Today I’m going to cover how to how to build what I called the Boost Build Layout in CityVille. What this does is add a tremendous boost multiplier to your earnings every single building in the game, up to 131% if you can believe it. This turns a measly cozy cottage normally pumping out 50 coins an hour to 116 coins an hour instead. This is like having more than two cozy cottages working for you at the same time! Best of all, it effectively bypasses your population restriction legally and allows you to collect what a town double your size would produce! And you won’t even incur the double restocking cost for your businesses. Supply one business, get two businesses worth of income. While 3×3 buildings can produce up to a 131% boost, 4×4 buildings max out at a nevertheless impressive 125%. Do you know that my neighbor’s pool hall franchise produces for me a gold bar every time I collect? That’s 945 coins versus 420. I’m only on level 13!

This is the CityVille Boost Build Layout cheat pictured below:

This strategy does not cost CityVille cash and always works. The key is in the build layout. Even as a newbie like me you must know that every  building must be next to a street road in order to collect business, but there are no rules that the piece of road must lead anywhere or be connected to any other piece of road. Thus you start with a building and place a piece of road next to it. Then using the CityVille boost build layout, you surround that centerpoint with arboretums (and a tiered fountain if you’ve received one from one of the early quests). There will be some gaps which you can take advantage of by stuffing small 1×1 decorations like blue flowers and tree that add 1% boosts as pictured below.

cityville cheat boost build labels

Now to put it to use. You don’t actually keep your building there. Instead, the cheat here is to swap out the building every time you want to collect from it. What this means is if your toy store and burger joint are both ready to be collected, move your toy store to the center of your build boost layout, collect from the toy store, move your toy store back, move your burger joint to the center of the layout, and collect from the burger joint. Remember that the road here is critical otherwise you will be unable to collect from the house or business. Also remember that in order to generate business, the rest of your buildings must be placed legally next to roads, otherwise they will stall and will not operate.

I started playing CityVille just four days ago and I am at level 13. I’ve not used my CityVille cash and I’ve only played maybe a few minutes at a time a couple times each day. Using this strategy I’ve been able to seriously increase my cashflow while being limited to a population of 160. Besides the city hall, I have no other community buildings built. This will not stop me from being ultra rich thanks the Boost Build Layout.

cityville level 13

I can foresee that as the city gets bigger this may become a more tedious task, so unless you are really hardcore, simply use this strategy as an initial booster so you earn money quickly and get a jump start on the game. Super-powered strategies like this and more (including how to get a +526% boost) are also in the CityVille Secrets guide so click here if you want more cheats like this one.

Tags:

MySQL String Search and Replace Query

/* Posted February 18th, 2011 at 2:21pm [Comments: none]    */
/* Filed under General    */

This is really useful if you ever have to migrate your WordPress MySQL database and the server path changes. Rather than do a fresh WordPress install on your new server and attempting to import your old posts from your old server, you can easily do basically the same thing with this basic MySQL query to search and replace all instances of a string.

Doing this is preferable if you exported your WordPress install but have lost the domain or if you just want everything the way it used to be but on your new server. I’ve found that the whole WordPress recommended way of export/import doesn’t do as thorough a job as this method. If you’ve got the technical savvy and WordPress know how, then this is a better way to go.

You’ll want to execute this MySQL query:

update TABLENAME set FIELD=replace(FIELD, 'search string', 'replacement string');

On the following tables: wp_xxxx_options, wp_xxxx_posts. For example, if your user name has changed but you have the same path set up, you can just replace all instances of your old username with the old one. You could also do this with a domain change.

At any rate, I highly recommend you know what you are doing before you attempt this. I wouldn’t recommend this to most people out there.

Related posts:

Tags:

Page 3 of 491234567...203040...Last »