Kwebble : Blog

Label: wordpress

  • Showing related articles in a WordPress blog

    Gepubliceerd op 16 juli 2009 in Programming.

    A few days ago I made a small change to the site. On pages showing a single article, the sidebar now shows a list of related articles on the site. By exposing these articles I hope visitors will find other interesting stuff to explore on this site.

    The WordPress plugins to add related articles I found seemed a bit to complex to me, so I was glad I found some PHP code to do the same. This code looks for other articles with the same tags as the displayed article. I changed it a bit into a separate part that retrieves the articles and a part to display them.

    The only thing I need to do now is to tag all the older articles, since I only started tagging recently.

    • php
    • wordpress
  • Archives for a category WordPress plugin

    Gepubliceerd op 15 augustus 2007 in Programming. 167 reacties

    For the new version of this website I wanted to show a list of monthly archives, limited to posts of a specific category. The software used to run this website is WordPress but the wp_get_archives() function, to get a list of archives, does not have the ability to filter on category. So I created the ‘Archives for a category’ plugin that enhances this function to show archive links for a specific category.

    Installation

    1. Download the plugin zip file and unzip the file in a temporary directory.
    2. Put the kwebble_archives_by_cat.php file in your WordPress plugin directory:
      <your wordpress dir>/wp-content/plugins
    3. Activate the plugin ‘Archives for a category’ on the Plugin Management page of the WordPress administration panel.
    4. Optionally disable the canonical URLs from the menu Settings | Kwebble.
      A WordPress feature added in version 2.3, called canonical URLs, redirects browsers on certain URLs. This also happens with the URLs for the archives with a cat parameter. This causes the archive pages to contain posts which do not belong to the selected period.

      To solve this problem the plugin can disable canonical URLs. This uses the technique used in the Disable Canonical URL Redirection plugin Mark Jaquith made. So if you are already using that plugin you don’t need to change the setting for this plugin.
      To disable canonical URLs go to the administration section of your blog, choose Settings and the Kwebble settings. On that page you will find a checkbox to disable canonical URLs.

    Usage

    After installing and activating the plugin the wp_get_archives() function accepts a ‘cat’ parameter to specify the categories of posts to show in the list of archives. The value of the ‘cat’ parameter must be a list of one or more category ID’s, separated by comma’s.

    If you specify the value of a category ID the posts from that category will be used to create the list of archives. If you place a minus sign ‘-’ in front of an ID the posts from that category will be excluded.

    Depending on the number of categories, your use of them and selection of categories to include in the archive list it may be easier to specify all categories to include or just those to exclude.

    You need to make sure the template used to show each archive displays posts from the selected category. I’m using category specific templates on this site, like category-id where id is the ID of the category to display. You can use other templates in the template hierarchy, but make sure the template shows items of the categories you specify.

    At some WordPress version the categories ID’s are no longer visible on the administration pages. You can find the ID of a category by opening the page to edit the category and inspect the URL of that page. The value after cat_ID= is the ID of the category.

    Examples

    Show the default monthly list of archives for category 1:

    <?php wp_get_archives('cat=1'); ?>
    

    The same list, but with posts from categories 1 and 3:

    <?php wp_get_archives('cat=1,3'); ?>
    

    Use posts from all categories except category 2:

    <?php wp_get_archives('cat=-2'); ?>
    

    Use posts from all categories except categories 2 and 8:

    <?php wp_get_archives('cat=-2,-8'); ?>
    

    Create a list of archives for category 1 as a dropdown box:

    <?php wp_get_archives('format=option&cat=1'); ?>
    

    Limitations

    This plugin does not work for weekly archives. The list with archive links is correct, but the links themselves do not include the category. So when used, WordPress will not filter the resulting page on the category. The technical reason is that WordPress does not apply filters when the links for weekly archives are generated, so the plugin can’t change them. Perhaps in a next version of WordPress…

    This plug-in was developed and tested to work correctly with WordPress version 2.7.1, but it probably works with earlier versions back to 2.2.1.

    Older versions

    These are earlier versions of the plugin. Use them only if you have a specific reason for not installing the current version.

    Version 1.4a

    27-03-2009 Download

    • Corrected post count when posts belong to multiple categories.
    • SQL queries now respect the configured SQL table prefix.
    • Templates with multiple calls to wp_get_archives(), with and without ‘cat’ parameter, generate correct URL’s.

    Version 1.4

    22-02-2009 – Added option to exclude categories. Download.

    Version 1.3

    6-01-2008 – Added support for multiple categories. Download.

    Version 1.2

    23-11-2007 – Added support for WordPress 2.3.1. Download.

    Version 1.0

    15-08-2007 – Initial version, works with WordPress 2.2.1. Download.

    Copyright

    Copyright 2007, 2008, 2009 Rob Schlüter. All rights reserved.

    Licensing terms

    • You may use, change and redistribute this software provided the copyright notice above is included.
    • This software is provided without warranty, you use it at your own risk.
    • php
    • plugin
    • wordpress
  • Putting the geo position in a Wordpress RSS feed

    Gepubliceerd op 2 oktober 2005 in Programming. 3 reacties

    The last few days I’ve been looking at adding geographic information to articles on this website. For WordPress, the software this site is running on, I found the Geo plugin with which you can store geographic coordinates for an article. The plugin adds this information to the page of each article, but not in the RSS feed, so I made a function that does this, though not automatically.

    To use it, start with adding the following function to the Geo plugin. I’m using version 1.0, don’t know if it works in earlier versions:

    /**
     * Returns the tags with geo information for inclusion in RSS 2.0 feeds.
     *
     * Include a call to this function inside the <item> tag to
     * add tags with geo information if available.
     * To keep the feed valid add these namespace declarations to the <rss> tag:
     *    xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
     *    xmlns:icbm="http://postneo.com/icbm"
     *    xmlns:geourl="http://geourl.org/rss/module/"
     */
    function get_the_rss_geotags() {
    	global $wp_query;
    
    	if(!get_settings('use_geo_positions')) return;
    
    	list($lat, $lon) = split(',', get_post_meta($wp_query->post->ID, '_geo_location', true));
    	if ($lat == '' || $lon == '') {
    		if (get_settings('use_default_geourl')){
    			// send the default here
    			$lat = get_settings('default_geourl_lat');
    			$lon = get_settings('default_geourl_lon');
    		}
    	}
    	if ($lat != '' && $lon != '') {
    		echo "<geo :lat>$lat</geo><geo :long>$lon</geo>\n"
    				. "<icbm :latitude>$lat</icbm><icbm :longitude>$lon</icbm>\n"
    				. "<geourl :longitude>$lon</geourl><geourl :latitude>$lat</geourl>\n";
    	}
    }
    

    Now you can add this line to wp-rss2.php, somewhere inside the <item> tag:

    <?php echo get_the_rss_geotags(); ?>
    

    Also remember to add these namespace declarations to the rss tag:

    <rss version=”2.0”
    	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
    	xmlns:icbm="http://postneo.com/icbm"
    	xmlns:geourl="http://geourl.org/rss/module/">
    

    That’s it.

    • geocode
    • php
    • plugin
    • rss
    • wordpress
  • Easy publishing with the WordPress bookmarklet

    Gepubliceerd op 20 augustus 2005 in Programming. 2 reacties

    WordPress includes a bookmarklet for easy publishing. Use it on a page you want to write about and you get the Write Post form with the title and selected text already filled in. To get the advanced editing form for the new post I applied the WordPress Bookmarklet Hack.

    I also added a line of JavaScript in the <head> part of the bookmarklet.php file to bring the edit window in front automatically:

    <script type="text/javascript">window.focus();</script>
    

    Then I changed the bookmarklet itself to remove the window settings from the created window. That changes the editing window to a complete browser window with all parts available. This is done by changing:

    'scrollbars=yes,width=600,height=460,left=100,top=150,status=yes'
    

    of the bookmarklet to:

    ''
    
    • bookmarklet
    • javascript
    • wordpress
  • Searching pages in WordPress 1.5

    Gepubliceerd op 20 februari 2005 in Programming. 2 reacties

    Update (march 6, 2004): David B. Nagle made a plugin which gives the same results as this hack, but does it the right way, using the plugin system. Use it instead of hacking as described below.

    A few days ago version 1.5 of WordPress was released. One of the interesting new features is the addition of pages. You use pages for static content on a site, which means you can now use WordpPress to build a larger part of you site. Very useful.

    But one thing I don’t understand is why pages are left out of search results? Through a thread on the support site I found a bug report that states This is intended behaviour until we revamp search.. So I looked for a solution.

    Hacking the search function

    Warning: This describes a change to one of the core WordPress files. It may introduce bugs or unwanted side effects when used. I haven’t done much testing, but it seems to work ok.
    I you decide to use this hack it’s your choice, you are responsible, not me. If you’re not comfortable with it don’t apply the change.

    To have the search function also return pages I changed classes.php. You find this file in the wp-includes directory. On line 493 this piece of code starts:

            if ($this->is_page) {
                $where .= ' AND (post_status = "static"';
            } else {
                $where .= ' AND (post_status = "publish"';
            }

    Change it to the following:

            // 2005-02-20, Rob Schluter: Hack to search posts & pages.
            if (!empty($q['s'])) {
                $where .= ' AND ((post_status = "static" or post_status = "publish")';
            } else{
                if ($this->is_page) {
                    $where .= ' AND (post_status = "static"';
                } else {
                    $where .= ' AND (post_status = "publish"';
                }
            }
            // end hack
    

    That’s it, put the changed file on your server and the search should work for pages also.

    • php
    • search
    • wordpress
  • Rubrieken

    • Artikelen
    • Foto's
    • Links
    • Media
    • Overheid
    • Programming
  • Recente Berichten

    • Tip: use the axis:axis:1.4 Maven artifact if you need Axis 1.4 support
    • Google Closure tools
    • Google en Microsoft indexeren tweets
    • De route van de Stad Amsterdam
    • Analoog of digitaal – maak je keuze
  • Abonneren

    • Atom feed Artikelen
    • Atom feed Reacties
  • Archief

© Rob Schlüter - Contact