$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom post types - Create a simple Testimonial page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom post types - Create a simple Testimonial page

matteradmin10PV0评论

I'm new to Wordpress theme development. I'd like to make a simple Testimonial page that a non-technical user can add more testimonial later. Here's the example of the page: Testimonials page

I'd like to have a admin screen where user input the name, upload the picture, and the testimonial detail. After that the testimonial item can be add to the page.

Please show me how to approach this. What is the right direction to go about this?

I'm new to Wordpress theme development. I'd like to make a simple Testimonial page that a non-technical user can add more testimonial later. Here's the example of the page: Testimonials page

I'd like to have a admin screen where user input the name, upload the picture, and the testimonial detail. After that the testimonial item can be add to the page.

Please show me how to approach this. What is the right direction to go about this?

Share Improve this question asked Mar 16, 2017 at 14:49 Long NguyenLong Nguyen 133 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 1

I would suggest a custom post type for your Testimonials. Each will be created as an individual post and you will have the ability to query, sort, categorize, your testimonials just as you can with blog posts, or any other post type. Non-technical site admins can simply "add new testimonial" and edit existing, etc, just as if they were working with pages, blog posts, etc

You must register your testimonial post type for that to happen. An extremely simple example. You will want to define many more of the optional parameters than this example:

function wpse_register_post_types() {
$args = array(
  'public' => true,
  'label'  => 'Testimonials'
);
register_post_type( 'testimonial', $args );
}

add_action( 'init', 'wpse_register_post_types' );

Full WP Codex documentation here: https://codex.wordpress/Function_Reference/register_post_type

This is an extremely simplified example to show the basics: create a function to handle registration, hook that function to WP's init action.

In a real application you will want to define your labels and other arguments for the register_post_type() function.

Depending on how you intend to use the testimonials on the front end, you will need templates for your new custom post type:

archive-testimonial.php <-- this will display all of the published testimonials; your example page single-testimonial.php <-- used to display a single testimonial; when a user clicks through to see all of the details on a single testimonial

This will get you started. For advanced features, like displaying random testimonials on a page, you'll want to read up on using the WP_Query class for custom queries.

Welcome to WPSE!

You could also consider enabling comments. Whether the admin user inputs them or customers input them directly, as long as they're moderating comments, new ones wouldn't show up until an admin had approved them. This would restrict the testimonials to only appear on the page where the comments are added, but would be simpler code-wise. Depends on whether they may want to feature testimonials in other areas later.

Post a comment

comment list (0)

  1. No comments so far