Posts Tagged ‘wordpress’

wordpress php snippets

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'); ?>

            frequently used wordpress plugins

            i needed to keep a list of the wordpress plugins i use, either on my personal site or on the various other sites i’ve worked on

            required

            • all in one seo pack
            • google analyticator
            • google xml sitemaps
            • db cache reloaded fix
            • hyper cache

            dependent on project

            • anyvar
            • custom post limits
            • shadowbox js
            • wordpress related posts
            • contact form 7 (+really simple CAPTCHA)
            • audio player
            • my page order
            • widget entries

            i need to also put frequently-used code… nice segue, joe…

            me and 1and1 are cool again…

            so i’ve had this long-standing issue with my host, 1and1, where i wasn’t able to install plugins or upgrade the wordpress software to the latest and greatest version…

            this really ticked me off because i would have to do plugin updates manually (upload via ftp) and the newest wordpress 3.x didn’t want to upgrade at all (i’d get server errors)

            so i finally consulted google and was able to find a solution — apparently it has bothered other people!

            If you are a 1and1.com user and are having problems getting the auto upgrade to work (for both the core and plugins), here’s the fix.

            Add the following line to your .htaccess file (in the root directory of your WP install):

            AddType x-mapp-php5 .php

            as soon as i updated the .htaccess file, i was able to upgrade plugins and even wordpress itself!

            i was even able to install the WPtouch plugin through my phone! that’s sick.

            happy.

            the band of primates

            so i’ve FINALLY updated the gorirra site… it wasn’t just a small cosmetic change neither… it’s a whole upgrade to the wordpress cms.

            i’m really happy with the way it turned out — it’s simple and modern <toot toot>

            i’m kinda glad i didn’t go with my initial mockup:

            wise decision...

            more coding funzz!

            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