Skip to content

Category: Wordpress

Creating a dropdown menu in WordPress

In wordpress 3.0 and above there is a nice build in menu. To create a drop down menu using this menu system follow there articles:

http://new2wp.com/pro/jquery-drop-down-menu-wordpress-3-menu/

http://wphacks.com/top-5-wordpress-navigation-menu-tutorials/

This is the main code in the CSS to achive the result:

#menu-header ul ul {
	display: none; /* For testing, change to display: block; */
	list-style:none;
	z-index:100;
}
#menu-header ul li:hover > ul {
	display: block;
}

How to display an archive with all postst in WordPress?

To do this add another page template in your theme’s folder.

You could create a Page (Write > Write Page) called…,  that just uses a custom Page template implementing query_posts().

I do something similar on my site but don’t list every post! Just the categories with description and such. However, one can combine the idea of a Category Page with what I do on my ‘Archive’ Page:

Sometimes the  function wp_query(); brakes the pagination, so if this hapens use this code insted:

<?php $limit = get_option('posts_per_page'); 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
query_posts('showposts=' . $limit . '&paged=' . $paged); 
$wp_query->is_archive = true; 
$wp_query->is_home = false; ?>

Notes:

$limit is assigned the ‘posts_per_page’ option from your WordPress settings, but can be changed to something else if you like:

$limit = 20;

These:

$wp_query->is_archive = true; $wp_query->is_home = false;

after the query_posts() are important as they force posts_nav_link() (and so pagination) to work, along with a few other helpful results gained for fooling WordPress into thinking we’re in the archive pages.

For the $paged stuff, see:
http://wordpress.org/support/topic/57912#post-312858

For more info: http://wordpress.org/support/topic/querying-all-posts

Allow member to have access to custom post type only. Permission to only edit their own posts

Here’s the solution:

http://wordpress.stackexchange.com/questions/14553/allow-member-to-have-access-to-custom-post-type-only-permission-to-only-edit-th

Which says:

Use Justin Tadlock’s plugin “Members“. It gives you the ability to create new roles and edit existing roles, as well as add custom capabilities. All that work that you’d have to do can be taken down to a few clicks.

I know you said in your comment on ZaMoose’s answer that you are ‘looking to write the functionality myself so I have full control over everything.’ That’s missing the whole point of open source software. Justin Tadlock released his plugin so you could use it precisely so you WOULD have complete control over everything.

If you really really want to reinvent the wheel, potentially wasting hundreds of hours of your own time I can’t stop you, but you could at least save yourself the trouble and use Tadlock’s plugin to learn how to do what you want.

Once you have a plugin that does what you want, you’ll need to change the 'map_meta_cap' flag to true and the 'capability_type' flag in your post type registration function so that it says something other than ‘post’, ‘page’, or any other ‘reserved’ type. Then, duplicate all the capabilities related to posts (e.g. edit_posts, edit_others_posts, publish_posts, etc.), using your capability type instead of posts. Make sure to assign all these permissions to administrators (you won’t be able to see the post type until you do this), then create your role, mimicking the ‘contributor’ role’s abilities for your post type.

For example, say your capability type was foobars, you would want to give ‘shop owners’ the edit_foobars, delete_foobars, and read capabilities. That way they can create their own draft foobars, and delete those drafts, but because they don’t have publish_foobars capabilities, they have to submit them for approval. Because they don’t have edit_published_foobars, all modifications to an approved foobar have to be approved.

How to disable wordpress html filter for posts and pages?

In some versions of WordPress there is a filter that strips some tags from the html code. If you want to remove this filter just open wp-includes/kses.php and find this row:

function kses_init_filters() {
    // Normal filtering.
    add_filter('pre_comment_content', 'wp_filter_kses');
    add_filter('title_save_pre', 'wp_filter_kses');

    // Post filtering
    add_filter('content_save_pre', 'wp_filter_post_kses');
    add_filter('excerpt_save_pre', 'wp_filter_post_kses');
    add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}

and comment out the rows that you need:

function kses_init_filters() {
    // Normal filtering.
    add_filter('pre_comment_content', 'wp_filter_kses');
    add_filter('title_save_pre', 'wp_filter_kses');

    // Post filtering
    //add_filter('content_save_pre', 'wp_filter_post_kses');
    add_filter('excerpt_save_pre', 'wp_filter_post_kses');
    //add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}

Then if you save the post in html it’s OK, but if you switch to normal view and then go back to html view the tags could be stripped again. This hapens most likely from the MCE Editor and to resolve this issue you could install a plugin called TinyMCE Valid Elements or some similar plugin.

How to add extra sidebar to a WordPress theme?

To begin the tutorial, extract your theme into a folder and open it to see all the files. If your theme has only one sidebar, then most probably you will NOT find a file called functions.php in your theme folder. In that case you will have to create this file yourself. Just open notepad or any other code editor to start a new file. Put this code into that file:

Problem with category slug renaming in WordPress

I had a problem. I couldn’t change the category slug in some of my categories. So I found the solution at:

http://wordpress.org/support/topic/category-slug-cant-be-updated

The problem comes from the fact that the tags and categories are stored in the same table in the database. And the tags also have slugs. So if there is already a tag with the slug that you want to put in the category you can’t do it until you delete the tag or change it’s slug.

You just need to go to the tags table in the admin panel and change the tag slug that’s making the problem.

How to translate the WordPress Thesis Theme

WordPress Thesis Theme is shipped in English language only, but it provides also the strings to translate in a file in PO (GNU Gettext Portable Object) format.
The file is thesis.po and is located in the directory wp-content/themes/thesis of your WordPress installation. The file thesis.mo that you’ll find in the same directory is the same file but in the machine readable format.
To translate the Thesis’s strings in your own language follow these simple steps :

  1. set your preferred language in the file wp-config.php : for Italian, for example, define ('WPLANG', 'it_IT');
    See these instructions WordPress in Your Language for a complete guide.
  2. rename the thesis.po file using your language code (ex for Italian language in will be : it_IT.po)
  3. open the file with the text editor of your choice and translate the strings filling the msgstr value
  4. using the command-line utility msgfmt to create the machine readable file : msgfmt -o it_IT.mo it_IT.po
  5. copy the files it_IT.po, it_IT.mo into the wp-content/themes/thesis directory
  6. In thesis 1.8 or later copy the files it_IT.po, it_IT.mo into the wp-content/themes/thesis_18/lib/languages directory
  7. There may be missing strings, so add them to the .po file with Dreamweaver or notepad and generate the .mo file with poedit.