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>
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 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!
Right now I have the following PHP:
<?php
$pages = get_pages( array( 'sort_column'=>'menu_order', 'parent'=>'0') );
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
$pageid=$page_data->ID;
echo '<div class="section'.(($title=='intro')?' intro-section':"").'">';
echo $content;
echo "</div>";
}
?>
There are 5 Pages, 2 of which have many child Pages. I want to take the above code further one level, so that each page will have its own wrapper, and, if a Page has children Pages, those pages will be placed within the same .section, but each within a separate div. Any advice? I'm a bit inexperienced in Wordpress so any help would be great. Below should give an example of what I want:
<div class="section">
<div class="page parent"></div>
</div>
<div class="section">
<div class="page parent"></div>
<div class="page child"></div>
<div class="page child"></div>
</div>
<div class="section">
<div class="page parent"></div>
</div>
Below is the code I'm working with right now.
<?php while (have_posts()) : the_post(); ?>
<?php
$pages = get_pages( array( 'sort_column'=>'menu_order', 'parent'=>'0') );
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
$pageid=$page_data->ID;
//Put a container around every page's content
if (count(get_pages('child_of=' . $page_data->ID.''))) {
// Loop through $page_data array to print the div you want
echo '<div class="section">';
echo '<div class="slide">';
echo $content;
echo "</div>";
$children = get_pages('child_of=' . $page_data->ID.'');
foreach( $children as $child ) {
$childcontent = apply_filters('the_content', $child->post_content);
echo '<div class="slide">';
echo $childcontent;
echo "</div>";
}
echo "</div><!--end section-->";
} else {
echo '<div class="section'.(($title=='intro')?' intro-section':"").'">';
echo $content;
echo "</div>";
}
}
?>
<?php endwhile ?>
Use child_of parameter of get_pages() function inside the loop. This parameter lists the sub-pages of a single Page only. It uses the ID for a Page as the value.
Eg.
if (count(get_pages('child_of=' . $page_data->ID))) {
// Loop through $page_data array to print the div you want
}
I've recently come to a project where using custom fields would be pretty handy. It's for a restaurant and if I can get this right, I could use this bit of code for a few different sections of the site.
I'm using the Magic Fields 2 plugin and right now it's awesome, except for when it comes to displaying the fields I've created. Here's where I'm getting pretty lost.
For example, I have a post called "Specials" and that has a grouping called "Menu Item" and that group has two fields called "Name" and "Description". Basically name serves as the menu item name, and description will be a small blurb about the food item.
Here's the code in my theme for this section right now:
<div id="specials">
<?php
$query2 = get_post(28);
$title = $query2->post_title;
$itemname= get_post_meta($post->ID, 'menu_item_name', true);
$description = get_post_meta($post->ID, 'menu_item_description', true);
?>
<div id="specialstitle"><?php echo $title; ?></div>
<div class="stripebackbrown"> </div>
<div id="specialslist">
<?php while ( have_posts() ) : the_post();
echo '<span>'.$itemname.'</span>';
echo '<p>'.$description.'</p>';
endwhile;
wp_reset_query();
?>
</div>
</div><!-- end specials-->
Now there is a very good chance what I'm doing in the above code is completely wrong, if it is, please let me know.
What I'm experiencing with the above code however is it's pulling the very first group for that post.
So instead of something like:
Tomato Soup
description text here
Turkey Sandwich
description text here
Greek Salad
description text here
I'm getting:
Tomato Soup
description text here
Tomato Soup
description text here
Tomato Soup
description text here
So while the above code is technically working, it's not working properly at the same time.
Any help would be greatly appreciated!
EDIT:
I'm having some better success with this:
<div id="specials">
<?php
$query2 = get_post(28);
$title = $query2->post_title;
?>
<div id="specialstitle"><?php echo $title; ?></div>
<div class="stripebackbrown"> </div>
<div id="specialslist">
<?php $itemname = get_post_meta ($post->ID, 'menu_item_name', false); ?>
<?php $description = get_post_meta ($post->ID, 'menu_item_description', false); ?>
<?php foreach ($itemname as $itemname){
echo '<span>' .$itemname. '</span>';
echo '<p>' .$description. '</p>';
} ?>
</div>
</div><!-- end specials-->
However, I'm not sure how to add $description to that foreach loop. So right now it's listing out the menu names but adding "Array" where the description should be. Getting closer!
I think you want to do this like that:
<div id="specials">
<?php
$query2 = get_post(28);
$title = $query2->post_title;
?>
<div id="specialstitle"><?php echo $title; ?></div>
<div class="stripebackbrown"> </div>
<div id="specialslist">
<?php while ( have_posts() ) : the_post();
$itemname = get_post_meta(get_the_ID(), 'menu_item_name', true);
$description = get_post_meta(get_the_ID(), 'menu_item_description', true);
echo '<span>'.$itemname.'</span>';
echo '<p>'.$description.'</p>';
endwhile;
wp_reset_query();
?>
</div>
Found a solution:
<?php
$query2 = get_post(28);
$title = $query2->post_title;
?>
<div id="specialstitle"><?php echo $title; ?></div>
<div class="stripebackbrown"> </div>
<div id="specialslist">
<?php $itemname = get_post_meta ($post->ID, 'menu_item_name', false); ?>
<?php $description = get_post_meta ($post->ID, 'menu_item_description', false); ?>
<?php foreach (array_combine($itemname, $description) as $itemname => $description){
echo '<span>' .$itemname. '</span>';
echo '<p>' .$description. '</p>';
} ?>
</div>
</div><!-- end specials-->
This combines the two arrays created by $itemname and $description and loops them as many times as there are groups to loop.
#speccode, thanks so much for trying to help me, your reordering of my two lines got me heading in the right direction.
I know this is old but I had the same problem so I attempted to improved #speccode answers' a tiny bit and it seems to work:
<?php $itemnames = get_post_meta($post->ID, 'itemnames', false); ?>
<?php $descriptions = get_post_meta($post->ID, 'descriptions', false); ?>
<?php foreach (array_combine($itemnames, $descriptions) as $itemname => $description)
{
echo '<img src="'.$itemname.'"/>';
echo '<p>' .$description. '</p>';
}
?>
I also attempted abit of structuring in there (see below) but I can't guarantee the validity of the markup... anyone?
<?php $itemnames = get_post_meta($post->ID, 'itemnames', false); ?>
<?php $descriptions = get_post_meta($post->ID, 'descriptions', false); ?>
<?php foreach (array_combine($itemnames, $descriptions) as $itemname => $description)
{
echo '<div class="nameAndDescription"><img src="'.$itemname.'"/>';
echo '<p>' .$description. '</p></div>';
}
?>
I'm using a plugin titled "WP Recent Links" which I first learned about via Eric Meyer's site. Eric uses to display a Link Log within his site and I'm doing the same on my test site - http://matala.jorgeledesma.net/ but I'm running into a little situation and that is that I don't know how to limit the output either on the sidebar or the actual page - http://matala.jorgeledesma.net/recent-links/
My goal is to have it echo only the first 5 entries on the sidebar and for the recent-links page only echo the current month. The code below displays the sidebar properly
<?php if (!is_page('48')) { ?>
<aside id="meta" class="widget">
<h1 class="widget-title">Link Log</h1>
<?php if ($links = rp_recentlinks_home()) { ?>
<ul>
<?php foreach ($links as $link) { ?>
<b><li><?php echo wptexturize($link->link_text); ?></b>
<?php if ('' != $link->link_caption) { ?>→
<?php echo wptexturize(convert_smilies($link->link_caption)); ?><?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</aside>
<?php } ?>
and this code display the actual recent-links page
<h1 class="page-title"><?php rp_recentlinks_archive_header(); ?></h1>
</header>
<div class="entry-content">
<?php $links = rp_recentlinks_archive_page(); ?>
</div>
<?php if ($links) { ?>
<ul>
<?php foreach ($links as $link) { ?>
<p id="rlink-<?php echo $link->ID; ?>"><?php echo wptexturize($link->link_text); ?>
<?php if ('' != $link->link_caption) { ?>→
<?php echo wptexturize(convert_smilies($link->link_caption)); ?><?php } ?>
</p>
<?php } ?>
</ul>
<?php } ?>
I tried putting the following code in the body.
$list = array_slice($input, 0, 5); // $list now only having first 5 item.
But I don't know how to apply it, if that's the command at all. So perhaps, someone can guide in the right direction. Thanks in advance, Jorge.
Looks like all you have to add is this before you pass $links to the foreach loop:
$links = array_slice($links,0,5);