Is it possible to get a different header.php on language switch with qtranslate (Wordpress)? - qtranslate

the problem is that on home page I have a lot of code which is added through header.php and it is not amendable through admin panel. What I want to do is to switch header files on language switch. Whenever a user press on the language icon, lets say on the English language icon the header should also switch from <?php get_header('mylanguage') ?> to <?php get_header('english') ?> or etc. Is it possible to do like this?
Regards,

In your page template instead of calling header through:
get_header();
use this to enable header switching when changing languages;
<?php if (qtrans_getLanguage() == 'de'): ?>
<?php include(TEMPLATEPATH.'/header-home-de.php' ); ?>
<?php else : ?>
<?php include(TEMPLATEPATH.'/header-home-en.php' ); ?>
<?php endif; ?>
In this example there are 2 headers depending on selected language.

Surely, it is possible in qTranslate. Even I've done qTranslate Swicher in bootstrap navigation.
<?php } if (qtranxf_getLanguage() == 'en') { ?>
English
<ul class="dropdown-menu">
<?php echo qtranxf_generateLanguageSelectCode('code'); ?>
</ul>
<?php } elseif (qtranxf_getLanguage() == 'fr') { ?>
Français
<ul class="dropdown-menu">
<?php echo qtranxf_generateLanguageSelectCode('code'); ?>
</ul>
<?php } ?>

Related

How to show only 2 post from post in ACF relationship

After creating customfield from ACF. I select multiple articles. How can I show only the last 2 posts? Thank!
Show only 2 post from relationship ACF
I would use the post_object field. With this field, you can select which objects you would like to display, when you configure it to "multiple values".
<?php
$featured_posts = get_field('featured_posts');
if( $featured_posts ) { ?>
<ul>
<?php foreach( $featured_posts as $post ) {
setup_postdata($post); ?>
<li>
<?php the_title(); ?>
</li>
<?php } ?>
</ul>
<?php
wp_reset_postdata(); ?>
<?php } ?>

View inside a view using CakePHP 3

Is it possible to display a view inside another view?
I have the following code:
<?php if ($result->type === 'brochure') : ?>
<div>
// massive template block
</div>
<?php elseif ($result->type === 'library') : ?>
<div>
// massive template block different from above
</div>
<?php else : ?>
<div>
// massive template block different from both above
</div>
<?php endif; ?>
I want to replace those with a content block so to speak. I had a look at view blocks but I'm either using it wrong or it doesn't do what I want it to do.
Is this possible in CakePHP 3?
you can use elements for that.
first you should create elements in src/Template/Element directory with .ctp format like this
// in brochure.ctp file in src/Template/Element
<div>
// your massive template block
</div>
then you can call elements like this :
<?php if ($result->type === 'brochure') : ?>
<?= $this->element("brochure") ?>
<?php elseif ($result->type === 'library') : ?>
<?= $this->element("library") ?>
<?php else : ?>
<?= $this->element("default") ?>
<?php endif; ?>

Cakephp working whit Cell

Hi I have a trouble whit Cell in my application I follow the tutorial but did not work for me
here is my code https://github.com/boguda/okpionir.git
I bake cell for News and add display function
I want to use this cell on my static page src/Template/Pages/pocetna.ctp
but it doesn't work
just change
<?php $cell = $this->cell('News'); ?>
<?= $cell ?>
to
<?= $this->cell('News::display'); ?>
Call Cell has to refer to specific method name
EDIT:
Also you have an error in your src/View/Cell/NewsCell
public function display()
{
$this->loadModel('News');
----> $top_news= $this->News->find()
->select('title')
->order(['created'=>'DESC'])
->limit(3)
->toArray();
$this->set('top_news' => $news); <-----
}
should be:
$this->set('top_news', $top_news);
or
$this->set(compact('top_news'));
And your view Template/Cell/News/display.ctp might look like this
<ul class="list-group">
<?php foreach ($top_news as $news): ?>
<li><?= h($news['title']); ?></li>
<?php endforeach; ?>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>

I can't load blocks in my default.ctp

I want to use the blocks statements in my application. I have a theme called: Boostrap. If I use only the statement $this->element() my elements load without problems, but if I use $this->start() and $this->end() I can't load my elements.
I try create a new file called index.ctp for a TestsController but the result is the same. I put $this->fetch('header') and $this->fetch('footer') in this file and nothing.
That's only an example of my real structure:
Themed\Boostrap\Layouts\default.ctp:
<html>
<head>
<title></title>
</head>
<body>
<?php $this->start('header'); ?>
<?php echo $this->element('header'); ?>
<?php $this->end(); ?>
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
<?php $this->start('footer'); ?>
<?php echo $this->element('footer'); ?>
<?php $this->end(); ?>
</body>
</html>
Themed\Boostrap\Elements\header.ctp:
<header>
<h1>Hello World!!</h1>
</header>
Themed\Boostrap\Elements\footer.ctp:
<!-- app/views/themed/boostrap/elements/footer.ctp -->
<footer>
Copyright (c) Bla bla bla 2014.
</footer>
Details of my environment:
S.O: Windows 7
CakePHP Versión: 2.4.4
PHP Versión: 5.3.28
You're layout should define the block output, not the start and end methods:
<?php echo $this->fetch('header'); ?>
Then, in your view, you outline the block that will be outputted:
<?php $this->start('header'); ?>
<?php echo $this->element('header'); ?>
<?php $this->end(); ?>
Given this use case, blocks don't seem like the right solution. Your element seems like it would be the only thing to display, in which you would output the element on the layout. However, a more appropriate use case would be different output at a per-page level.
In your layout:
<?php echo $this->element('header'); ?>
<?php echo $this->fetch('header_block'); ?>
Page one:
<?php $this->start('header_block'); ?>
//Something unique to page 1
<?php $this->end(); ?>
Page two:
<?php $this->start('header_block'); ?>
//Something unique to page 2
<?php $this->end(); ?>

how to use cakePHP params to set unordered list items as active

I want to be able to set a navigational list item as active by using cakePHP params. This would visually tell the visitor which page they're currently on. I've figured out how to do it for the current controller but, I'm routing specific rows in the post controller for pages such as 'about us' and it's not working even though I'm trying to check for the 'pass' param. Here's the code:
In an element called "leftNavBar.ctp' I've got the following:
<?php
$current_pass = $this->params['pass'];
$current_controller = $this->params['controller'];
?>
<ul class="nav">
<li class="<?php if(in_array($current_pass, array(2))){echo 'active';} ?>">
<?php echo $this->Html->link(__("About Us",true),"/about-us") ?>
</li>
<li class="<?php if(in_array($current_controller, array('galleries'))){echo 'active';} ?>">
<?php echo $this->Html->link(__("Galleries",true),"/galleries") ?>
</li>
</ul>
This is the router instructions for the 'about us' page:
Router::connect('/about-us',array
('controller' => 'posts', 'action' => 'view', 2));
Because the Posts controller has other rows/list items that I also want to set as active in the left nav bar, what I want to figure out is how to be able to do that?
thanks
You can try setting variable inside the controller and access in view like
In Controller
function view($id) {
..........
..........
$this->set('current_pass',$id);
}
In View
<?php
$current_controller = $this->params['controller'];
?>
<ul class="nav">
<li class="<?php if(in_array($current_pass, array(2))){echo 'active';} ?>">
<?php echo $this->Html->link(__("About Us",true),"/about-us") ?>
</li>
<li class="<?php if(in_array($current_controller, array('galleries'))){echo 'active';} ?>">
<?php echo $this->Html->link(__("Galleries",true),"/galleries") ?>
</li>
</ul>
What I ended up doing with luck was the following:
<?php
$url = $this->Html->url() ;
$current_controller = $this->params['controller'];
?>
<ul class="nav">
<li <?php if($url == '/NAME-OF-URL-HERE/about-us') echo 'class="active"';?>>
<?php echo $this->Html->link(__("About Us",true),"/about-us") ?>
</li>
<li class="<?php if(in_array($current_controller, array('galleries'))){echo 'active';} ?>">
<?php echo $this->Html->link(__("Galleries",true),"/galleries") ?>
</li>
</ul>
This works well since not all URLS are handled the same way. Some URLs are controllers, others are specific IDs within controllers.
Hope this helps others.
Paul

Resources