Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

advanced customization WordPress

  • SOLVED

I need an interface that can be changed easy by the administrator.

In the page administration I added the possibility to php eval any function, so the administrator can in theory do whatever she wants. I will make a pretty administration out of this, but before I do it I wanna hear your thoughts.

I have a page called 'index' and I made an url rewrite to show the page 'index' instead of index.php. Then I realized I can do the same with 404.php, archive.php and so on. I think I will make pages of everything, and if the administrator wants to change some tiny message she can do it very easy.

Now I wanna know if this is stupid or not. If it's not too stupid, should I bother to make my custom functions as a kind of widgets? Any other good advice?

Answers (4)

2011-01-30

Michael Fields answers:

IMHO it's a bad idea to use pages for such a thing. I would also suggest not overriding template hierarchy at all. In my experience you will get the best results if you work with WordPress. The best solution here is to probably create a custom post_type for "sections" or something similar:
function mfields_register_section_post_type() {
register_post_type( 'mfields_section', array(
'public' => false,
'show_ui' => true,
'publicly_queryable' => false,
'rewrite' => false,
'query_var' => false,
'show_in_nav_menus' => false,
'can_export' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor' ),
'labels' => array(
'name' => 'Sections',
'singular_name' => 'Section',
'add_new' => 'Add New',
'add_new_item' => 'Add New Section',
'edit_item' => 'Edit Section',
'new_item' => 'New Section',
'view_item' => 'View Section',
'search_items' => 'Search Section',
'not_found' => 'No Sections found',
'not_found_in_trash' => 'No Sections found in Trash'
)
)
);
}
add_action( 'init', 'mfields_register_section_post_type', 0 );


You could then create a new "Section" with a title of "404" and use the content box to store whatever text/images you need. Once this is done, create a 404.php file in your theme and add code similar to the following:

<?php
$sections = get_posts( array(
'post_type' => 'mfields_section',
'post_title' => '404',
) );
if ( isset( $sections[0] ) ) {
global $post;
$post_backup = $post;
$post = $sections[0];
setup_postdata( $post );
the_title( '<h2>', '</h2>' );
the_content();
$post = $post_backup;
}
?>


This code will display the first section with a title of "404". This is the most flexible solution IMO. If an end user accidentally deletes the section, a new one can easily be created and will display in the appropriate template based on it's title.

Best Wishes,
-Mike


Daniel Wahlqvist comments:

I was thinking 'pages' but you're absolutely right, I should treat this as a custom type. I will do it like you suggest.

I might post more detailed questions when I have implemented this in more detail. Thanks for the ideas!

2011-01-30

Peter Michael answers:

Have you read [[LINK href="http://codex.wordpress.org/Template_Hierarchy"]]http://codex.wordpress.org/Template_Hierarchy[[/LINK]] ?


Daniel Wahlqvist comments:

Yeah,
I've read that. I wanna override it all, I want everything to happen in page.php so that it can be customized in the administration of pages.

My question is if that's a good or bad idea and if anyone have any advice.


Peter Michael comments:

I think it's a bad idea & overkill. You should probably create widgets & shortcode functions, but the again, it depends on your project.

Also, maybe custom post types are a solution for you?


Daniel Wahlqvist comments:

Yeah, I guess my idea might be overkill. Would you like to give me hints about an alternative?

Shortcodes are excellent I think, however, shortcodes can only be used in pages, am I right? That disturbs me.

How do I get something similar in the templates? I guess I could use widgetareas but I think it would be ugly to solve the same problem with widget areas and shortcodes depending on the type of page. Also, the widget adminstration could quickly become confusing if the site is big (my site is semi-big but I'm trying to plan ahead).

Another idea is to hardcode a page into each template, that way I can run any custom shortcode. That would certainly be less complex than a lot of url rewrites.

I have several custom post types and several custom taxonomies. The site has 10k articles, so there's a big need to be flexible about how to show it for the user.

2011-01-30

Maor Barazany answers:

It really depends on what you want to achieve. I think it's not a good idea, since eval() function has many security holes and can be exploited.
Also, why does the admin have to deal with php? I think it's better to develop widgets with option fields and also option page(s) to allow the admin easily change what it needed. You have to know what things on the site should be changed dynamically and by that to develop the option page and the custom widgets. For my opinion, this is a much better approach in all manners.

2011-01-31

rilwis answers:

I don't think it's a bad idea. At least it gives you a possibility of <strong>expanding </strong>current WP template hierarchy. Yes, I emphasize expanding, that means not overloading (overkilling) WP template hierarchy. You should use it with its own power, and coordinate with WP template hierarchy.

Like you said, I'm imaging a new template system that you can create. Instead of overloading WP template hierarchy, you can use it for specific needs, like this:

You create a download site that one page of downloading need 2 or more steps. All of these steps are using one post's data, but each step takes one part of this data and show to user. With your new template system, you can easily do this (I hope so).

I'm not feeling really good with current WP template hierarchy, especially when it comes with custom post types. In very small cases, the URL can be recognize in several ways, and might cause an error. I think if your code can overkill this, then it's good.

This is one thing. The 2nd thing I think it's good is the client can easily choose which page can be displayed. Not all clients know coding. If the usability of your code can satisfy a large number of clients, why don't you make your own version?