【问题标题】:user comments display on wordpress page用户评论显示在 wordpress 页面上
【发布时间】:2016-10-21 00:01:35
【问题描述】:

希望实现类似于此页面的内容,用户可以在表单字段中输入想法,然后在提交时直接发布到页面上。

http://hcma.ca/

使用 wordpress cmets 最适合这个吗?或者以某种方式发送表单提交以填充页面上的转发器高级自定义字段。谁能建议如何最好地实现这一目标?

还想知道垃圾邮件。上面的网站没有验证码或类似的(据我所知)。这有什么关系?

谢谢!

【问题讨论】:

    标签: wordpress comments spam


    【解决方案1】:

    如果您不想使用付费插件,您可以创建一个新的自定义帖子类型,然后在您想要的页面上显示结果。你应该关注这个tutorial here

    简而言之:

    创建一个新的帖子类型:

    // Our custom post type function
    function create_posttype() {
    
        register_post_type( 'movies',
        // CPT Options
            array(
                'labels' => array(
                    'name' => __( 'Movies' ),
                    'singular_name' => __( 'Movie' )
                ),
                'public' => true,
                'has_archive' => true,
                'rewrite' => array('slug' => 'movies'),
            )
        );
    }
    // Hooking up our function to theme setup
    add_action( 'init', 'create_posttype' );
    

    在页面中显示结果:

    <?php 
    $args = array( 'post_type' => 'movies', 'posts_per_page' => 10 );
    $the_query = new WP_Query( $args ); 
    ?>
    <?php if ( $the_query->have_posts() ) : ?>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <div class="entry-content">
    <?php the_content(); ?> 
    </div>
    <?php wp_reset_postdata(); ?>
    <?php else:  ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    

    然后您可以使用这个免费插件添加Google reCaptcha 以避免垃圾邮件

    【讨论】:

    • 感谢 Tasos,我明白了,但是我如何拥有网站访问者可以填写的前端表单并填充 CPT?
    • 检查此答案,您可以在其中为自定义帖子类型创建表单提交wordpress.stackexchange.com/q/11288/40793 如果您对答案感到满意,则应将其标记为已接受(绿色勾号)并投票想要
    猜你喜欢
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    相关资源
    最近更新 更多