Posts Tagged ‘WordPress’

Operation n » Writing Secure WordPress Plugins

This article discusses two things that all WordPress plugins should do.

Operation n » Writing Secure WordPress Plugins.

New Theme

I have installed a new theme that does almost everything I want from a theme. I just had to fiddle with the default link widget to get my dynamic links. This theme is available from Bytes for All.

Page Pertinent Link Lists

I’m using WordPress as a web site management tool. As such, on my pages I want to have only those links that are pertinent to the page in the link list. This can be done automatically by firs managing the link list categories to have slugs that match those of the page they belong to. Then the following code is place in the right-sidebar.php file:

right-sidebar.php
  1. <?php if (is_home() || is_front_page()) {
  2.     echo "<li><h2>"; _e('Recent Posts','andreas09'); echo "</h2>\n<ul>";
  3.     wp_get_archives('type=postbypost&limit=10');
  4.     echo "</ul></li>\n";
  5. } ?>

This will place the recent posts widget on the home page and post page.

  1. <?php
  2. $cat_found = 0;
  3. // Get all the link categories
  4. $categories = get_categories('type=link');
  5. foreach ($categories as $cat) {
  6.     // If the category slug matches the page slug
  7.     if ($post->post_name == $cat->category_nicename) {
  8.         // no more looking
  9.         $cat_found = 1;
  10.         // output bookmarks from the category found
  11.         wp_list_bookmarks('category='.$cat->cat_ID);
  12.         // done
  13.         break;
  14.     }
  15. }
  16.  
  17. // If no categories match the page, output default bookmarks
  18. if ($cat_found == 0) {
  19.     echo "\n<!– default –>\n";
  20.     wp_list_bookmarks('category=8&orderby=updated&show_updated=1');
  21.     wp_list_bookmarks('category=2');
  22. }
  23. ?>

Updated to WordPress 2.6.2 so here is the new wp_widget_links from widgets.php:

  1. function wp_widget_links($args) {
  2.     global $post;
  3.  
  4.     extract($args, EXTR_SKIP);
  5.  
  6.     $cat_found = 0;
  7.     $categories = get_categories('type=link');
  8.     $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
  9.  
  10.     foreach ($categories as $cat) {
  11.         echo "<!– post_name ", $post_ID, " ", $post->post_name, " category_nicename ", $cat->category_nicename, " –>\n";
  12.         if ($post->post_name == $cat->category_nicename) {
  13.             $cat_found = 1;
  14.             wp_list_bookmarks(apply_filters('widget_links_args', array(
  15.                 'title_before' => $before_title, 'title_after' => $after_title,
  16.                 'category_before' => $before_widget, 'category_after' => $after_widget,
  17.                 'show_images' => true, 'class' => 'linkcat widget', 'category' => $cat->cat_ID
  18.             )));
  19.             break;
  20.         }
  21.     }
  22.  
  23.     if ($cat_found == 0) {
  24.         wp_list_bookmarks(apply_filters('widget_links_args', array(
  25.             'title_before' => $before_title, 'title_after' => $after_title,
  26.             'category_before' => $before_widget, 'category_after' => $after_widget,
  27.             'show_images' => true, 'class' => 'linkcat widget', 'category' => 8
  28.         )));
  29.         wp_list_bookmarks(apply_filters('widget_links_args', array(
  30.             'title_before' => $before_title, 'title_after' => $after_title,
  31.             'category_before' => $before_widget, 'category_after' => $after_widget,
  32.             'show_images' => true, 'class' => 'linkcat widget', 'category' => 2
  33.         )));
  34.     }
  35. }

Style and Cheat Sheets

I’ve added a new set of pages for Cheat Sheets of things I do regularly, but not regularly enough to remember the exact syntax. I copied the first one from Samat Jean’s blog so I had to make his style work for me. His html looks like this:

<div class="codeblock"><code>some code</code></div>

So I had to try to make this work with the andreas09 theme I’m using. Turned out to be simple to add this to the style.css file:

/* CodeBlock */
.codeblock {
    padding: 5px;
    border: 1px solid #CCC;
    background-color: #EEE;
    font-size:1.6em;
}

Form my own in-line code, I prefer:

pre {
        border: 1px dashed #bbb;
        font-size: 75%;
        padding: 5px;
        color: #202020;
        background: #F1F1FF;
        overflow: auto;
        font-size:1.6em;
}

So it turns out if I simple get rid of the Code Block entry and define a style for code I get what I want, almost:

code {
    border: 1px dashed #bbb;
    font-size: 75%;
    padding: 5px;
    color: #202020;
    background: #F1F1FF;
    overflow: auto;
    font-size:1.6em;
}

But not quite.

Visitors

Site Links

  • Blackberry Forums
  • Blackberry Support Forums
  • FreshMeat
  • Radio Electronics
  • SlashDot
  • Smiths Falls Weather
  • Stack Overflow
  • XKCD
  • Yahoo Groups

Blogroll

Meta