Link separators for wp_list_pages() code snippet

   Posted: May 28th, 2010    By: Devin Walker   

WordPress makes it very easy to dynamically create menus from pages and categories with the use of the function wp_list_pages() and wp_list_cats()... but what if you want to have separators in your menus? Here's a bit of code that will do just that:

wp_list_pages Separators

$args = array(
  'sort_column' => 'menu_order',
  'title_li' => '',
  'depth' => '1',
  'echo' => 0
);
$separator = ' | ';
$pattern = '/(<\\/a>).*?(<\\/li>).*?(<li)/is';
$replace = '</a>' . $separator . '</li><li';
$subnav = preg_replace($pattern,$replace,wp_list_pages($args));
echo $subnav;

Please note: I got this code from Rares Comes (very nice lavalamp menu there)

With 2 comments

Posted in PHP,Wordpress

Tagged with ,

WordPress List Subpages Even if On Subpage

   Posted: May 25th, 2010    By: Devin Walker   

I'm building a new site and the navigation on it requires me to use a different bit of code for parent and child pages. I thought I'd share the code for those out there building a similar navigation. Here's a handy bit of code that you can use to display all subpages on a subpage. For instance, you have your pages setup like so:

Page: Fruit
subpage: Banana
subpage: Apply
subpage: Orange

On Parent Page

If you were wanting to show a navigation menu of all subpages in the Fruit category you could use the following bit of code:

<?php
  $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
  if ($children) { ?>
  <ul id="mainNav">
	<div id="locationsNavHead">choose a product</div>
  <?php echo $children; ?>
  </ul>
<?php } ?>

On Subpages

For child, or subpages, we could use the following bit of code:

<div id="sidebar">
<?php
//list subpages even if on a subpage
  if($post->post_parent)
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  else
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  if ($children) { ?>
  <ul id="mainNav">
  <div id="locationsNavHead">choose a product</div>
  <?php echo $children; ?>
  </ul>
<?php } ?>
</div>

If you are confused at what this all means please comment below and check out wp_list_pages() over at the WordPress Codex

With 3 comments

Posted in HTML,PHP,Wordpress

Tagged with

Google Unveils the Google Font Directory and API

   Posted: May 19th, 2010    By: Devin Walker   

Google is looking to help all of us web and graphic designers out there who have been trying to break free of the CSS font-family limitations. How are they doing this? Today Google released the Google Font Directory and Google Font API in attempts to bring a selectable and dynamic font solution to the web. I'm expecting the directory in the future this solution will grow to become the web's leading robust and scalable font library and API.

The good things about this web font solution is that it is very easy to implement and the text is completely selectable (for copy-and-paste purposes). The downsides (both will eventually become irrelevant) are that not every browser will support it... mostly the old school ones that no one should care about anymore, and that it in it's current state the Google Font Directory is limited to a about 20+ fonts (of which you'd probably use about 10). As the web continues to evolve both of these 'downsides' will no longer be relevant.

Google Web Fonts
Using the Google Font API and Directory

Read the rest of this entry »

WordPress: If URL is Homepage then do this…

   Posted: May 19th, 2010    By: Devin Walker   

Question: In WordPress how to I make sure the page loaded is the homepage URL and display some data if the standard WordPress Conditional Tags are not working for my theme?!

Answer: Here's a quick snippet of code that will give you an option to do something if these WordPress basic conditional tags are not working in whatever theme you are coding. Before we go any further I want to make sure that you have already tried to use the much simpler WordPress Conditional tags rather than using the method below.

I found this bit of code to be useful in the past when the handy WordPress conditional tags didn't work as intended and I needed another way to perform the same function. Hope you enjoy and please comment if you have any trouble with the code.

<?php
   // DLOCC If URL is Homepage then do this...
        $homepage = "/";
        $currentpage = $_SERVER['REQUEST_URI'];
        if($homepage==$currentpage):
    ?>
<div><p>My Info on Homepage</p></div>
<?php else: ?>
<?php endif; ?>

What this Conditional Statement Does

  1. sets the homepage variable as the url root
  2. checks the current url in the browser and sets that as the current page variable
  3. sets the conditional if the two variables are the same value then do something

    With 9 comments

    Posted in Wordpress

    Tagged with

    WordPress Loop: If Parent or Child of Page or Category

       Posted: May 18th, 2010    By: Devin Walker   

    The WordPress loop is extremely useful when developing customized WordPress solutions. One bit of code I've had to use often is one that will display a set of code if the page or post is a parent of child of a certain category. This is an easy way to display, output, or show data on all of your WordPress pages that are a parent or child of a specific category.

    Read the rest of this entry »

    No comments :[

    Posted in Wordpress

    Tagged with