Language & url change in headless CMS - wordpress

I'm using Wordrpess as headlessCMS, nextJS, graphQL.
When i get my menu from wordpress it has links in this way
For ENG:
"/about-us"
For PL:
"/o-nas"
My goal is to have one template in my files, for example "/pages/about.js"; and then when user enters "/about-us" or "/o-nas" then "/pages/about.js" file is used (inside it, by useRouter I can detect if user is /en or /pl and then make specific query for data).
How can I create this kind of idk. 'redirection'? I tried using but i wasn't able to make anything working
https://i18n.nuxtjs.org/custom-paths/?fbclid=IwAR1k5T5AI5hX60ep4coXtOwUpXirNfc5W4-5NzVv-y0G7wLoPPKPAL4xNv4
https://nextjs.org/docs/advanced-features/i18n-routing
Can anyone help me or provide some kind of working example?

Related

nested pages in strapi and nextjs

So we want to create a big website with nextjs and strapi.
We sometimes have deep nested pages like
www.ourwebsite.com/onderwijs/bijbelscholen/parttime-bijbelscholen
How is this possible?
I have tried to setup dynamic routing in nextjs which is working fine, but I have a problem.
If I want dynamic routes which are all nested I need to do something like this:
I know it's ugly, I'm sorry.
so now when I go to
www.ourwebsite.com/onderwijs/bijbelscholen/parttime-bijbelscholen
I just get the latest word from the URL and take that and put that into my API to get the right data which is working fine! I configured strapi so it finds by slug and not by id. So my API URL looks like this: www.myStrapiInstalation/api/pages/parttime-bijbelschool
but when I go to
www.ourwebsite.com/onderwijs/parttime-bijbelscholen
It's also working! but that's not good! Because it needed to give me a 404 page because it doesn't exist but now it just takes the latest word and gets the data from strapi. My API URL is still this of course: www.myStrapiInstalation/api/pages/parttime-bijbelschool
So what do I need to do?
Is it just not possible to make everything hardcoded and do I need to make nested folders with real names like: 'onderwijs', 'activiteiten' etc.
Or can I make everything dynamic so that people can make nested routes in nested routes in strapi?
I feel like this is a very stupid question, but I'm really stuck here.
Next JS allows catch-all routes, which is useful for nesting pages and have this format:
pages/post/[...slug].js
In your example, the pages folder structure would be:
pages/secondNest/[...page].js
However, since you're using Strapi to fetch the content, the routes of these pages should be known in advance so that if the user navigates to an invalid page, the result should be 404.
You can set the valid routes in Next with getStaticPaths. But notice that you will also need to set up a custom controller in your Strapi application to return the content tree of your website the way that getStaticPaths expects.
That way, it's ok to use the last part of the URL to get the content.
One disavantage of using catch-all routes, though, is that you must know the base of each URL. For example, if you have the following URLs
www.example.com/onderwijs/bijbelscholen/parttime-bijbelscholen
www.example.com/activiteiten/bijbelscholen/parttime-bijbelscholen
the folder structure in pages would be:
pages/onderwijs/[...page].js
pages/activiteiten/[...page].js
The key factor here is that the paths following the base of the URL should be set statically with the help of a custom controller that returns the tree of the content.

GitHub Page Custom URL Styling and Pics don't render

My site, Jekyll static pages and a blog, https://omnebonum.github.io/dsu/ on GitHub pages looks like it is supposed to (such as it is). I have a custom URL set up that points the repo to democracystraightup.org. That works but when I go that URL the pages show up without any CSS or pics.
I know this isn't super specific information, but you can check them both out if you like, and any general insights would be appreciated.
All your css, javascript and other assets are returning 404 errors:
The paths are all pointing to subdirectories of http://democracystraightup.org/dsu/ (e.g. http://democracystraightup.org/dsu/js/gallery.js).
Thats wrong.
You need to drop the /dsu to make it work.
For example http://democracystraightup.org/js/gallery.js works totally fine.

How to link images and pages in wordpress pages?

So, in the WordPress page, I need to link the pdf in wp-contents so I linked it with the relative URL as href="/wp-content/uploads/2017/03/test.pdf"
when I click it since my root in localhost is localhost/test it takes me to localhost/wp-content/uploads/2017/03/test.pdf (which doesn't serve the file). However, I don't think it'll be an issue in the server. Still, I want to know if this is the correct way?
Also, so I'm in page localhost/test/page22 Now on the page, I have an anchor tag as href="/page23" it takes me to page23 correctly, but when I'm in a different sub page say localhost/test/page/page2 now, the link takes me to localhost/test/page/page23 which is not correct as it should be localhost/test/page23. How can I solve these issues
WordPress provides functions for getting the URL of resources you should use these instead of having your code generate the URL. In this case you should call wp_get_attachment_url().

drupal 6 /user/permissions checkbox page core module

Does anyone know where i can find the code that makes the user/permissions checkbox page in drupal? I'd like to see how it's done to make something similar for a custom module i'm building.
The function you're looking for is theme_checkbox($element) and can be found in root/includes/form.inc. If you ever want to know what function/template is responsible for a certain HTML element then Theme developer is your friend.
Enable the module, set the permissions and you'll see a small checkbox Themer info. Then just point to the HTML part you're interested and see what theme function/template is doing the rendering.
i think on default module folder there is user folder on user.admin.inc file contain code for permission function is user_admin_perm(); see this code

How to make sure changes to a Wordpress plugin won't be lost on plugin update?

I'm pretty sure I've read somewhere that you can actually move the main plugin *.php file to somewhere else (I assume under your theme directory) to have it safe in case you made changes to it and your plugin updates. I tried Google but I can't find anything. Google page with good results will suffice.
I've just experienced a situation where my 2 plugins which had its layout changed and accommodated my needs and I want to make sure it doesn't happen again. Apart from having the main file in another location, is there a way to move along any CSS and JS files as well?
In Concrete5 CMS there is a nice way of doing this, by creating a new folder inside a block of an addon (may be regarded as a WP plugin), inside of which you can create copies of main file, any CSS and JS files and then you can simply edit them and choose that template for a page location you are using that block in.
I assume there is no such thing in Wordpress but how close can I get?
UPDATE: I found where I applied that advice on creating a new instance of the file then moving it to the theme directory.
The plugin in question was HL-Twitter. These are the plugin files:
admin.php
archive.php
functions.php
hl_twitter.php
hl_twitter_archive.php
hl_twitter_widget.php
import.php
widget.php
Now, this is the top contents (commented out) of the hl_twitter_widget.php:
Widget Theme for HL Twitter
To change this theme, copy hl_twitter_widget.php
to your current theme folder, do not edit this
file directly.
Available Properties:
$before_widget
$after_widget
$before_title
$after_title
$widget_title
$show_avatars
$show_powered_by
$num_tweets: how many tweets to show
$tweets: array of $tweet
$tweet: object representing a tweet
$tweet->twitter_tweet_id
$tweet->tweet
$tweet->lat
$tweet->lon
$tweet->created
$tweet->reply_tweet_id
$tweet->reply_screen_name
$tweet->source
$tweet->screen_name
$tweet->name
$tweet->avatar
$user: represents the Twitter user (ONLY SET IF SHOWING A SINGLE USERS TWEETS!)
$user->twitter_user_id
$user->screen_name
$user->name
$user->num_friends
$user->num_followers
$user->num_tweets
$user->registered
$user->url
$user->description
$user->location
$user->avatar
So I was wrong about copying the main file (in this case hl_twitter.php), but still - this enabled me to edit the file outside the plugin directory and the system somehow checks for its existence and picks it up if exists.
If this behavior something that is natively supported by Wordpress or it has been integrated in the plugin itself?
With themes, Wordpress has a concept of "child themes" which allows exactly that: to keep changes separate from main theme, in case it changes.
I haven't yet found a way to do this with plugins.
I'm using a few tactics myself:
I bump plugin version to a very high number like 99.9. This way Wordpress won't ever update the plugin.
Store my plugins in version control (i use git, but it doesnt matter), this allows you to update the plugin, run the 'diff' tool and see what changes happend. If you don't like you just revert like it would be a bad code you've written. But this approach requires a bit of skill.
Are you talking about running parts of a modified 3rd party plugin, and an updated version, at the same time?
That's not going to be possible. There is no magical method of "preserve my changes and transfer them into the new version automatically". The way to go here is doing a diff between the edited version and the update, and integrating the changes in the actual source files.
The bottom line is, if you manually edit a third party plugin, you're in for manual review (and possibly rework) once an update takes place. That's why it's usually not a good idea to extensively modify third party plugins.
Well in fact, yes! There is some kind of way.
You have to remove the to be modificated plugin's original actions/filters and then add your altereted actions/filters.
If the desired plugin is even coded in OOP you can just inherit the whole class and rewrite the wanted functions (oh sorry: "methods". we're talking about OOP ;) ). Instantiate your inherited class and rest as above.
Maybe there are better ways! I already search for a method so that the original class won't even get loaded but our altered one instead but I'm no John Carmack.

Resources