Wordpress Category Thumbnail List Plugin - php

I'm trying to tweak a Wordpress Plugin - Category Thumbnail List to display "Coming Soon" when the shortcode calls for posts in a category but there are none.
I've tried contacting the developer but had no luck.
I've modified the original code using the following but it doesn't display. Any ideas?
foreach($myposts as $post) :
setup_postdata($post);
if ( has_post_thumbnail() ) {
$link = get_permalink($post->ID);
$thmb = get_the_post_thumbnail($post->ID,'thumbnail');
$title = get_the_title();
$output .= '<div class="categoryThumbnailList_item">';
$output .= '' .$thmb . '<br/>';
$output .= '' .$title . '';
$output .= '</div>';
} else {
$output .= '<p>Coming Soon</p>';
}
endforeach;
Here's the full code:
<?php
/*
Plugin Name: Category Thumbnail List
Plugin URI: http://jonk.pirateboy.net/blog/category/bloggeriet/wordpress/plugins/
Description: Creates a list of thumbnail images, using the_post_thumbnail() in WordPress 2.9 and up.
Version: 1.11
Author: Jonk
Author URI: http://jonk.pirateboy.net
*/
$categoryThumbnailList_Order = stripslashes( get_option( 'category-thumbnail-list_order' ) );
if ($categoryThumbnailList_Order == '') {
$categoryThumbnailList_Order = 'date';
}
$categoryThumbnailList_OrderType = stripslashes( get_option( 'category-thumbnail-list_ordertype' ) );
if ($categoryThumbnailList_OrderType == '') {
$categoryThumbnailList_OrderType = 'DESC';
}
$categoryThumbnailList_Path = get_option('siteurl')."/wp-content/plugins/categoy-thumbnail-list/";
define("categoryThumbnailList_REGEXP", "/\[categorythumbnaillist ([[:print:]]+)\]/");
define("categoryThumbnailList_TARGET", "###CATTHMBLST###");
function categoryThumbnailList_callback($listCatId) {
global $post;
global $categoryThumbnailList_Order;
global $categoryThumbnailList_OrderType;
$tmp_post = $post;
$myposts = get_posts('numberposts=-1&&category='.$listCatId[1].'&&orderby='.$categoryThumbnailList_OrderType.'&&order='.$categoryThumbnailList_Order);
$output = '<div class="categoryThumbnailList">';
foreach($myposts as $post) :
setup_postdata($post);
if ( has_post_thumbnail() ) {
$link = get_permalink($post->ID);
$thmb = get_the_post_thumbnail($post->ID,'thumbnail');
$title = get_the_title();
$output .= '<div class="categoryThumbnailList_item">';
$output .= '' .$thmb . '<br/>';
$output .= '' .$title . '';
$output .= '</div>';
} else {
$output .= '<p>Coming Soon</p>';
}
endforeach;
$output .= '</div>';
$output .= '<div class="categoryThumbnailList_clearer"></div>';
$post = $tmp_post;
wp_reset_postdata();
return ($output);
$output = '';
}
function categoryThumbnailList($content) {
return (preg_replace_callback(categoryThumbnailList_REGEXP, 'categoryThumbnailList_callback', $content));
}
function categoryThumbnailList_css() {
global $categoryThumbnailList_Path;
echo "
<style type=\"text/css\">
#import url(\"".$categoryThumbnailList_Path."categoy-thumbnail-list.css\");
</style>
";
}
add_action('wp_head', 'categoryThumbnailList_css');
add_filter('the_content', 'categoryThumbnailList',1);
?>
<?php
add_action('admin_menu', 'my_plugin_menu');
function my_plugin_menu() {
add_options_page('Category Thumbnail List Options', 'Category Thumbnail List', 'manage_options', 'category-thumbnail-list', 'my_plugin_options');
}
function my_plugin_options() {
global $categoryThumbnailList_Order;
global $categoryThumbnailList_OrderType;
if( $_POST['save_category-thumbnail-list_settings'] ) {
// update order type
if( !$_POST['category-thumbnail-list_ordertype'] )
{
$_POST['category-thumbnail-list_ordertype'] = 'date';
}
update_option('category-thumbnail-list_ordertype', $_POST['category-thumbnail-list_ordertype'] );
// update order
if( !$_POST['category-thumbnail-list_order'] )
{
$_POST['category-thumbnail-list_order'] = 'DESC';
}
update_option('category-thumbnail-list_order', $_POST['category-thumbnail-list_order'] );
$categoryThumbnailList_Order = stripslashes( get_option( 'category-thumbnail-list_order' ) );
$categoryThumbnailList_OrderType = stripslashes( get_option( 'category-thumbnail-list_ordertype' ) );
echo "<div id=\"message\" class=\"updated fade\"><p>Your settings are now updated</p></div>\n";
}
?>
<div class="wrap">
<h2>Category Thumbnail List Settings</h2>
<form method="post">
<table class="form-table">
<tr valign="top">
<th scope="row">Order by</th>
<td>
<select name="category-thumbnail-list_ordertype" id="category-thumbnail-list_ordertype">
<option <?php if ($categoryThumbnailList_OrderType == 'date') { echo 'selected="selected"'; } ?> value="date">Date</option>
<option <?php if ($categoryThumbnailList_OrderType == 'title') { echo 'selected="selected"'; } ?> value="title">Title</option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">Display order</th>
<td>
<select name="category-thumbnail-list_order" id="category-thumbnail-list_order">
<option <?php if ($categoryThumbnailList_Order == 'DESC') { echo 'selected="selected"'; } ?> value="DESC">Descending (z-a/9-1/2010-2001)</option>
<option <?php if ($categoryThumbnailList_Order == 'ASC') { echo 'selected="selected"'; } ?> value="ASC">Ascending (a-z/1-9/2001-2010)</option>
</select>
</td>
</tr>
</table>
<div class="submit">
<!--<input type="submit" name="reset_category-thumbnail-list_settings" value="<?php _e('Reset') ?>" />-->
<input type="submit" name="save_category-thumbnail-list_settings" value="<?php _e('Save Settings') ?>" class="button-primary" />
</div>
<div>
Update the thumbnail sizes here
</div>
<div>
You may need to update your css when changing the thumbnail size
</div>
</form>
</div>
<?php
}
?>
Many Thanks,
Mike

Haven't tested your code, but a quick glance shows at least one problem... you're using this outside of the loop. When not used in the loop, has_post_thumbnail() doesn't know what post you're checking. With just that modification, your code should be this:
foreach($myposts as $post) :
setup_postdata($post);
if ( has_post_thumbnail( $post->ID ) ) {
$link = get_permalink($post->ID);
$thmb = get_the_post_thumbnail($post->ID,'thumbnail');
$title = get_the_title();
$output .= '<div class="categoryThumbnailList_item">';
$output .= '' .$thmb . '<br/>';
$output .= '' .$title . '';
$output .= '</div>';
} else {
$output .= '<p>Coming Soon</p>';
}
endforeach;

Related

Merging and ordering XML feeds with PHP - Very slow to load

Within wordpress and using ACF Pro, I'm merging multiple Songkick XML feeds with PHP, attaching an artist name to them (annoyingly each feed doesn't include the artist name), and ordering them by the event date.
I've managed to put this all together (with help from different questions on here) using separate steps, but the page is loading very slowly, so I wondered if there was a way of streamlining or merging some of the steps?
With the code below I am:
Fetching multiple XML feeds (sing an ACF fields from other pages on the site)
Attaching an artist name to each feed
Merging the feeds (whilst removing some of the data to try and speed
up the processing time)
Outputting the information into a table while ordering by date
My code below:
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => 'artists'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) : $artistFeedCount = 0; while ( $parent->have_posts() ) : $parent->the_post(); if( get_page_template_slug() == 'template-artist.php' && 'publish' === get_post_status() ) {
$singleArtistName = get_the_title();
$singleArtistSongkickRSS = 'https://api.songkick.com/api/3.0/artists/' . get_field('artist_songkick_id') . '/calendar.xml?apikey=XXXXXXXXXXXXXXXX';
$SongkickEvents[]=$singleArtistName;
$SongkickEvents[$singleArtistSongkickRSS] = $SongkickEvents[$artistFeedCount];
unset($SongkickEvents[$artistFeedCount]);
$artistFeedCount++;
?>
<?php }; endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
<?php
$eventsDom = new DOMDocument();
$eventsDom->appendChild($eventsDom->createElement('events'));
foreach ($SongkickEvents as $artist_dates => $artist_name ) {
$eventsAddDom = new DOMDocument();
$eventsAddDom->load($artist_dates);
$events = $eventsAddDom->getElementsByTagName('event');
if ($eventsAddDom->documentElement) {
foreach ($events as $event) {
$eventsDom->documentElement->appendChild(
$eventsDom->importNode($event, TRUE)
);
$artistName = $eventsDom->createElement('mainartist', $artist_name);
foreach($eventsDom->getElementsByTagName('event') as $singleEvent) {
$singleEvent->appendChild($artistName);
}
foreach($eventsDom->getElementsByTagName('performance') as $singlePerformance) {
$singlePerformance->parentNode->removeChild($singlePerformance);
}
}
}
}
$newXML = $eventsDom->saveXml();
$LiveDates = simplexml_load_string($newXML);
$eventsArr=array();
foreach($LiveDates->event as $eventsArrSingle)
{
$eventsArr[]=$eventsArrSingle;
}
usort($eventsArr,function($dstart,$dend){
return strtotime($dstart->start['date'])-strtotime($dend->start['date']);
});
foreach($eventsArr as $eventsArrSingle) { ?>
<div class="event-row <?php $eventStatus = $eventsArrSingle['status']; if($eventStatus == 'cancelled' || $eventStatus == 'postponed'): echo 'cancelled'; endif; ?>">
<div class="event-block event-date">
<span><?php $eventDate=$eventsArrSingle->start['date']; echo date("d", strtotime($eventDate)); ?></span>
<?php echo date("M", strtotime($eventDate)); ?>
</div>
<div class="event-block event-info">
<span><?php echo $eventsArrSingle->mainartist; ?></span>
<?php if($eventsArrSingle->venue['displayName'] != 'Unknown venue'): echo $eventsArrSingle->venue['displayName'] . ', '; endif; ?><?php echo $eventsArrSingle->venue->metroArea['displayName']; ?>
</div>
<div class="event-block event-button">
<span><?php if($eventStatus == 'cancelled'): echo 'Cancelled'; elseif($eventStatus == 'postponed'): echo 'Postponed'; else: echo 'Tickets'; endif; ?></span> <i class="fas fa-arrow-right"></i>
</div>
</div>
<?php };?>
Any help would be greatly appreciated, I'm sure there's a way of merging everything in fewer steps!
For anyone coming across the same issue, this is the solution I used. Using the Transient API to store the feed for 3 hours at a time.
<?php
function eventsFunction() {
// Do we have this information in our transients already?
$eventTransient = get_transient( 'eventsTransientData' );
// Yep! Just return it and we're done.
if( ! empty( $eventTransient ) ) {
echo $eventTransient;
} else {
$single_artist_ids = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => 'artists'
);
$parent = new WP_Query( $single_artist_ids );
if ( $parent->have_posts() ) : $artistFeedCount = 0; while ( $parent->have_posts() ) : $parent->the_post(); if( get_page_template_slug() == 'template-artist.php' && 'publish' === get_post_status() ) {
$singleArtistName = get_the_title();
$singleArtistSongkickRSS = 'https://api.songkick.com/api/3.0/artists/' . get_field('artist_songkick_id') . '/calendar.xml?apikey= XXXXXXXXXXXXXXXX';
$SongkickEvents[]=$singleArtistName;
$SongkickEvents[$singleArtistSongkickRSS] = $SongkickEvents[$artistFeedCount];
unset($SongkickEvents[$artistFeedCount]);
$artistFeedCount++;
?>
<?php }; endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
<?php
$eventsDom = new DOMDocument();
$eventsDom->appendChild($eventsDom->createElement('events'));
foreach ($SongkickEvents as $artist_dates => $artist_name ) {
$eventsAddDom = new DOMDocument();
$eventsAddDom->load($artist_dates);
$events = $eventsAddDom->getElementsByTagName('event');
if ($eventsAddDom->documentElement) {
foreach ($events as $event) {
$eventsDom->documentElement->appendChild(
$eventsDom->importNode($event, TRUE)
);
$artistName = $eventsDom->createElement('mainartist', $artist_name);
foreach($eventsDom->getElementsByTagName('event') as $singleEvent) {
$singleEvent->appendChild($artistName);
}
foreach($eventsDom->getElementsByTagName('performance') as $singlePerformance) {
$singlePerformance->parentNode->removeChild($singlePerformance);
}
}
}
}
$eventsXML = $eventsDom->saveXml();
$LiveDates = simplexml_load_string($eventsXML);
$eventsArr=array();
foreach($LiveDates->event as $eventsArrSingle)
{
$eventsArr[]=$eventsArrSingle;
}
usort($eventsArr,function($dstart,$dend){
return strtotime($dstart->start['date'])-strtotime($dend->start['date']);
});
$eventsStored = '';
foreach($eventsArr as $eventsArrSingle) {
$eventsStored .= '<div class="event-row ';
$eventStatus = $eventsArrSingle['status']; if($eventStatus == 'cancelled' || $eventStatus == 'postponed'): $eventsStored .= 'cancelled'; endif;
$eventsStored .= '">
<div class="event-block event-date">
<span>';
$eventDate=$eventsArrSingle->start['date']; $eventsStored .= date("d", strtotime($eventDate));
$eventsStored .= '</span>';
$eventsStored .= date("M", strtotime($eventDate));
$eventsStored .= '</div>
<div class="event-block event-info">
<span>';
$eventsStored .= $eventsArrSingle->mainartist;
$eventsStored .= '</span>';
if($eventsArrSingle->venue['displayName'] != 'Unknown venue'): $eventsStored .= $eventsArrSingle->venue['displayName'] . ', '; endif;
$eventsStored .= $eventsArrSingle->venue->metroArea['displayName'];
$eventsStored .= '</div>
<div class="event-block event-button">
<a href="' . $eventsArrSingle['uri'] . '" target="_blank"><span>';
if($eventStatus == 'cancelled'): $eventsStored .= 'Cancelled'; elseif($eventStatus == 'postponed'): $eventsStored .= 'Postponed'; else: $eventsStored .= 'Tickets'; endif;
$eventsStored .= '</span> <i class="fas fa-arrow-right"></i></a>
</div>
</div>';
};
set_transient( 'eventsTransientData', $eventsStored, 3*HOUR_IN_SECONDS );
echo $eventsStored;
}
}
eventsFunction();
?>

How to fix the problem with the_content filter

I want to add shortcode that has information about my custom post after the_content but when i add the code it shown before the_content
Here is my code
<?php
function foobar_func() { ?>
<h3>Title : </h3>
<ul>
<li>foo : </li>
</ul>
<?php }
add_shortcode( 'project_information', 'foobar_func' );
function wpdev_before_after( $content ) {
$beforecontent = '';
if ( is_single() ) {
$aftercontent = '[project_information]';
} else {
$aftercontent = '';
}
$fullcontent = $beforecontent . $content . $aftercontent;
return $fullcontent;
}
add_filter('the_content', 'wpdev_before_after');
?>
My foobar_func should be like this and i have more custom taxonomy to list and if I use variable to show them my code will be very messy
function foobar_func() { ?>
<h3>Title : </h3>
<ul>
<li>foo : <?php
$terms = wp_get_post_terms( $post->ID, 'taxonomy', $args );
foreach( $terms as $term ) {
if ( end($terms) == $term ){
echo '' . $term->name . '';
} else {
echo '' . $term->name . ' , ';
}
}
?></li>
</ul>
<?php }
Try assigning the html to a variable and return it in your foobar_func()
function foobar_func() {
$html = "
<h3>Title : </h3>
<ul>
<li>foo :
";
$terms = wp_get_post_terms( $post->ID, 'taxonomy', $args );
foreach( $terms as $term ) {
if ( end($terms) == $term ){
$html .= '' . $term->name . '';
} else {
$html .= '' . $term->name . ' , ';
}
}
$html .= "
</li>
</ul>";
return $html;
}

upload categorie to woocommerce

hello I am new to programing. I am creating a simple RSS feed plugin for wordpress to upload some products to WooCommerce and need to upload the category to wordpress . In plugin the category is visible but they are not showing like the url link. I need the category to show like checkbox. Can anybody have any idea ?
File number 1
* Init feed with information from DB
private function load()
{
if ($this->id) {
$post = get_post( $this->id );
if (!$post) {
$this->id = null;
return;
}
$this->title = $post->post_title;
$this->id = $post->ID;
$meta = get_post_meta($post->ID);
foreach ($meta as $key=>$item) {
$newKey = substr($key, 1);
$this->properties[$newKey] = $item[0];
if ($newKey == 'post_category') {
$this->properties[$newKey] = unserialize($item[0]);
}
}
}
}
..................
$fields = array( 'post_category');
..................
// Create post
$post = array('post_category' => $this->post_category);
And the file number 2 have this
<div class="postbox">
<div class="handlediv" title="<?php esc_html_e('Click to toggle', 'rss-autopilot'); ?>"><br></div>
<h3 class="hndle ui-sortable-handle"><span><?php esc_html_e('Categories', 'rss-autopilot'); ?></span></h3>
<div class="inside">
<ul class="rssap-categories-list">
<?php wp_category_checklist( 0, 0, $feed->post_category, false, null, true ); ?>
</ul>
<div class="clear"></div>
</div>
</div>
Here is your code.
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul class="product-cats">';
foreach ( $terms as $term ) {
echo '<li class="category">';
echo '<h2>';
echo '<input name="product_category[]" type="checkbox" value="'. $term->term_id.'"';
echo $term->name;
echo '</a>';
echo '</h2>';
echo '</li>';
}
echo '</ul>';
}

Why won't my WP widget respond to my code edits? TPL is involved

(Posted this on the WP StackExchange, but was sent back here. So hello!)
I'm attempting to modify a WP widget that displays the portfolio page from this template, Royal Startex (please click Portfolio in the header). The template is based on the Klasik Framework. Documentation for both is nearly non-existent.
As it stands, the widget pulls category-based posts & their post thumbnail and displays them as a grid; clicking on the image effects a lightbox & slideshow effect.
Instead, I'd like clicking on the image to go directly to the post. No lightbox, no slideshow. I've been attempting to modify the plugin's code, but haven't had any luck. My changes don't seem to have any effect (unless I just delete a bunch of random code, which breaks the page). I'm assuming the main problem is my unfamiliarity with how $tpl works. First time I've seen it.
Here's the plugin code:
function Klasik_PFilterWidget() {
$widget_ops = array('classname' => 'widget_klasik_pfilter', 'description' => __('KlasikThemes Portfolio Filter','klasik') );
$this->WP_Widget('klasik-theme-pfilter-widget', __('KlasikThemes Portfolio Filter','klasik'), $widget_ops);
}
/** #see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
$cats = apply_filters('widget_category', empty($instance['category']) ? array() : $instance['category']);
$display = apply_filters('widget_display', empty($instance['display']) ? '' : $instance['display']);
$cols = apply_filters('widget_cols', empty($instance['cols']) ? '' : $instance['cols']);
$showposts = apply_filters('widget_showpost', empty($instance['showpost']) ? '' : $instance['showpost']);
$longdesc = apply_filters('widget_longdesc', empty($instance['longdesc']) ? '' : $instance['longdesc']);
$customclass = apply_filters('widget_customclass', empty($instance['customclass']) ? '' : $instance['customclass']);
$enablepagenum = apply_filters('widget_enablepagenum', isset($instance['enablepagenum']));
$instance['category'] = isset($instance['category'])? $instance['category'] : "";
global $wp_query;
?>
<?php echo $before_widget;
if ( $title!='' )
echo $before_title . esc_html($title) . $after_title;
$cols = intval($cols);
if(!is_numeric($cols) || $cols < 1 || $cols > 6){
$cols = 4;
}
$longdesc = (!is_numeric($longdesc) || empty($longdesc))? 0 : $longdesc;
$showposts = (!is_numeric($showposts))? get_option('posts_per_page') : $showposts;
$categories = $cats;
echo '<div class="klasik-portfolio '.$customclass.'">';
$approvedcat = array();
$sideoutput = "";
if( count($categories)!=0 ){
foreach ($categories as $key) {
$catname = get_term_by("slug",$key,"category");
$approvedcat[] = $key;
}
}
$approvedcatID = array();
$isotopeclass = "";
if( $display == 'filterable'){
echo '<div class="frame-filter">';
echo '<div class="filterlist">';
echo '<ul id="filter" class="controlnav">';
echo '<li class="segment-1 selected-1 current first">'.__('All Categories','klasik').'</li>';
foreach ($categories as $key) {
$catname = get_term_by("slug",$key,"category");
echo '<li class="segment-1">'.$catname->name.'</li>';
$approvedcatID[] = $key;
}
echo '</ul>';
echo '</div>';
echo '</div>';
echo '<div class="clear"></div>';
$isotopeclass = "isotope portfoliolist";
$showposts = -1;
}else{
foreach ($categories as $key) {
$catname = get_term_by("slug",$key,"category");
$approvedcatID[] = $key;
}
}
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$args = array(
'post_type' => 'post',
"paged" => $paged,
'showposts' => $showposts,
'orderby' => 'date'
);
if( count($approvedcatID) ){
$args['tax_query'] = array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $approvedcat
)
);
}
$wp_query->query($args);
global $post;
$tpl = '<div data-id="id-%%ID%%" class="%%CLASS%%" data-type="%%KEY%%">';
$tpl .= '<div class="klasik-pf-img"><div class="shadowBottom">';
$tpl .= '<a class="pfzoom" href="%%FULLIMG%%" %%LBOXREL%% title="%%TITLE%%"><span class="rollover"></span>%%THUMB%%</a>';
$tpl .= '<div class="clear"></div>';
$tpl .= '</div></div>';
$tpl .= '<div class="klasik-pf-text">';
$tpl .='<h3 class="pftitle"><a href="%%LINK%%" title="%%TITLE%%">';
$tpl .='<span>%%TITLE%%</span>';
$tpl .='</a></h3>';
$tpl .='<div class="textcontainer">%%TEXT%%</div>';
$tpl .= '</div>';
$tpl .= '<div class="clear"></div>';
$tpl .= '</div>';
$tpl = apply_filters( 'klasik_pfilter_item_template', $tpl );
if ($wp_query->have_posts()) :
$x = 0;
$output = "";
$output .= '<div class="row '.$isotopeclass.'">';
while ($wp_query->have_posts()) : $wp_query->the_post();
$template = $tpl;
$custom = get_post_custom($post->ID);
$cf_price = (isset($custom['custom-price'][0]))? $custom['custom-price'][0] : "";
$cf_customdesc = get_the_title() ;
$x++;
if($cols==1){
$colclass = "twelve columns";
}elseif($cols==2){
$colclass = "one_half columns";
}elseif($cols==3){
$colclass = "one_third columns";
}elseif($cols==4){
$colclass = "one_fourth columns";
}elseif($cols==5){
$colclass = "one_fifth columns";
}elseif($cols==6){
$colclass = "one_sixth columns";
}
if($x%$cols==0){
$omega = "omega";
}elseif($x%$cols==1){
$omega = "alpha";
}else{
$omega = "";
}
$itemclass = $colclass .' '. $omega;
//get post-thumbnail attachment
$attachments = get_children( array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'orderby' => 'menu_order',
'post_mime_type' => 'image')
);
$fullimageurl = '';
$cf_thumb2 = '';
foreach ( $attachments as $att_id => $attachment ) {
$getimage = wp_get_attachment_image_src($att_id, 'widget-portfolio', true);
$fullimage = wp_get_attachment_image_src($att_id, 'full', true);
$portfolioimage = $getimage[0];
$cf_thumb2 ='<img src="'.$portfolioimage.'" alt="" />';
$thethumblb = $portfolioimage;
$fullimageurl = $fullimage[0];
}
//thumb image
if(has_post_thumbnail($post->ID)){
$cf_thumb = get_the_post_thumbnail($post->ID, 'widget-portfolio');
$thumb_id = get_post_thumbnail_id($post->ID);
$args = array(
'post_type' => 'attachment',
'post_status' => null,
'include' => $thumb_id
);
$fullimage = wp_get_attachment_image_src($thumb_id, 'full', true);
$fullimageurl = $fullimage[0];
$thumbnail_image = get_posts($args);
if ($thumbnail_image && isset($thumbnail_image[0])) {
$cf_customdesc = $thumbnail_image[0]->post_content;
}
}else{
$cf_thumb = $cf_thumb2;
}
//LIGHTBOX URL
//$custom = get_post_custom($post->ID);
//$cf_lightboxurl = (isset($custom["lightbox-url"][0]) && $custom["lightbox-url"][0]!="")? $custom["lightbox-url"][0] : "";
//if($cf_lightboxurl != ""){
// $fullimageurl = $cf_lightboxurl;
//}
$format = get_post_format($post->ID);
if(($format=="video")||($format=="audio")){
$lightboxrel = "";
$fullimageurl = get_permalink();
}else{
$lightboxrel = "data-rel=prettyPhoto[mixed]";
}
$ids = get_the_ID();
$addclass="";
$catinfos = get_the_terms($post->ID,'category');
$key = "";
if($catinfos){
foreach($catinfos as $catinfo){
$key .= " ".$catinfo->slug;
}
$key = trim($key);
}
//PORTFOLIOID
$template = str_replace( '%%ID%%', $post->ID, $template );
//POST-DAY
$postday = '';
$postday .= get_the_time( 'd' );
$template = str_replace( '%%DAY%%', $postday, $template );
//POST-MONTH
$postmonth = '';
$postmonth .= get_the_time('M');
$template = str_replace( '%%MONTH%', $postmonth, $template );
//POST-YEAR
$postyear = '';
$postyear .= get_the_time('Y');
$template = str_replace( '%%YEAR%', $postyear, $template );
//PORTFOLIOCLASS
$pfclass = 'item ';
$pfclass .= $itemclass.' ';
$pfclass .= $key;
$template = str_replace( '%%CLASS%%', $pfclass, $template );
//PORTFOLIOKEY
$pfkey = $key;
$template = str_replace( '%%KEY%%', $pfkey, $template );
//PORTFOLIOFULLIMAGE
$pffullimg = $fullimageurl;
$template = str_replace( '%%FULLIMG%%', $pffullimg, $template );
//LIGHTBOXREL
$pflightbox = $lightboxrel;
$template = str_replace( '%%LBOXREL%%', $pflightbox, $template );
//PORTFOLIOIMGTITLE
$pffullimgtitle = $cf_customdesc;
$template = str_replace( '%%FULLIMGTITLE%%', $pffullimgtitle, $template );
//PORTFOLIOLINK
$pflink = get_permalink();
$template = str_replace( '%%LINK%%', $pflink, $template );
//PORTFOLIOIMAGE
$pfthumb = '';
$pfthumb .= $cf_thumb;
$template = str_replace( '%%THUMB%%', $pfthumb, $template );
//PRICE
$pfprice = '';
$pfprice .= $cf_price;
$template = str_replace( '%%PRICE%%', $pfprice, $template );
//TAGS
$pftags = "";
$posttags = get_the_tags();
$count=0;
if ($posttags) {
foreach($posttags as $tag) {
$count++;
if (1 == $count) {
$pftags .= $tag->name . ' ';
}
}
}
$template = str_replace( '%%TAG%%', $pftags, $template );
//PORTFOLIOTITLE
$pftitle = '';
$pftitle .= get_the_title();
$template = str_replace( '%%TITLE%%', $pftitle, $template );
//PORTFOLIOTEXT
$pftext = '';
if($longdesc>0){
$excerpt = klasik_string_limit_char(get_the_excerpt(), $longdesc);
}else{
$excerpt = get_the_excerpt();
}
$pftext .= $excerpt;
$template = str_replace( '%%TEXT%%', $pftext, $template );
//PORTFOLIOCATEGORY
$pfcat = '';
$categories = get_the_category();
$separator = ', ';
if($categories){
foreach($categories as $category) {
$pfcat .= ''.$category->cat_name.''.$separator;
}
}
$template = str_replace( '%%CATEGORY%%', trim($pfcat, $separator), $template );
$output .= $template;
endwhile;
$output .= '</div>';
if($enablepagenum){
ob_start();
klasik_pagination();
$output.='<div class="clear"></div>';
$output .= ob_get_contents();
$output.='<div class="clear"></div>';
ob_end_clean();
}
echo $output;
endif;
$wp_query = null; $wp_query = $temp; wp_reset_query();
echo '<div class="clear"></div>';
echo '</div>';
?>
<?php echo $after_widget; ?>
<?php
}
/** #see WP_Widget::update */
function update($new_instance, $old_instance) {
return $new_instance;
}
/** #see WP_Widget::form */
function form($instance) {
$instance['title'] = (isset($instance['title']))? $instance['title'] : "";
$instance['category'] = (isset($instance['category']))? $instance['category'] : array();
$instance['display'] = (isset($instance['display']))? $instance['display'] : "";
$instance['cols'] = (isset($instance['cols']))? $instance['cols'] : "";
$instance['showpost'] = (isset($instance['showpost']))? $instance['showpost'] : "";
$instance['longdesc'] = (isset($instance['longdesc']))? $instance['longdesc'] : "";
$instance['customclass'] = (isset($instance['customclass']))? $instance['customclass'] : "";
$instance['enablepagenum'] = (isset($instance['enablepagenum']))? $instance['enablepagenum'] : "";
$title = esc_attr($instance['title']);
$categories = $instance['category'];
$display = esc_attr($instance['display']);
$cols = esc_attr($instance['cols']);
$showpost = esc_attr($instance['showpost']);
$customclass = esc_attr($instance['customclass']);
$longdesc = esc_attr($instance['longdesc']);
$enablepagenum = esc_attr($instance['enablepagenum']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'klasik'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Category:', 'klasik'); ?><br />
<?php
$chkvalue = $categories;
$portcategories = get_categories();
$returnstring = '';
foreach($portcategories as $category){
$checkedstr="";
if(in_array($category->slug,$chkvalue)){
$checkedstr = 'checked="checked"';
}
$returnstring .= '<div style="float:left;width:48%;">';
$returnstring .= '<label for="'. $this->get_field_id('category')."-". $category->slug .'">';
$returnstring .= '<input type="checkbox" value="'. $category->slug .'" name="'. $this->get_field_name('category'). '['.$category->slug.']" id="'. $this->get_field_id('category')."-". $category->slug . '" '.$checkedstr.' /> '. $category->name;
$returnstring .= '</label>';
$returnstring .= '</div>';
}
$returnstring .= '<div style="clear:both;"></div>';
echo $returnstring;
?>
</label></p>
<p><label for="<?php echo $this->get_field_id('display'); ?>"><?php _e('Display:', 'klasik'); ?></label><br />
<select id="<?php echo $this->get_field_id('display'); ?>" name="<?php echo $this->get_field_name('display'); ?>" class="widefat" style="width:50%;">
<?php foreach($this->get_display_options() as $k => $v ) { ?>
<option <?php selected( $instance['display'], $k); ?> value="<?php echo $k; ?>"><?php echo $v; ?></option>
<?php } ?>
</select></p>
<p><label for="<?php echo $this->get_field_id('cols'); ?>"><?php _e('Number of Columns:', 'klasik'); ?></label><br />
<select id="<?php echo $this->get_field_id('cols'); ?>" name="<?php echo $this->get_field_name('cols'); ?>" class="widefat" style="width:50%;">
<?php foreach($this->get_number_options() as $k => $v ) { ?>
<option <?php selected( $instance['cols'], $k); ?> value="<?php echo $k; ?>"><?php echo $v; ?></option>
<?php } ?>
</select></p>
<p><label for="<?php echo $this->get_field_id('showpost'); ?>"><?php _e('Number of Post:', 'klasik'); ?> <input class="widefat" id="<?php echo $this->get_field_id('showpost'); ?>" name="<?php echo $this->get_field_name('showpost'); ?>" type="text" value="<?php echo $showpost; ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('longdesc'); ?>"><?php _e('Length of Description Text:', 'klasik'); ?> <input class="widefat" id="<?php echo $this->get_field_id('longdesc'); ?>" name="<?php echo $this->get_field_name('longdesc'); ?>" type="text" value="<?php echo $longdesc; ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('customclass'); ?>"><?php _e('Custom Class:', 'klasik'); ?> <input class="widefat" id="<?php echo $this->get_field_id('customclass'); ?>" name="<?php echo $this->get_field_name('customclass'); ?>" type="text" value="<?php echo $customclass; ?>" /></label></p>
<p>
<?php if($instance['enablepagenum']){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
<input type="checkbox" name="<?php echo $this->get_field_name('enablepagenum'); ?>" id="<?php echo $this->get_field_id('enablepagenum'); ?>" value="true" <?php echo $checked; ?> /> <label for="<?php echo $this->get_field_id('enablepagenum'); ?>"><?php _e('Enable Paging', 'klasik'); ?> </label></p>
<?php
}
protected function get_display_options () {
return array(
'default' => __( 'Default', 'klasik' ),
'filterable' => __( 'Filterable', 'klasik' )
);
} // End get_display_options()
protected function get_number_options () {
return array(
'1' => __( '1 Column', 'klasik' ),
'2' => __( '2 Column', 'klasik' ),
'3' => __( '3 Column', 'klasik' ),
'4' => __( '4 Column', 'klasik' ),
'5' => __( '5 Column', 'klasik' ),
'6' => __( '6 Column', 'klasik' )
);
} // End get_number_options()
} // class Widget
The relevant code, to me, appears to be this:
$tpl = '<div data-id="id-%%ID%%" class="%%CLASS%%" data-type="%%KEY%%">';
$tpl .= '<div class="klasik-pf-img"><div class="shadowBottom">';
$tpl .= '<a class="pfzoom" href="%%FULLIMG%%" %%LBOXREL%% title="%%TITLE%%"><span class="rollover"></span>%%THUMB%%</a>';
$tpl .= '<div class="clear"></div>';
$tpl .= '</div></div>';
$tpl .= '<div class="klasik-pf-text">';
$tpl .='<h3 class="pftitle"><a href="%%LINK%%" title="%%TITLE%%">';
$tpl .='<span>%%TITLE%%</span>';
$tpl .='</a></h3>';
$tpl .='<div class="textcontainer">%%TEXT%%</div>';
$tpl .= '</div>';
$tpl .= '<div class="clear"></div>';
$tpl .= '</div>';
$tpl = apply_filters( 'klasik_pfilter_item_template', $tpl );
My semi-educated guess was this, to wrap the whole thing in an code. No dice.
$tpl = '<div data-id="id-%%ID%%" class="%%CLASS%%" data-type="%%KEY%%">';
$tpl .='<a href="%%LINK%%" title="%%TITLE%%">'; <!-- MOVE THIS UP -->
$tpl .= '<div class="klasik-pf-img"><div class="shadowBottom">';
$tpl .= '<a class="pfzoom" href="%%FULLIMG%%" %%LBOXREL%% title="%%TITLE%%"><span class="rollover"></span>%%THUMB%%</a>';
$tpl .= '<div class="clear"></div>';
$tpl .= '</div></div>';
$tpl .= '<div class="klasik-pf-text">';
$tpl .='<a href="%%LINK%%" title="%%TITLE%%">';
$tpl .='<span>%%TITLE%%</span>';
$tpl .='<div class="textcontainer">%%TEXT%%</div>';
$tpl .= '</div>';
$tpl .='</a>'; <!-- AND MOVE THIS DOWN -->
$tpl .= '<div class="clear"></div>';
$tpl .= '</div>';
$tpl = apply_filters( 'klasik_pfilter_item_template', $tpl );
I at least thought that'd be a good starting point, but nope. Nothing. Am I editing the wrong code?
Help is much appreciated! Thank you.
There are two things you need to do here which I figured out by looking at the javascript console of the demo site (http://demowordpress.templatesquare.com/royalstartex/portfolio/). Note that you won't see the same info if you click on the link that you provided until you click 'Remove Frame' to get rid of the outer frame.
First off $tpl is nothing more than a php variable. It could be called $dingleberry if you want. So $tpl is not a thing that you need to understand. This is just basic PHP.
The link to the page seems to come from %%LINK%%. So put that link in the href for the image, and get rid of the text section. There's probably more you could clean up:
$tpl = '<div data-id="id-%%ID%%" class="%%CLASS%%" data-type="%%KEY%%">';
$tpl .= '<div class="klasik-pf-img"><div class="shadowBottom">';
// Note that I changed the href below
$tpl .= '<a class="pfzoom" href="%%LINK%%" %%LBOXREL%% title="%%TITLE%%"><span class="rollover"></span>%%THUMB%%</a>';
$tpl .= '<div class="clear"></div>';
$tpl .= '</div></div>';
$tpl .= '<div class="clear"></div>';
$tpl .= '</div>';
$tpl = apply_filters( 'klasik_pfilter_item_template', $tpl );
Second is the lightbox. You can first try removing the pfzoom class from the a tag but that might mess up some styling.
$tpl .= '
An easier way to disable the lightbox is to disable the click events that have been bound to the a tag. Add this to your jQuery block somewhere. Or here's a complete jQuery block that you could just use anywhere:
jQuery(function($) {
// disable every handler bound to the .pfzoom class and just do a normal anchor tag click
$('.pfzoom').off();
});

Receiving syntax error "Unexpected }" for a professional WordPress plugin, Sidebar Menu Widget

I'm receiving an "Unexpected }" syntax error for a commercially available WordPress plugin, Sidebar Menu Widget, and I can't seem to find out why such an error is being thrown. The widget consists of the following, with the "Unexpected }" syntax error happening at the closing brace of the function form($instance) within the class sidebar_menu_widget extends WP_Widget:
<? ob_start();
/*
Plugin Name: Sidebar Menu Widget
Plugin URI: http://webloungeinc.com
Description: With this plugin you can display menu in sidebar according to nev menu.
Author: Weblounge inc.
Version: 1.0
Author URI: http://webloungeinc.com
*/
define( 'PLUGINS_PATH', plugin_dir_url(__FILE__) );
wp_register_style( 'style', PLUGINS_PATH . 'style.css' );
wp_enqueue_style ( 'style' );
function _getSidebarMenu($menu_id='',$post)
{
$menuItems = wp_get_nav_menu_items($menu_id);
foreach($menuItems as $menuItem)
{
if($menuItem->object_id == $post->ID && $menuItem->object == $post->post_type)
{
$parentMenuId = $menuItem->menu_item_parent;
$currentMenuId = $menuItem->ID;
}
}
$menuItems = (array) $menuItems;
$_cnt = 0;
foreach($menuItems as $_counter)
{
if($currentMenuId==$_counter->menu_item_parent)
{
$_cnt++;
}
}
foreach($menuItems as $kmi=>$vmi)
{
$vmi = (array) $vmi;
if($currentMenuId <> "")
{
if(in_array($currentMenuId,$vmi))
{
if($currentMenuId == $vmi[ID])
{
if($_cnt <> 0)
{
echo $content = '<li class="m_title">' . $vmi[title] . '</li>';
}
else
{
foreach($menuItems as $sis_menu)
{
// Parent
$sis_menu = (array) $sis_menu;
if($sis_menu[ID] == $parentMenuId)
{
echo $content = '<li class="m_title">' . $sis_menu[title] . '</li>';
}
if($sis_menu[menu_item_parent] == $parentMenuId)
{
$_other_cls = implode(" ",$sis_menu[classes]);
if($sis_menu[ID] == $currentMenuId)
{
$_cur_class = 'current_m_item';
}
else
{
$_cur_class = "";
}
echo $content = '<li>» ' . $sis_menu[title] . '</li>';
}
}
}
}
else
{
$_other_cls = implode(" ",$vmi[classes]);
echo $content = '<li>» ' . $vmi[title] . '</li>';
}
}
}
else
{
if($vmi[menu_item_parent]==0)
{
$_other_cls = implode(" ",$vmi[classes]);
echo $content = '<li>» ' . $vmi[title] . '</li>';
}
}
}
}
/* Custom Product Specials Widget */
class sidebar_menu_widget extends WP_Widget {
function sidebar_menu_widget() {
// widget actual processes
parent::WP_Widget(false, $name = 'Sidebar Menu', array(
'description' => 'Displays a Sidebar Menu'
));
}
function widget($args, $instance) {
global $post;
extract($args);
echo $before_widget;
$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
if ( !empty($instance['title']) )
echo $before_title . $instance['title'] . $after_title;
echo '<ul class="menu ' . $instance['class'] . '">';
_getSidebarMenu($instance['nav_menu'],$post);
echo '</ul>';
echo $after_widget;
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) {
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$class = isset( $instance['class'] ) ? $instance['class'] : '';
$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
// Get menus
$menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
// If no menus exists, direct the user to go and create some.
if ( !$menus ) {
echo '<p>'. sprintf( __('No menus have been created yet. Create some.'), admin_url('nav-menus.php') ) .'</p>';
return;
}
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('class'); ?>"><?php _e('Class:') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('class'); ?>" name="<?php echo $this->get_field_name('class'); ?>" value="<?php echo $class; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
<?php
foreach ( $menus as $menu ) {
$selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
}
?>
</select>
</p>
<?php
----> }
}
add_action('widgets_init', 'register_sidebar_menu_widget');
function register_sidebar_menu_widget() {
register_widget('sidebar_menu_widget');
}
I've indicated the spot of the error with an arrow. After extensive debugging, the only thing that I can think of that could cause such an error is the insertion of HTML in the form() function. However, I thought that ob_start() could allow such an interruption to take place while maintaining the flow of php via buffering the output? Do I need to make some sort of ob_get_contents() call after the HTML to allow such a continuation?
I'm about to rewrite the plugin in order to avoid the interruption, but it bothers me that this is a commercially available plugin that won't work for me straight out of the box. Any help would be greatly appreciated! Thanks.
I'm running PHP 5.5.12 by the way, and this error message is being given to me via XDebug. Please let me know if you need any other information if you're looking to help.

Categories