Using two permalink structures for 2 types of posts - reactjs

I'm new to wordpress and currently facing an issue on permalinks.
For example I have a page for privacy policy and the permalink for that page is like this
https://testsitename.io/privacy
Above page works with the this permalink structure in permalink settings
https://testsitename.io/archives/123
I also integrated a react app to wordpress and, the react app produces a permalink like
https://testsitename.io/crazy_droid
Above page loads with a custom permalink structure of https://testsitename.io/%post_id%
The issue is when i select a permalink structure i can only get one type of page to load. Other page will give a 404 not found error. How can i fix this issue .
NOTE: i'm a newbie to wordpress
UPDATE:
For the react app, url is created through a register_post_type as follows
function custom_post_type()
{
register_post_type(
'expert',[
'public' => true,
'label' => 'Experts',
'rewrite' => array( 'slug' => '/' ),
'supports' => array( 'title','editor','thumbnail' )
]);
}

Related

How to have different dashboards based on roles with cakedc plugins / users & acl

I am using CakeDC Users & ACL plugins in my CakePhp app. I have different roles for my users in my app and I would like to have different dashboards based on roles after login.
I extend the plugin with my own table and controller based on the documentation here, so I have MyUsersController and MyUsersTable which override the initial files of the plugin, UsersController and UsersTable. Everything works fine. I create an event in my events.php file which contains:
use CakeDC\Users\Controller\Component\UsersAuthComponent;
use Cake\Event\Event;
use Cake\Event\EventManager;
EventManager::instance()->on(
UsersAuthComponent::EVENT_AFTER_LOGIN,
['priority' => 99],
function (Event $event) {
if ($event->data['user']['role_id'] === 'bbcb3031-ebed-445e-8507-f9effb2de026') //the id of my client role{
return ['plugin' => 'CakeDC/Users', 'controller' => 'MyUsers', 'action' => 'index', '_full' => true, 'prefix' => false];
}
}
);
But it seems like the override is not working because I have an error:
Error: CakeDC/Users.MyUsersController could not be found.
In my URL I have /users/my-users instead of /my-users and I don't know why. I have test with a template file which is include in the plugin and the Users controller like this:
function (Event $event) {
if ($event->data['user']['role_id'] === 'bbcb3031-ebed-445e-8507-
f9effb2de026') //the id of role{
return ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile';
}
And it works. My URL redirect after login as a client is /profile.
Could someone help me to understand? Please tell me if it's not clear enough and if it's missing parts of codes that might be important to understand my problem.
I specify that I am beginner with Cake.
Your custom controller doesn't live in the CakeDC/Users plugin, hence you must disable the plugin key accordingly, so that the correct URL is being generated (assuming your routes are set up correctly) that connects to your controller, like this:
[
'plugin' => null,
'controller' => 'MyUsers',
'action' => 'index',
'_full' => true,
'prefix' => false
]
That would for example match the default fallback routes, generating a URL like /my-users.
See also:
Cookbook > Routing > Creating Links to Plugin Routes

Dynamic base url with drupal and angularjs

I have create 2 angular app into drupal 7 like "example.com", "example.com/app1", "example.com/app2".
example.com is my main site. So, when I set html5 pushstate enable for removing hash in angular apps, I got nobase error from angularjs. Coz,
<base href="">
require for enable angularjs html5 pushstate.
My question is, since i have multiple angualr app in this drupal site, how can i dynamically add conditional base url for "/app1" and "app2" ?
anybody can help me? Waiting for response. Thanx.
You can add base element to your site in this way:
YOUR_THEME_NAME_preprocess_html(&$variables, $hook) {
$url = 'default';// default url
if($application1) {// your condition for app1
$url = 'app1';
} elseif($application2) {// your condition for app2
$url = 'app2';
}
$data = array(
'#tag' => 'base',
'#attributes' => array(
'href' => $url,
),
);
drupal_add_html_head($data, 'base_href');
}
Put it into your template.php

How To display data from API in drupal page or in View?

How to call API in drupal and display data from that API in to page or create drupal view of that API data? I want to display data that is coming from API in drupal page or i want to create view of data that is coming from API. If anyone knows this, please share in details.
You can simply create a drupal module for webservices or api.
In hook menu, you can provide the url and function info like this
$items['api/v1.0/projectListings'] = array(
'title' => t('Project Listings'),
'description' => t('Project listings '),
'page callback' => 'project_listings',
'access callback' => TRUE,
);
On call back function you can query your needs
function project_listings(){
//get the data eg: $data
echo json_encode($data);
}
Using hook menu url you can retrive the data and use in the page you want by decoding the received JSON data

Rewrite url in CakePhp

I'm new to Cakephp.
I have a home page with a lot of links like /mark-james.hmtl.../steve-pain.html, etc.
I want to display the personal page after the user clicks on the name, how can rewrite that?
Obviously now I have: Error: mark-james.hmtlController could not be found.
Router::connect(
'/user1-home-page',
array('controller' => 'users', 'action' => 'user1')
);
http://book.cakephp.org/2.0/en/development/routing.html
You can define routing as mentioned above.

Cakephp routing only for frontend pages without a prefix

I am working on site
http://solarsmart.com.pk/
and I have created a controller and action for pages which gets all the pages data from database on the basis of last two values from the following url
http://solarsmart.com.pk/pages/page/about/about-us
I want to remove /pages/page which are controller and action respectively. if I set the route as follows
Router::connect('/*', array('controller' => 'pages', 'action' => 'page','manager'=>FALSE));
It works but then the problem arises that the admin routing pages also redirect to pages/page I want them to remain as they are right now
I had the same problem and what I did following
I got the url from the Router Class like
$curUrl = Router::url();// returns the current url of the page
$curUrl = explode('/', $curUrl); // exploding on the base of '/'
then I checked that if the url has the required prefix or not
which in your case will be like the following
if (!in_array('admin', $curUrl)) {
Router::connect('/*', array('controller' => 'pages', 'action' => 'page', 'admin' => FALSE));
}

Resources