Wordpress, Redirects and WPML - php

I have a fresh installation of wordpress, and I wrote some quick rewrite rule in my functions.php that looks like this -
// "rewrite" /assets/xyz to /assets/?asset=xyz
function assets_rewrite_rule($rules) {
global $wp_rewrite;
$asset_rule = array( // (not tested)
'assets/(.+)/?' => 'index.php?pagename=Assets&asset=$matches[1]'
);
return array_merge($asset_rule, $rules);
}
add_filter('page_rewrite_rules', 'assets_rewrite_rules');
And I have my sidebar translated with WPML and String Translation in the most primitve way.
Here's the english part (not translated) of my sidebar -
<div class="sideall">
<div class="sidebar-mai1">
<div class="sidebar-name">
<img style="width: 25px; margin-right: 10px; margin-bottom: -7px;" title="first asset" src="/wp-content/images/sidbar-assets/firstasset.png" alt="first asset" />First Asset</div>
<div class="sidebar-btn">
<a class="btn-sidebar" href="/assets/first-asset/">Review</a>
<a class="btn-sidebar1" href="/buy/first-asset">Trade Now!</a></div>
<div style="clear: both;"></div>
</div>
And while trying to make a translation to other language (let's say italian), the wpml refuses to save my changes to the review links..like my redirection rule is affecting it somehow.
Here's the translation I added to the sidebar -
<div class="sideall">
<div class="sidebar-mai1">
<div class="sidebar-name">
<img style="width: 25px; margin-right: 10px; margin-bottom: -7px;" title="first asset" src="/wp-content/images/sidbar-assets/firstasset.png" alt="first asset" />First Asset</div>
<div class="sidebar-btn">
<a class="btn-sidebar" href="/it/assets/first-asset/">Revisione</a>
<a class="btn-sidebar1" href="/buy-it/first-asset">Scambia ora!</a></div>
<div style="clear: both;"></div>
</div>
As you can see both the review and the buy links were changed.. but after I hit save, it only saves the change i made in the buy href, but it reverts my change to the review link, and it looks like this after I save -
<div class="sideall">
<div class="sidebar-mai1">
<div class="sidebar-name">
<img style="width: 25px; margin-right: 10px; margin-bottom: -7px;" title="first asset" src="/wp-content/images/sidbar-assets/firstasset.png" alt="first asset" />First Asset</div>
<div class="sidebar-btn">
<a class="btn-sidebar" href="/it/assets">Revisione</a>
<a class="btn-sidebar1" href="/buy-it/first-asset">Scambia ora!</a></div>
<div style="clear: both;"></div>
</div>
As you can see, after I hit save, it removes the /first-asset part from my translation and now it leads to an empty page (/it/assets) .. I am wondering if it may be cause as a result of the rewrite..

An alternate way to approach this:
Listen to your customer's browser setting.
locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
https://secure.php.net/manual/en/locale.acceptfromhttp.php
You can then rewrite it to a function like this:
function my_get_langauge() {
static $lang;
if(is_null($lang)) {
$lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
/**
* Check list of allowed/accepted languages or revert to default
*/
if(!in_array($lang, ['nl','en','de','it']) )
{
$lang = 'en';
}
}
return $lang;
}
This way you don't have to worry about redirects for languages, and you can accept languages as your website user wants to see it.

If you test your expression online you'll see that your regex is removing the first-asset part of the URL.
Regular Expression: assets\/(.+)\/?
Test String: /it/assets/first-asset/
This will return /it/assets/.

Related

Hide menu-text (div) on website (php, html)

I have a simple website, using php, html, css,
and would like to hide two menu buttons:
menu box & text
<div class="filter margin"></div>
<div class="filter_options">
<div class="filter_op filter_op_selected" data-type="type" data-id="bla 1">
<div class="filter_check"></div>
<div class="filter_value">bla</div>
</div>
<div class="filter_op " data-type="type" data-id="bla 2">
<div class="filter_check"></div>
<div class="filter_value">bla</div>
</div>
Still it is necessary, that the upper box is ticked & as such recognized by the code;
for the correct work-logic of the menu.
Thanks for any tip or suggestion.
[I know that in the code language mql4/5, which is based on php, you can simply hide a line of code when typing # in front of it.
It won't be shown, but it will be used (if such a box is hidden but ticked, it will behave like that).
I was asking myself how to do that in php]
After researching a lot, I've come to the following answer:
<div class="filter margin"></div>
<div class="filter_options">
<div
class="filter_op filter_op_selected"
data-type="type"
data-id="bla 1"
style="height: 0; visibility: hidden; font-size: 0; padding: 0; margin: 0"
>
<div class="ranking_filter_check"></div>
<div class="ranking_filter_value">bla</div>
</div>
</div>

Move elements one below other in block

I have this little problem with my site. I want to move block title and second line to center, and button to keep in at center too, something like this:
image how wanted to look
Currently it looks like this:
current look on block
Where can be seen this form is here at bottom of page. This is what I do to customize it myself, I updated this CSS class:
.heading {
font-family: GOTHAM-BOLD;
font-size: 28px;
color: #273a55;
margin-left:340px; // i added this line, but seems it mess entire look.
}
and this is PHP code from that form:
<div class="footer box">
<div class="bluebg box"></div>
<div class="container">
<div class="footermain box">
<div class="footertop box">
<div class="row">
<div class="col-md-6 nopd">
<div class="ftleft box">
<div class="ftlinner box">
<h1 class="heading"><?php echo (get_field('news_letter_title'))?get_field('news_letter_title'):get_field('news_letter_title', 'option') ?></h1>
<?php echo (get_field('news_letter_tag'))?get_field('news_letter_tag'):get_field('news_letter_tag','option') ?>
</div>
</div>
</div>
<?php
endwhile;
It seems that Heading title and line bellow that is contained into one class called heading. So question now is now to move to center to start looking like image provided.
Follow these steps :
Change your col-md-6 class to col-md-12 in both the text bloc and the button bloc.
Add class text-center to the text column like this
<div class="col-md-12 nopd text-center" >
Add style justify-content: center; to "footertop box" like this :
<div class="footertop box" style="justify-content: center;">
Remove class noleft from button column and add margin:0 to button
as far as I understand, you want to have the texts centered and the button below them
for quick solution, add this class to your css:
.footertop.box .row {
display: block;
width: 100%;
text-align: center;
}
delete div's col-md-6 classes which are in div.row

How to centre-align 'n' number of images, coming from database

I have links of images stored in database,I want to bring the set of images at the centre of the screen (which in my case is left-aligned). No matter how many pictures comes dynamically, the set of the images should be aligned centre.
Iam using bootstrap for designing and here is how my code look like:
<div class="row">
<div class="col-md-12 text-center">
<?php
foreach($n as $val)
{ // loop to iterate 'n' image links
?>
<div class="col-md-1">
<img src="<?php echo $val; ?>" // images showing up.
</div>
<?php
}
?>
</div>
</div>
I am adding an image below to demonstrate the situation.
I have tried the following:
bootstrap classes : center-block (which is based on margin)
bootstrap classes : text-center (which is based on text-align)
bootstrap classes : "img-responsive center-block"
Please Note:
I don't want to push the content toward centre forcefully (like using of bootstrap class "col-md-push-3" or something as such, because the number of images to be displayed is not fixed. They vary time to time)
The column classes you are using to wrap the images [col-md-1]are floated left by default....you'd have to override that behaviour.
.text-center .col-md-1 {
float: none;
display: inline-block;
}
.text-center .col-md-1 {
float: none;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-md-12 text-center">
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
</div>
</div>
You can still use some good old CSS using FlexBox, as shown on this Fiddle. Basically, it uses a structure like:
<div class="container">
<div class="picture">
<img src="http://lorempixel.com/image_output/food-q-c-200-200-1.jpg" />
</div>
</div>
And then, with some FlexBox properties, you can achieve what you want:
.container {
display: flex;
}
.picture {
flex: 1 1;
width: 100%;
}
img {
width: 100%;
}
To sum up, you put the container in flex mode, and then all its div would occupy same space. Some intermediary divs are required in order to keep the aspect ratio of each image.
If you want to center them in case of you have less pictures available, you can still use the justify-content: center; property, setting a maximum width on the divs, such as this other Fiddle.
Note however that this solution would not work on IE9-.
Make a div with text-align:center
Amand then make a div inside it with display:inline-block

How to generate dynamic external link?

I'm new in php and css.
My goal is to put two icons into main menĂ¹ of a wordpress site. these icons should point to dynamic external links to my domain.
My header.php code of my theme is:
<div id="flags" style="position:absolute;left:97%;top:10px; width:300px; height:30px; background-color:transparent">
<img src="wp-content/themes/minimable-premium/templates/it-icon-24.png" />
<img src="wp-content/themes/minimable-premium/templates/uk-icon-24.png" />
</div>
I need to take the current URL, replace only a part of that with a string of my choice. For example, into the first url, the string "aaa" with "ccc".
Thus, the icon link to the new address.
I tried to follow this way:
<div id="flags" style="position:absolute;left:97%;top:10px; width:300px; height:30px; background-color:transparent">
<?php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$strEng = "eng";
$strIta = "ita";
$new_link = str_replace($strEng,$strIta, $actual_link);
?>
<div id="banner" onclick="window.location.href='$new_link'" style="cursor: pointer">
<img src="wp-content/themes/minimable-premium/templates/it-icon-24.png" />
</div>
<img src="wp-content/themes/minimable-premium/templates/uk-icon-24.png" />
</div>
Can you give me advice on how to write the correct code and in which files?
You can't reference array elements directly inside a string the same way you can with normal variables. You'll have to combine the multiple strings with the . operator. See my changes on line 3:
<div id="flags" style="position:absolute;left:97%;top:10px; width:300px; height:30px; background-color:transparent">
<?php
$actual_link = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$strEng = "eng";
$strIta = "ita";
$new_link = str_replace($strEng,$strIta, $actual_link);
?>
<div id="banner" onclick="window.location.href='$new_link'" style="cursor: pointer">
<img src="wp-content/themes/minimable-premium/templates/it-icon-24.png" />
</div>
<img src="wp-content/themes/minimable-premium/templates/uk-icon-24.png" />
</div>
It looks like you are trying to make a translatable site.
What I think you should do is use the large plugin community from WordPress to make your site translatable. (WPML, WordPress MultiLingual is a great one)
If you do want to do it this way, or want to change the uri of the website try it like this:
<style>
#flags {
position:absolute;
left:97%;
top:10px;
width:300px;
height:30px;
background-color:transparent;
}
#flags a {
display: block; /* if you want the link to be a block */
}
</style>
<div id="flags">
<?php
$actual_link = "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
$strEng = "eng";
$strIta = "ita";
$new_link = str_replace($strEng,$strIta, $actual_link);
?>
<a id="banner" href="<?php echo $new_link; ?>">
<img src="wp-content/themes/minimable-premium/templates/it-icon-24.png" />
</a>
<a href="mydomain.com/bbb/">
<img src="wp-content/themes/minimable-premium/templates/uk-icon-24.png" />
</a>
</div>
Also with the above example, you both forget
Try avoiding inline styles. It works, but if you wanna make a job out of this clients and employers won't like it ;)

highlight current page menu li

Is there a way for me to highlight a menu li depending on the page id? I can't seem to figure out a way to do it.
http://www.dawaf.co.uk/cthm/work/
<div id="header">
<h1>
<a href="http://www.dawaf.co.uk/cthm/work">
<img src="http://www.dawaf.co.uk/cthm/wp-content/uploads/2013/01/logo2.png" alt="CTHM Logo" id="logo" width="140" height="44" />
</a>
<div id="contact-details">
26 Queen Anne Road, London, E9 7AH<br />
t + 44 7912325101<br />
hello#cthm.co.uk
</div>
</h1>
<div id="nav">
<span id="nav-li">
Work
Studio
CTHM+
<a href="https://twitter.com/hello_cthm" target="_blank">
<img src="http://www.dawaf.co.uk/cthm/wp-content/uploads/2013/01/twitter.png" alt="Twitter" width="13" height="13">
</a>
</span>
</div>
</div>
<div id="content">
I would recommend adding an active class to the navigation item. Something like this:
Work
And then the CSS:
#nav a.active {
/* your active style here */
}
You have two options. One is that mentioned by Zak, whereby you would need to use jQuery for your website to mark only one item at a time as "active". The other option is the CSS :active selector, which will auto apply CSS to the link which is in use (at the present time). For example:
#nav li a:active {
/* Insert styling here, such as, background-color: #01B */
}
Let me know if this helps!

Categories