Skip to content

Instantly share code, notes, and snippets.

@q2amarket
Last active Feb 14, 2018
Embed
What would you like to do?
This code will allows to create custom page without creating a page in admin > page area. This will create automatically and doesn't require any page creation in plugin section too. Replace your-page to what you like

#Create Page With Plugin

This code will allows you to create page without adding page in Admin > Pages area. This page can be set as a home page by defining constant path in qa-config.php. Also you can create menu link by adding page request (page slug e.g. your-page).

##Usage

  • Create directory in qa-plugin. for example: your-site/qa-plugin/your-page
  • Place qa-plugin.php and your-page.php file in your-page directory you created in above step

###Optional To make page as a home page

  • In qa-config.php file copy code from this Gist qa-config.php code and paste into your qa-config.php file as metnioned.

To add navigation menu

  • Go to Admin > Pages click on Add Link button
  • Set Text/Lable in Text of link
  • Position as you want
  • Visibility as you want
  • Url of link you can only place page slug. for example your-page this is relative url. Or you can add absolute url by http://your-site.com/your-page
<?php
//find $QA_CONST_PATH_MAP=array( around line #99 in qa-config.php
// after that comment add below code to make your page as a home page.
// you do not need to either create a page or add any menu item.
$QA_CONST_PATH_MAP=array(
'your-page' => '' //your-page is the (url)request of your page
); // this will make 'your-page' as home page of your site.
<?php
//Make sure you need to register your plguin using metadata.json (for q2a 1.7+) or plugin metadata comment (for q2a below 1.7)
// register page module
qa_register_plugin_module('page', 'your_page.php', 'your_page_class', 'Page Title');
<?php
class your_page_class
{
var $directory;
var $urltoroot;
public function __construct()
{}
public function load_module( $directory, $urltoroot )
{
$this->directory = $directory;
$this->urltoroot = $urltoroot;
}
public function match_request( $request )
{
$parts = explode( '/', $request );
return $parts[0] == 'your-page';
}
public function process_request( $request )
{
$qa_content = qa_content_prepare();
switch( $request ) {
case 'your-page':
//add your code/logic/content here
break;
default:
//your default code
}
//you can also use if/else instead of switch case
if ( $request == 'your-page' )
{
//your code here
}
//finally return $qa_content
return $qa_content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment