I am trying to create a Yii2 theme, & would like to set a variable that with scope of the entire views folder. For a single page theme I used...
$assetDir = Yii::$app->assetManager->getPublishedUrl(
'#vendor/path/to/assets/folder'
);
in index.php & I then I accessed it using...
<img src="<?= $assetDir ?>/img/image.jpg" alt="">
For partials I am able to pass that using...
<?= $this->render('_partial.php', ['assetDir' => $assetDir]) ?>
I am now wanting to do similar in a theme with multiple pages & cannot find how to do that without setting $assetDir in each page. I imagine it would be set in the main.php layout.
Use params array for this as stated in Sharing Data among Views.
The view component provides the params property that you can use to share data among views.
For example, in an about view, you can have the following code which specifies the current segment of the breadcrumbs.
$this->params['breadcrumbs'][] = 'About Us';
Then, in the layout file, which is also a view, you can display the breadcrumbs using the data passed along params:
<?= yii\widgets\Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
Related
I need to add additional images next to post title, in this case decided to use ACF and add fields (image) into another plugin (Event Schedule). After I added fields in ACF I was trying to add some code from ACF documention however it doesnt work..
P.S. Every post will have different images based on their type. You can choose it while you are editing specific post.
In ACF field menu I chose to return format Image Array.
Tried with all return formats: Image Array, Image URL and Image ID. As I understand plugin cant find the variable acf_name and the image source is left blank.
<div class="wcs-class__meta">
<div class="wcs-class__inner-flex">
<h3 class="wcs-class__title" :title="event.title" v-html="event.title"></h3>
// Using this code from official ACF documentation
<?php
$acf_name= get_field('acf_name');
if( !empty($acf_name) ): ?>
<img src="<?php echo $acf_name['url']; ?>" alt="<?php echo $acf_name['alt']; ?>" />
<?php endif; ?>
</div>
</div>
Now nothing happens, no errors, nothing. However, also it doesnt show those images I want.
Files in the plugins folder do not have access to global functions like get_field();. You can overwrite most plugin files in your theme, in which you should have access to global functions. Keep in mind that when the plugin you override gets updated, the file your are overriding will not. This could cause security issues.
The following article talks about the right ways of custmizing plugins: https://iandunn.name/2014/01/10/the-right-way-to-customize-a-wordpress-plugin/
My client has a custom made theme that uses custom fields instead of featured images.
I added some new plugins and I need to start using featured image instead.
So instead of updating every single post, I thought there's a way to do it using MySQL.
I want to create a MySQL query that transfers all the custom fields values to the featured image.
The theme uses 2 custom fields:
For single image posts:
$post->news_image
For Gallery: // it takes the first image of the gallery
<?php if( has_shortcode($pin->post_content, 'gallery' ) ): ?>
<?php $gallery = get_post_gallery_images( $pin ); ?>
<?php $mythumbs = $gallery[0]; ?>
<?php endif ?>
Should I create a new php file with MySQL in it? and what should it contain?
I have a template that i was using for my project.
Look at the picture below:
This is when i am not using the kartikGrid. the dropdown menu running as well as the template want.
look at the image below:
this is when i use kartik, the dropdown menu not running anymore.
can some body tell me why it happen.
The template using different bootsrap version with kartik.
thaks.
Hope some body help me.
Imaginaroom, that did the trick for me thank you.
My top menu wasn't responding (direct link, or drop down menu) after kartik was used. I added an id to my menu widget and it did the trick.
echo Nav::widget([
'id' => 'topMenuID',
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
Manually assign different ids to all widgets, so there won't be any conflicts.
If you don't assign ids to widgets, yii gives them one automatically, but the problem occures when loading data with ajax or pjax, then Yii cannot know which ids are already used in the page.
Every widget in Yii2 has a property 'id' that you can assign in configuration array when calling a widget.
Add this code in layout or page that has problem:
$this->registerJs( "$(document).ready(function() { $('.dropdown-toggle').dropdown(); });", View::POS_END, 'ecommerceProductJs' );
I try to display an image with the following code.
<?php echo $this->Html->image('/img/adverts/001/ad.jpg', array('alt' => 'ad')); ?>
this creates me this:
<img class="zdrwtxgldzisqmpzuclb" src="/img/adverts/001/ad.jpg" alt="werbung">
I don't know where this strange class atribute is comming from but it seams to ruin my code as the picture is not displayed.
Now if I use another sub folder in webroot/img, the sub folder uploads like this:
<?php echo $this->Html->image('/img/uploads/001/ad.jpg', array('alt' => 'ad')); ?>
it works and gives back an <img> tag without that class.
<img src="/img/uploads/001/ad.jpg" alt="werbung">
So the question is, where does this class attribute come from, and is this the reason why no image is displayed? I can't find anything about that effect and where it is coming from.
If I add a class attribute to my CakePHP code then it just appends this strange string after my class attribute.
<?php echo $this->Html->image('adverts/01/ad.jpg', array('alt' => 'werbung', 'class' => 'img' )); ?>
<img src="/img/adverts/01/ad.jpg" alt="werbung" class="img zdrwtxgldzisqmpzuclb">
Of course the both folders uploads and adverts have the same rights.
Edit: ndm was right, it is an ad-blocker. Shocking, I didn't know they are that clever.
ndm was right. It was the ad blocker "Adblocker Plus" that caused that effect.
The problem is solved.
I am trying to create a Wordpress template from static HTML that I made a while back. In the HTML there is a <span> tag within each link in the main navigation menu. It looks like this:
https://www.dropbox.com/s/52zgm8kpj8cfb51/Screenshot%202014-08-25%2018.35.47.png?dl=0
The span accounts for the small tab-like extension to the left of the links. This is to give the page a three-dimensional effect. Unfortunately, when I converted the HTML to a Wordpress theme, I was not able to find how to do this whilst making use of Wordpress' dynamic menu function. This creates the links automatically and generates the HTML. I was wondering if anyone knew a way in which I could edit the generated hyperlinks to include the <span> tag.
Assuming you're using the wp_nav_menu() function to generate the menu links, I believe the code you're looking for is:
<?php
$defaults = array(
'link_before' => '<span>',
'link_after' => '</span>'
);
wp_nav_menu( $defaults );
?>
http://codex.wordpress.org/Function_Reference/wp_nav_menu