Add “custom page” without page

后端 未结 3 1435
逝去的感伤
逝去的感伤 2020-12-12 05:43

The title might not be completely clear, but I didn\'t know how to ask this in another way.

I want to build a system in Wordpress where the user can put some projec

相关标签:
3条回答
  • 2020-12-12 06:17

    basically you can do this by creating a rewrite rule and then point to a file.

    add_action('init', 'add_rewrite_rule');
       function add_rewrite_rule(){
       // add_rewrite_rule(REGEX url, location, priority (i.e. top is before other rewrite rules)
       //basically tell wordress to add a query var if sidebar is added to url. change sidebar to what you want your link to be.
       // i set up a custom post type to make this work called custompostype..it does nothing but just to give post_type a value. 
       add_rewrite_rule('^sidebar?','index.php?is_sidebar_page=1&post_type=customposttype','top');
    }
    
    // register a query var
    add_action('query_vars','market_set_query_var');
    function market_set_query_var($vars) {
       array_push($vars, 'is_sidebar_page');
       return $vars;
    }
    
    // associate a template with your quer_var 
    add_filter('template_include', 'market_include_template', 1000, 1);
    function market_include_template($template){
        if(get_query_var('is_sidebar_page')){
        $new_template = (theme or plugin path).'/pages/yourpage.php'; // change this path to your file 
    if(file_exists($new_template))
        $template = $new_template;
    } 
    return $template;
    }
    

    after adding any rewrite rule, the changes wont take place until you go into settings->permalinks and hit the "save" button.

    0 讨论(0)
  • 2020-12-12 06:30

    Sorry i didn't got your question properly. but some what say to create Custom post or taxonomy :

    Please check below link

    Custom Post and Taxonomies

    0 讨论(0)
  • 2020-12-12 06:41

    In your functions.php file add this anywhere:

    function themeslug_projects() {
        $args = array(
          'public' => true,
          'label'  => 'Projects', 
    
          'rewrite' => array( 'slug' => 'projects' ),
        );
        register_post_type( 'projects', $args );
    }
    
    add_action( 'init', 'themeslug_projects' );
    

    Do save your permalink settings again after doing this, this will work surely then..

    0 讨论(0)
提交回复
热议问题