here are a bunch of frequently used code snippets i’ve used with many of my projects

* i really should know these by now… but what are ya gonna do?

linking to the homepage

    <a href="<?php echo get_option('home'); ?>">...</a>

    image references

      <img src="<?php bloginfo('stylesheet_directory'); ?>/images/FILE_NAME.jpg"
      alt="<?php bloginfo('name'); ?>" title="<?php bloginfo('name'); ?>" />

      dynamic widgets

        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('WIDGET_NAME') ) : ?>
        <?php endif; ?>

        then, in functions.php, add this:

        register_sidebar(array('name'=>'WIDGET_NAME',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
        ));

        custom fields – mentioned before on my site, but just to have ’em all together

          <?php $VARIABLE_NAME=get_post_meta($post->ID, "CUSTOM_FIELD_NAME", true);
          if (get_post_meta($post->ID, "CUSTOM_FIELD_NAME", true)) {
          echo ("<img src=\"FULL_PATH_TO/$VARIABLE_NAME\" />");
          } ?>

          copyright

            &copy; <?php echo date('Y'); ?> - <?php bloginfo('name'); ?>

            again, thanks to sam the cooking guy

            ingredients

            • 1-two pound london broil
            • 4 cloves garlic, chopped fine
            • kosher salt and pepper
            • 1 sourdough baguette
            • ⅔ cup horseradish sauce
            • 4 oz arugula leaves (or spring mix lettuce)
            • olive oil
            Read more »

            been watching some sam the cooking guy lately… i think i can tackle these…

            bacon-wrapped scallops

            ingredients

            • 1 lb sea scallops, defrosted
            • 12 slices of pre-cooked bacon
            • 1/4 cup teriyaki sauce
            • 2 skewers
            • 1 tbsp toasted sesame seeds
            Read more »

            on the topic of “figuring things out wrt coding” — i was working on converting a site to wordpress and was trying to figure out how to get a home page movie to appear ONLY on the home page (easily).
            so i looked around and found out there was a wordpress function called “is_front_page()”

            so, along with a nifty fade in/fade out script, i created this in the header.php file:

            <?php
              if ( is_front_page() ) {
              echo "
                <div class=\"hpmovie\">
                  <div id=\"xlide\">
                    <img src=\"wp-content/themes/[THEMENAME]/images/5.jpg\"
                      alt=\"\" />
                    <img src=\"wp-content/themes/[THEMENAME]/images/11.jpg\"
                      alt=\"\" />
                    ...
                  </div>
                </div>
              ";
              }
            ?>

            so basically, if it’s the home page, it’ll write stuff to the page… boom

            so this won’t make sense to any of you, but i was pretty proud of myself when i made this. i used various xsl elements to basically have the page pull data from an xml document:

            xsl

            ...
            <xsl:variable name="readmore">
              <xsl:choose>
                <xsl:when test="@readmore != ''">
                  <xsl:value-of select="@readmore" />
                </xsl:when>
                <xsl:otherwise>
                  See all <xsl:value-of select="@title" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <div style="font-size:8pt;">
              <a href="{@url}"><xsl:value-of select="$readmore" /></a>
            </div>
            ...

            this is a sample of the xml that it pulls:

            <page id="..." title="Newsletters" url="newsletters.asp"
              thumbnail="include/media/images/products-newsletters.gif"
              description="blah blah blah">

            so since there isn’t a title attribute to this node, it’ll default to the title. on the page, it’ll say “See all Newsletters”

            i made it myself! yay

            as i write the title of this tutorial, i can tell it might get long and/or complicated… i’ll try my best… here we go

            FIRST, you’ll need the tools — download virtual pc (especially if you run windows vista) and then grab an image here — i would suggest getting the IE6 image, since that version of IE is the “worst” of them all
            Read more »

            i feel that i should add a few notes as an addendum to my previous post — call it the “companion pack,” if you will

            • after you modify the “default” folder in the “wp-content\themes” directory, make a copy of it and rename it to something… anything…
              • i found this out the hard way. wordpress just recently did a string of updates (currently 2.8.2) and every time i’d do an update, my site would revert back to the default layout
              • luckily i had all my files locally so i was able to re-upload to the default folder
              • it only took me 3 upgrades to figure out that i had to rename the folder so that wordpress wouldn’t overwrite my work

            Read more »

            hot on the heels of my first tutorial, i come back at ya with a new one.

            i REALLY like using wordpress as a cms — not only for its ease of customization or its extensive library of useful (mostly) plugins, but for these two huge reasons:

            1. ability for the end-user to modify the web site content without breaking the overall site geography
            2. search engine optimization — yea i kinda did mention them earlier, but several plugins can work to help your site get spidered like the best of them.

            so i guess that answers the “why use wordpress?” question — here’s my method of getting a custom theme setup for wordpress
            Read more »

            so chaunce asked if i could do a small tutorial for a wordpress (wp) question he had… i’m honored that he asked me to do so… actually, i think i might start to write a bunch of tutorials that i’ve learned along the way…

            and here… we… go…

            this tutorial deals with the user wanting a site with a blog and pages, but the user wants a specific page to be the front page, not the blog (something similar to andy’s site, but not — since he doesn’t want his site to be full-on wordpress)

            *note, i suck at technical writing, but i’ll try to fake it… i’m open to suggestions/comments for future tutorials
            Read more »