I am trying to modify the module template code to add an anchor to the title of each module. I have extremely limited PHP knowledge, so any guidance would be very helpful.
I've found posts for doing this with articles, but the code appears to be very different for modules.
This is the code that is in my module template.
function modChrome_basic($module, &$params, &$attribs)
{
if (!empty ($module->content)) : ?>
<?php echo $module->content; ?>
<?php endif;
}
function modChrome_standard($module, &$params, &$attribs)
{
if (!empty ($module->content)) : ?>
<div class="rt-block <?php if ($params->get('moduleclass_sfx')!='') : ?><?php echo $params->get('moduleclass_sfx'); ?><?php endif; ?>">
<div class="module-surround">
<?php if ($module->showtitle != 0) : ?>
<div class="module-title">
<?php
echo '<h2 class="title">';
if (preg_match("/icon[-]{1,}/i", $params->get('moduleclass_sfx'))) :
echo '<span class="title-icon ' .getIconClass($params->get('moduleclass_sfx')). '"></span>';
endif;
echo $module->title;
echo '</h2>';
?>
</div>
<?php endif; ?>
<div class="module-content">
<?php echo $module->content; ?>
</div>
</div>
</div>
<?php endif;
}
This is the code I tried
if( strlen($this->item->params->get('title')) > 0 ) {
echo '<a name="'.$this->item->params->get('title').'"></a>';
}
I also tried
if( strlen($module->item->params->get('title')) > 0 ) {
echo '<a name="'.$module->item->params->get('title').'"></a>';
}
Joomla has an easy way to customize the module appearance.
You have to use a Custom module chrome.
You have to create a modules.php file under /templates/TEMPLATE_NAME/html/modules.php.
Inside this file you have to put:
<?php
function modChrome_custom( $module, &$params, &$attribs ) {
echo '<div id="' .$params->get( 'moduleclass_sfx' ) .'" >';
if ($module->showtitle)
{
echo '<h' .$headerLevel .'>' .$module->title .'</h' .$headerLevel .'>';
}
echo '<div class="module_content">';
echo $module->content;
echo '</div>';
echo '</div>';
}
?>
In the code above the module id getting moduleclass_sfx value. You could change it and set another module variable.
In order to use this appearence you have to set the appropriate style to the template module calls like: <jdoc:include type="modules" name="user1" style="custom" />
If you want to use another style name you have to change the function from modChrome_custom to modChrome_NEWSTYLE.
Good Luck!
Related
I didn't build this PHP file, but I am trying to figure out why it is giving me errors. If the "Block layout mode" ACF variable is set to "Modal" then the block works, but gives me this error. "Undefined variable $vids on line 176". If I select the "Embed & Thumbnail" mode, then none of the block is displayed and I get this error. "Call to undefined function vc_embed_layout() on line 252". I can't pin down why this is happening, and I haven't been able to find any unclosed tags or anything in my php file. This is the file in question, and I've marked the lines that trigger errors.
<?php
global $theme_text_domain;
$block_class_identifier = 'blk__vidcol';
// default variables
$block_id = $top_class = $top_style = $inner_class = $inner_style = '';
// check for custom id
$block_id .= BLOCK::set_id( get_sub_field('content_block_id') );
// set block class, $i comes from FLEX class loop and represents the block order on a page
$top_class .= BLOCK::set_standard_classes( $i );
$top_class .= BLOCK::set_custom_classes( get_sub_field('content_block_classes') );
// check for top padding adjustment
$top_class .= BLOCK::set_padding_class( get_sub_field('block_padding_adjustment') );
$top_style .= BLOCK::set_padding_style( get_sub_field('block_padding_adjustment'), get_sub_field('custom_top_padding'), get_sub_field('custom_bottom_padding'));
// check for custom color theme
$top_style .= BLOCK::set_colors( get_sub_field('color_theme'), get_sub_field('text_color'), get_sub_field('custom_background_color') );
// check for width settings
$inner_class .= BLOCK::set_width_class( get_sub_field('content_width') );
$inner_style .= BLOCK::set_width_style( get_sub_field('content_width'), get_sub_field('custom_maximum_content_width') );
$block_assets = get_stylesheet_directory_uri() . '/inc/blocks/' . basename(__FILE__, '.php') . '/assets/';
/*
CUSTOM BLOCK SPECIFIC SETUP
*/
$layout = get_sub_field('block_layout_mode');
$top_class .= ' layout-' . $layout;
// title color
$h2_style = (get_sub_field('color_theme') == 'custom') ? ' color: ' . get_sub_field('custom_title_color') . ';' : '';
/**
* outputs code for the modal version of the video collection block
* #return html output
*/
if (!function_exists('vc_modal_layout')) {
function vc_modal_layout() {
global $block_class_identifier;
$cta_label = get_sub_field('cta_label');
$counter = 0;
$cta = array(
'style' => get_sub_field('cta_style'),
'button_color' => get_sub_field('button_color'),
'button_text_color' => get_sub_field('button_color')
);
$cta_class = BLOCK::get_cta_style( $cta, '.' . $block_class_identifier . ' .button');
?>
<?php // list section ?>
<?php if( have_rows('videos') ): ?>
<div class="vid-container">
<?php while ( have_rows('videos') ) : the_row(); ?>
<?php if ($counter == 0): ?>
<div class="vid-featured">
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
<a class="vid_overlay" data-fancybox data-src="#<?php echo $block_class_identifier; ?>_vid_0" href="javascript:;"></a>
</div>
<!-- modal -->
<div id="<?php echo $block_class_identifier; ?>_vid_0" class="modal video-modal" style="display: none;">
<div class="modal-inner">
<h3><?php echo get_sub_field('video_title'); ?></h3>
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
<div class="vid-list">
<?php else: ?>
<div class="vid-item">
<div class="item-btn">
<a class="button <?php echo $cta_class; ?>" data-fancybox data-src="#<?php echo $block_class_identifier; ?>_vid_<?php echo $counter; ?>" href="javascript:;"><?php echo $cta_label; ?></a>
</div>
<div class="item-title"><?php echo get_sub_field('video_title'); ?></div>
</div>
<!-- modal -->
<div id="<?php echo $block_class_identifier; ?>_vid_<?php echo $counter; ?>" class="modal video-modal" style="display: none;">
<div class="modal-inner">
<h3><?php echo get_sub_field('video_title'); ?></h3>
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo get_sub_field('youtube_embed_code'); ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
<?php endif; ?>
<?php $counter++; ?>
<?php endwhile; ?>
</div>
</div>
<?php else: ?>
No videos defined.
<?php endif; ?>
<?
}
}
/**
* outputs code for the embed version of the video collection block
* #return html output
*/
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout($vids, $i) {
?>
<?php if ( $vids ): ?> **this is line 176**
<div class="vid-container2">
<h2 class="vid-title"><?php echo $vids[0]['video_title']; ?></h2>
<div class="vid-container2-inner">
<div class="vid-embed">
<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/<?php echo $vids[0]['youtube_embed_code']; ?>?rel=0&showinfo=0" frameborder="0" allowfullscreen onload="this.style.visibility = 'visible';"></iframe>
</div>
</div>
<div class="vid-thumbnails">
<?php foreach ($vids as $key => $vid): ?>
<?php $wrap_class = ($key == 0) ? ' tn-hide' : ''; ?>
<div class="tn-wrapper <?php echo $wrap_class; ?>" data-embed="<?php echo $vid['youtube_embed_code']; ?>" data-title="<?php echo $vid['video_title']; ?>">
<img src="https://img.youtube.com/vi/<?php echo $vid['youtube_embed_code']; ?>/mqdefault.jpg" alt="">
</div>
<?php endforeach; ?>
</div>
</div>
<script>
var vid_swap = function() {
$('.block_<?php echo $i; ?> .vid-embed').css({opacity: 1});
$('.block_<?php echo $i; ?> .tn-wrapper').on('click', function(e) {
var $this = $(this);
var embed_id = $this.attr('data-embed');
var title = $this.attr('data-title');
console.log('embed = ' + embed_id);
$('.block_<?php echo $i; ?> .vid-title').animate({opacity: 0}, 100);
$('.block_<?php echo $i; ?> .vid-embed').animate({opacity: 0}, 1000, function() {
$('.block_<?php echo $i; ?> .vid-embed, .block_<?php echo $i; ?> .vid-title').css('visiblity','hidden');
$('.block_<?php echo $i; ?> .vid-title').html( title );
$('.block_<?php echo $i; ?> .vid-embed iframe').attr('src', 'https://www.youtube.com/embed/' + embed_id);
$('.block_<?php echo $i; ?> .tn-wrapper.tn-hide').removeClass('tn-hide');
$this.addClass('tn-hide');
$('.block_<?php echo $i; ?> .vid-title').css('visiblity','visible').delay(500).animate({opacity: 1}, 500);
$('.block_<?php echo $i; ?> .vid-embed').delay(500).animate({opacity: 1}, 1000);
});
});
}
jQuery(document).on('block_init', vid_swap);
</script>
</div>
<?php else: ?>
No videos defined.
<?php endif; ?>
<?php
}
}
?>
<section id="<?php echo $block_id; ?>" class="<?php echo $block_class_identifier; ?> <?php echo $top_class; ?>" style="<?php echo $top_style; ?>">
<div class="inner <?php echo $inner_class; ?>" style="<?php echo $inner_style; ?>">
<?php // title section ?>
<?php if (get_sub_field('title')): ?>
<h2 style="<?php echo $h2_style; ?>"><?php echo get_sub_field('title'); ?></h2>
<?php endif; ?>
<?php $vids = get_sub_field('videos'); ?>
<?php if ($layout == 'modal') vc_modal_layout($vids); ?>
<?php if ($layout == 'embed') vc_embed_layout($vids, $i); ?> **This is line 252**
</div>
</section>
You're not accepting any arguments in vc_modal_layout() function declaration.
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout() {
needs to have parameters in order to accept arguments.
something like this is what you're looking for:
if (!function_exists('vc_embed_layout')) {
function vc_embed_layout($vids=[], $i=0) {
And it's the same idea with vc_modal_layout, the function needs to be able to accept the variables from outside it.
When we call a function, the function needs to be able to accept all arguments passed to it. And all variables we use need to be defined, if there's a risk of them being undefined or empty arrays, we can check them with if(!empty($var)) or if(isset($var))
An alternative to passing the variable to the function is to access it as a global. But it's generally better to pass the variable to the function because when we pass the variable to a function in PHP it works with a copy of the variable's value inside the function. When we do something like this:
$var = 10;
function doIt(){
global $var;
$var++;
}
doit();
echo $var;
we could overcomplicate things..
let's have a closer look here:
if ($layout == 'modal') vc_modal_layout($vids);
if ($layout == 'embed') vc_embed_layout($vids, $i); ?> **This is line 252**
function vc_modal_layout(){ ... }
// should be:
function vc_modal_layout($vids){ ... }
function vc_embed_layout($vids, $i)
// looks good.
Aside from that, nothing stands out as really unusual & I'd want to have a look at the actual site to tinker with this problem further.
i need your help in this case; i have module in joomla and want to cutting title with specified a limit from joomla library string.php. i change this code :
<?php if ($params->get('show_title', 1)) : ?>
<h3 itemprop="name">
<?php if ($params->get('link_titles') && $params->get('access-view')) : ?>
<?php echo $this->escape($displayData->title); ?>
<?php else : ?>
<?php echo $this->escape($displayData->title); ?>
<?php endif; ?>
</h3>
to this code :
<?php if ($params->get('show_title', 1)) : ?>
<h3 itemprop="name">
<?php if ($params->get('link_titles') && $params->get('access-view')) : ?>
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($displayData->slug, $displayData->catid)); ?>" itemprop="url">
<?php
$limit =100;
if (strlen($this->item->text) > $limit) {
echo (substr($this->item->text, 0, $limit)) . " ... ";
}
else {
echo $this->escape($displayData->title); } ?></a><?php else : ?>
<?php endif; ?>
</h3>
but not work.
thanks for your attention guys.
Joomla has a built-in JHtmlString/truncate method which you can use, I've had good success using it with some of our templates and overrides.
This method would let you simplify your code and you could replace you entire last php block with something like the following
<?php
$limit =100;
echo JHTML::_('string.truncate', ($this->item->text), $limit, false, false);
?>
More about JHtmlString/truncate: https://docs.joomla.org/API16:JHtmlString/truncate
Some example code which might be helpful:
https://gist.github.com/2dpi/a540527a64f9f0093392
https://hotexamples.com/examples/-/JHtmlString/truncateComplex/php-jhtmlstring-truncatecomplex-method-examples.html
Good luck!
I like to insert adsense in the middle of category, archive, tag & search page listing on a WordPress website. Here is the closest solution I can find online:
<?php $postcounter = 1;
if (have_posts()) : ?>
<?php while (have_posts()) : $postcounter = $postcounter + 1;
the_post(); ?>
<?php if(4 == $postcounter)
{ echo ' <div id="adsbetween">
<center> YOUR_ADSENSE_CODE </center>
</div> ' ;
} ?>
I need help on applying the same with what I have in my theme below:
if (($cat_layout == 'masonry-3') || ($cat_layout == 'masonry-2')) {
echo '<div class="module-masonry-wrapper clear-fix">';
echo '<div class="masonry-content-container">';
while (have_posts()): the_post();
echo kid_masonry_render(get_the_ID());
endwhile;
echo '</div></div>';
Here is another instance:
echo '<div class="classic-blog-content-container">';
while (have_posts()): the_post();
echo kid_classic_blog_render(get_the_ID(), 35);
endwhile;
echo '</div>';
The code should ad ADSENSE_CODE after the 4th listing.
Any help?
This should inject the adsense and let the loop continue (I think that is what you want).
if($cat_layout=='masonry-3' || $cat_layout=='masonry-2'){
$postcounter=1;
echo '<div class="module-masonry-wrapper clear-fix">';
echo '<div class="masonry-content-container">';
while(have_posts()){
if($postcounter==4){
echo '<div id="adsbetween"><center>YOUR_ADSENSE_CODE</center></div>';
}
the_post();
echo kid_masonry_render(get_the_ID());
++$postcounter;
}
echo '</div>';
echo '</div>';
}
The extra case:
$postcounter=1;
echo '<div class="classic-blog-content-container">';
while(have_posts()){
if($postcounter==4){
echo '<div id="adsbetween"><center>YOUR_ADSENSE_CODE</center></div>';
}
the_post();
echo kid_classic_blog_render(get_the_ID(),35);
++$postcounter;
}
echo '</div>';'
I want to get correct category link where post has posted!
Simple example: http://news.filmground.host-ed.me/
Look "Author: Elar", so next after that should be a category link like "Category: Game News"!
I think source code is here, taken from plugin "categories"
code is here
<?php
// =====================================================================
// PLUGIN INFO
// =====================================================================
$_PLUGIN_CONFIG['DATA'] = array(
'author'=>'Diego Najar',
'version'=>'3.6',
'url'=>'http://www.nibbleblog.com'
);
// =====================================================================
// PLUGIN CLASS
// =====================================================================
class PLUGIN_CATEGORIES extends Plugin
{
public function blog_body()
{
global $categories;
$html = '<ul>';
foreach($categories as $category)
{
// URL generator
$href = Url::category($category['slug']);
$html .= '<li class="category">'.$category['name'].'</li>';
}
$html .= '</ul>';
return $html;
}
}
?>
and page where this goes is here
<header>
<h1 class="post-title">
<?php echo Post::title() ?>
</h1>
<div class="post-published"><span style="font-size:13px"><img alt="Date when post was added!" src="img/dd.png" style="height:13px; margin-bottom:-2px; margin-top:0px; width:13px" title="Date when post was added!" /> Posted on:</span> <?php echo Post::published() ?> | <img alt="Date when post was added!" src="img/au.png" style="height:13px; margin-bottom:-2px; margin-top:0px; width:13px" title="Post author!" /> Author: Elar</div>
</header>
<div class="post-content">
<?php echo Post::content() ?>
</div>
<footer>
<span class="comment-count">
<?php echo Post::comment_count_link() ?>
</span>
<div class="post-tags"><?php echo Post::tags ()?></div>
</footer>
And also how get commas between tags?
<div class="post-tags"><?php echo Post::tags ()?></div>
I am using nibbleblog blog script!
For category try to add this to your html
<?php echo Post::category() ?>
And for tags this should work:
<?php
$tagLinks = array();
foreach (Post::tags(TRUE) as $tag) {
$tagLinks[] = '<a class="tag" href="' . Url::tag($tag['name']) . '">' . $tag['name_human'].'</a>';
}
?>
<div class="post-tags"><?php echo implode(', ', $tagLinks); ?></div>
I'm hoping that someone can help me out here. I am trying to get ACF integrated into a Theme a client purchased.
The basic functionality is that I have built a custom field on every post to choose where to place the post. Thus, if they choose “Option A” in the post, then the code needs to check for that option to be true before passing all of the content related to the post (Title, Content, Images, etc.)
A basic code example of how this would work in a standard php document would be as follows:
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<?php if(get_field('pick_your_theme') == "Theme1") { ?>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<?php } ?><?php endwhile; ?>
<?php endif; ?>
The issue here is that the theme author has created the page in one giant open PHP function rather than breaking it up (as in example code 1 above) where I can easily insert the selector get_field.
Below is a link for the PHP code for the page:
http://pastebin.com/wyWQiQvx
Normally you should already be able to access ACM fields within the loop using the following code:
<?php the_field('NAME_OF_FIELD'); ?>
Building on #ChrisHerbert's comment, it should be a simple matter of sneaking your conditional in there, so the loop section of your code looks something like this:
if ( have_posts() ){ while (have_posts()){ the_post();
if(get_field('pick_your_theme') == "Theme1") {
if( $gdl_show_title != "No" ){
echo '<div class="sixteen columns mb0">';
echo '<div class="page-header-wrapper">';
echo '<h1 class="page-header-title title-color gdl-title">' . get_the_title() . '</h1>';
echo '<div class="header-gimmick mr0"></div>';
echo '<div class="clear"></div>';
echo '</div>';
echo '</div>'; // sixteen columns
}
if( $page_background != 'No' ){
echo "<div class='sixteen columns'>";
echo '<div class="page-bkp-frame-wrapper">';
echo '<div class="page-bkp-frame">';
}
$content = get_the_content();
// Show content
if( $gdl_show_content != 'No' && !empty($content) ){
echo '<div class="sixteen columns">';
echo '<div class="gdl-page-content">';
echo '<div class="bkp-frame-wrapper">';
echo '<div class="bkp-frame p20">';
the_content();
echo '</div>';
echo '</div>';
echo '</div>'; // page-content
echo '</div>'; // sixteen columns
}
} //pick_your_theme conditional
} // while loop
} //if have posts
Clearly you can customize the code within the 'pick_your_theme' conditional to meet you needs and add a } elseif(get_field('pick_your_theme') == "Some_Other_Theme") { or a default for when 'pick_your_theme' isn't set } else { block in there as needed.