Wordpress personalized permalink - php

Bonjour!
I'm using a translation plugin on my web site that doesn't display on mobile display (column where the plugin is displayed is not visible on mobile).
When I put my article in english, the url becomes:
frenchyincali.com/my-article/**?lang=en**
Thus, I'd like to include a link in my code that is very basic: Getting the permalink and add the suffix "?lang=en" for the english link and just the default permalink for the default language (French).
I guess it'd be something like <?php the_permalink();>... But then I don't know what to put to add the suffix. Can you help me please?
I tried to find something elsewhere but I can't find the answer; Thanks.

Displays the URL for the permalink to the post currently being processed in The Loop.
English Article

Add functions.php
function lang() {
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if($lang == "en") {
$suffix = "?lang=en";
} elseif($lang == "tr") {
$suffix = "?lang=tr";
} else {
$suffix = "";
}
return $suffix;
}
Use like this:
Article
I think this way is simple.

Related

Change default user profile URL - BBpress Plugin

Bbpress Wordpress Plugin have default link user profile url. The link like this: www.example.com/forum/users/(username)
The main purpose in nutshell is: I want to change the url.
Actually, I found the solution but its not perfect. The code like this:
function user_profile_link(){
$url = 'http://localhost/example.com/profile/';
$author_id = bbp_get_reply_author_id();
$user_info = get_userdata($author_id);
echo ' '. $user_info->display_name.' ';
}
add_filter('bbp_get_user_profile_url', 'user_profile_link');
Yes, the code working well. But the outcome is, the user profile URL not replaced and there is double URL like this image below:
image1
I think the problem solved if I display: none it. The code like this:
<style>
.bbp-author-link{
display: none;
}
</style>
But there is one problem. The new URL that I make appeared beside the breadcrumbs like this image:
image2
I want to remove the link that appeared beside the breadcrumbs. Is there any solution? Any help is appreciated. Thank You
In a filter hook, you normally have to override the current value by returning it. Therefore try returning the new value by using the function you already created. It may remove the duplicate.
Also, use site_url() instead of $url variable because there will be issues when you use a hardcoded URL.
function user_profile_link(){
$author_id = bbp_get_reply_author_id();
$user_info = get_userdata($author_id);
return site_url()."/profile/".$user_info->user_login;
}
add_filter('bbp_get_user_profile_url', 'user_profile_link');
For this problem, I found the solution.
The code is like this:
function user_profile_link(){
$author_id = bbp_get_reply_author_id();
$user_info = get_userdata($author_id);
$url = site_url()."/profile/".$user_info->user_login;
return $url;
}
add_filter('bbp_get_user_profile_url', 'user_profile_link');

if title contains string 'aaa','bbb' or ,'ccc' replace field {category[1}

Hello gods of Stackoverflow,
Now i hate to be "that guy" who didnt search properly but i am running into a problem that i need a fix for and can't find a solution i can work with because of my lack in coding skills, my knowledge barely tickles the surface.
Here's the thing.
I am using a tool to import feeds into my website (WP all Import) as woocommerceproducts. But in the categorization the feed suppliers made errors which i want to tackle without emailing them everytime i stumble upon one.
i.e: the title contains words like satchel, bag, clutch etc but the product is categorized as 'jewellery > earrings' in the CSV or XML.
The import tool will ask me where to find the product category, i point it to the node {category[1]}
But when the category is missing or faulty i want it to check the title for certain words, and if present change the value of it to that found word.
something like:
[if ({title[1]}contains "satchel") {
category = "bags > satchel",
} else if ({title[1]} contains clutch) {
category = "bags > clutch",
} else {
category = {sub_category[1]} #the normal value if nothing was found
}]
I just can't find the pieces to put the formatting together. I might need to work towards a function that i could expand to generate categories based solely out of presence of certain words in the title but maybe when i get better that would be an option.
I hope i was able to provide a clear view on the problem. The "[ ]" is there because thats how the plugin wants code to be entered instead of a {fieldname[1]}, another example below:
The following was an example of a problem i was able to fix:
i needed to replace values like "0/3months/1/2months" to "0-3 months/1-2months" before i replaced the slash"/" with a pipe"|" for wordpress to recognize it as a seperate value.
[str_replace("/","|",
str_replace("0/3","0-3",
str_replace("1/2","1-2",
str_replace("3/6","3-6",{size[1]}))))]
The fields can also be used to call functions but only in the 'pro' version of the plugin.
Any help is very much appreciated, thanks in advance.
You could use strpos.
Example:
if (strpos($title, "satchel") !== false) {
$category = "bags > satchel";
}
So after an afternoon of poking around, testing stuff, and not knowing alot about php i came up with a solution with help from a friend.
Wp All Import does not allow custom php directly from the field itself, it does however support custom php functions and provides an editor for these on the bottom of the import configuration page. I did the following:
<?php
//Checks Title for keywords and
//uses those to create categories
//We are using our own Main categories so only
//sub and subsub categroies need to be created.
//Call function
[get_subcat_from_title({title[1]},{category[1]})]
//Function
function get_subcat_from_title($title,$defaultcat)
{
if (strpos($title,"Satchel") !== false) {
$cat = "Tassen";
} elseif (strpos($title,"Travel") !== false) {
$cat = "Tassen";
} elseif (strpos($title,"Gusset") !== false) {
$cat = "Tassen";
} else {
$cat = $defaultcat;
}
return $cat;
}
//Checks Title for keywords and uses those to create subcategories
//Call Function
[get_subsubcat_from_title({title[1]},{sub_category[1]})]
//Function
function get_subsubcat_from_title($title,$defaultcat)
{
if (strpos($title,"Satchel") !== false) {
$cat = "Satchel";
} elseif (strpos($title,"Travel") !== false) {
$cat = "Travel";
} elseif (strpos($title,"Gusset") !== false) {
$cat = "Gusset";
} else {
$cat = $defaultcat;
}
return $cat;
}
?>
On the Taxonomies, Tags, Categories option we can create our own hierarchical order like this:
[main category]
+[sub category]
++[sub sub category]
The main category field is given a name we use as our main category.
The sub category is filled with function SUBCAT
The subsub category is filled with function SUBSUBCAT
this way it will create a parent by our own name, a child that has the named 'Tassen' if any keyword is present, and a grandchild with the specific keyword as it's name.
This way i can expand the function using all kinds of statements when the right category isn't present in de provided feed.
thanks #sebastianForsberg for responding.
I hope this helps anyone who comes across a similar problem in the future..

cannot get drupal 7 to recognize a page template for a content type

I have a drupal 7 site that I want to make secondary front pages on. the problem with this is the "page--front.tpl.php" is a two column layout and the "page.tpl.php" is a one column layout. if i use a node template it shoves it in the body of the one column.
the theme name is "egress" the machine name for the content type is "landing" but when i try to hook the page--landing the same way i do the node--landing nothing happens. nothing.
i am clearing the cache and hard refreshing the page with every change of the template files.
one code i have tried in the of the "page.tpl.php"
function egress_preprocess_page(&$vars) {
global $node;
if ($node->type == 'landing') {
$vars['theme_hook_suggestions'] = array('page__landing');
}
}
another
function egress_preprocess_page(&$vars) {
if ($vars['node']->type == "landing_page") {
$vars['template_files'][] = 'page--landing';
}
}
anyone ideas?
The following should go to your theme's template.php rather than page.tpl.php
function egress_preprocess_page(&$vars) {
// For page--(node-type).tpl.php
if (isset($vars['node'])) {
$vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
}

Wordpress Plugin Using Permalinks

So i created a plugin that is basically a gallery that you choose options as you go.
First choose Brand
Then Color
Then Style
At each step i am passing the variables via $_GET
So once you have chosen your brand and continue the next page URL is cabinets/?brand=1
Then after you choose your color it is cabinets/?brand=1&color=2
i have written a rewrite for this that is supposed to make pretty urls but all it is doing is showing the home page.
add_filter('rewrite_rules_array','cabinets_rewrite_rules_array');
function cabinets_rewrite_rules_array($rules){
$cabinets_slug = 'cabinets';
$my_cab_rules[$cabinets_slug.'/?$'] = $cabinets_slug."/?brand=$matches[1]";
$my_cab_rules[$cabinets_slug.'/(.+?)/?$'] = $cabinets_slug."/?brand=$matches[1]&color=$matches[2]";
$my_cab_rules[$cabinets_slug.'/(.+?)/(.+?)/?$'] = $cabinets_slug."/?brand=$matches[1]&color=$matches[2]&style=$matches[3]";
return $my_cab_rules + $rules;
}
i have tried many things even as much as updating the htaccess file but i dont want to have to do that since this is a plugin.
Any Idea?
You could try adding your new variables to the list of query vars.
function prfx_add_query_vars($aVars) {
global $wp_query;
$aVars[] = "brand";
$aVars[] = "color";
$aVars[] = "style";
return $aVars;
}
add_filter('query_vars', 'prfx_add_query_vars');

Codeigniter if controller

First of all sorry if its a noob question.
But is it posibble to do this in codeingiter, like if i have a sidebar but i only want to load it in 2 pages
if(controller == 'blog') {
//load sidebar
}
just like in wordpress if is_page
Use $this->router->fetch_class()
if($this->router->fetch_class() == 'blog') {
//load sidebar
}
Also $this->uri->segment(2) will work in most cases, but in some cases like mod_rewrite or when using subfolder or route it may fail.
More simply you can do like this.
$controller_name = $this->CI->router->fetch_class();
if($controller_name === "your_controller_name")
{
//your logic
}

Categories