Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

pedro_dles on "PHP: Add translated tags to category list"

$
0
0

I have a website made from a template in WordPress, I've installed a translation plugin (qtranslate).

http://madebysylvie.be/collection

In my "photo album" page when I sort the items in the default language (english) everything works fine, however if I change to another translation (ex.french), the name of the category changes and the tagged items don't appear anymore.

Here is the PHP code that executes that function,

<ul class="filter_portfolio"> 

                <?php
                    // Get the taxonomy

                    $terms = get_terms('filter', $args);
                    // set a count to the amount of categories in our taxonomy
                    $count = count($terms);
                    // set a count value to 0
                    $i=0;
                    // test if the count has any categories
                    if ($count > 0) {
                        // break each of the categories into individual elements
                        foreach ($terms as $term) {
                            // increase the count by 1
                            $i++;

                            // rewrite the output for each category

                            $term_list .= '<li class="segment-'.$i.'"><a href="javascript:void(0)" data-value="' . $term->slug . '">' . $term->name . '</a></li>';

                            // if count is equal to i then output blank
                            if ($count != $i)
                            {
                                $term_list .= '';
                            }
                            else
                            {
                                $term_list .= '';
                            }
                        }
                        // print out each of the categories in our new format
                        echo $term_list;

                    }
                ?>

            </ul>

would like to change this block of code in order to identify the tags in the translated version. I know that the trigger is the ("data-value") parameter.

The following code let's me translate the taxonomies from the default language,

function qtranslate_edit_taxonomies(){
$args=array(
  'public' => true ,
  '_builtin' => false
);
$output = 'object'; // or objects
$operator = 'and'; // 'and' or 'or'

$taxonomies = get_taxonomies($args,$output,$operator); 

if  ($taxonomies) {
 foreach ($taxonomies  as $taxonomy ) {
     add_action( $taxonomy->name.'_add_form', 'qtrans_modifyTermFormFor');
     add_action( $taxonomy->name.'_edit_form', 'qtrans_modifyTermFormFor');        

 }
 }

}
add_action('admin_init', 'qtranslate_edit_taxonomies');
?>

Thank for helping.


Senyaj on "rows of data with each post"

$
0
0

Hello,

Is is possible to have multiple rows of meta data with each post? e.g

- LOOK THIS IS THE MAIN POST
---- id(1) | file_name(file.zip) | name(blah)
---- id(2) | file_name(faasd.zip) | name(blah)
---- id(3) | file_name(123123.zip) | name(blah)
---- id(4) | file_name(234234.zip) | name(blah)

Hope this makes sense.

halben on "Preg_match not returning error?"

$
0
0

I was wondering if I could use preg_match in wordpress. I'm trying to validate a phone number and here is what I have:

if (preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $sanitized_phone))
			$errors[] = 'Error: Please enter a valid phone number. (e.g. 999-999-9999)';

I tested it and there's not error output. Anyone know why?

madphill on "Query posts with attachments by category"

$
0
0

I'm attempting to pull media from posts by category and the media is showing up, it's just not by category. It's currently ALL media regardless of whether or not it's attached to a post. I'm having trouble figuring out what to do.

<div class="row-fluid">
<?php
global $post;
$args = array(
'post_category' => 'trees',
'post_type' => 'attachment',
'numberposts' => 8,
'orderby' => 'random',
'post_status' => null,
'post_parent' => null, // any parent
);
$attachments = get_posts($args);
foreach ($attachments as $post) : setup_postdata($post); ?>
<div class="span3">

downFast on "Find post id by a tag"

$
0
0

How can I find the post id by reading its tag?

alex05 on "WordPress Gallery Upload Limit"

$
0
0

I'm trying to limit the amount of files a user can upload through the wp gallery, and i've found the following filter

add_filter('wp_handle_upload_prefilter', 'yoursite_wp_handle_upload_prefilter');
function yoursite_wp_handle_upload_prefilter($file) {
  list($category,$type) = explode('/',$file['type']);
  if ('image'!=$category || !in_array($type,array('jpg','jpeg','gif','png'))) {
    $file['error'] = "Sorry, you can only upload a .GIF, a .JPG, or a .PNG image file.";
  } else if ($post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : false)) {
    if (count(get_posts("post_type=attachment&post_parent={$post_id}"))>0)
      $file['error'] = "Sorry, you cannot upload more than one (1) image.";
  }
  return $file;
}

However this filter works only on the current post, what i'm trying to achieve is to limit the upload only on that instance when the user opens the uploader, is it possible?

bignides on "RSS calendar feed sorted wrong"

$
0
0

The site I'm working on has a customized plugin that is supposed to pull Helios calendar events from an RSS feed and display them in order of nearest event first. For some reason, it is always sorted furthest start date first. This is true whether the RSS feed data is sorted in ASC or DESC order. I don't event see any code for sorting at all so I don't know why it's not just displaying exactly what's in the feed. This has been messing with me for days so any help would be greatly appreciated. Thanks.

/**
 * Display the RSS entries in a list.
 *
 * @since 2.5.0
 *
 * @param string|array|object $rss RSS url.
 * @param array $args Widget arguments.
 */
function jfmc_wp_widget_rss_output( $rss, $args = array() ) {
	if ( is_string( $rss ) ) {
		$rss = fetch_feed($rss);
	} elseif ( is_array($rss) && isset($rss['url']) ) {
		$args = $rss;
		$rss = fetch_feed($rss['url']);
	} elseif ( !is_object($rss) ) {
		return;
	}

	if ( is_wp_error($rss) ) {
		if ( is_admin() || current_user_can('manage_options') )
			echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
		return;
	}

	$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
	$args = wp_parse_args( $args, $default_args );
	extract( $args, EXTR_SKIP );

	$items = (int) $items;
	if ( $items < 1 || 20 < $items )
		$items = 10;
	$show_summary  = (int) $show_summary;
	$show_author   = (int) $show_author;
	$show_date     = (int) $show_date;

	if ( !$rss->get_item_quantity() ) {
		echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
		$rss->__destruct();
		unset($rss);
		return;
	}

	echo '<ul>';
	foreach ( $rss->get_items(0, $items) as $item ) {
		$link = $item->get_link();
		while ( stristr($link, 'http') != $link )
			$link = substr($link, 1);
		$link = esc_url(strip_tags($link));
		$title = esc_attr(strip_tags($item->get_title()));
		if ( empty($title) )
			$title = __('Untitled');

		$desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
		$desc = wp_html_excerpt( $desc, 60 );

		// Append ellipsis. Change existing [...] to [&hellip;].
		if ( '...' == substr( $desc, -5 ) )
			$desc = substr( $desc, 0, -5 ) . '&hellip;';
		elseif ( '&hellip;' != substr( $desc, -10 ) )
			$desc .= ' &hellip;';

		$desc = esc_html( $desc );

		if ( $show_summary ) {
			$summary = "<div class='rssSummary'>$desc</div>";
		} else {
			$summary = '';
		}

		$date = '';
		if ( $show_date ) {
			$date = $item->get_date( 'U' );

			if ( $date ) {
				$date = ' <div class="rss-date ewidget-time"><span class="ewidget-date">' . date_i18n( 'd', $date ) . '</span><br /><div class="ewidget-mon">' . date_i18n('M', $date ) . '</div></div>';
			}
		}

		$author = '';
		if ( $show_author ) {
			$author = $item->get_author();
			if ( is_object($author) ) {
				$author = $author->get_name();
				$author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
			}
		}

		if ( $link == '' ) {
			echo "<li>$title{$date}{$summary}{$author}</li>";
		} else {
			echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
		}
	}
	echo '</ul>';
	$rss->__destruct();
	unset($rss);
}
/**
 * Process RSS feed widget data and optionally retrieve feed items.
 *
 * The feed widget can not have more than 20 items or it will reset back to the
 * default, which is 10.
 *
 * The resulting array has the feed title, feed url, feed link (from channel),
 * feed items, error (if any), and whether to show summary, author, and date.
 * All respectively in the order of the array elements.
 *
 * @since 2.5.0
 *
 * @param array $widget_rss RSS widget feed data. Expects unescaped data.
 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
 * @return array
 */
function jfmc_wp_widget_rss_process( $widget_rss, $check_feed = true ) {
	$items = (int) $widget_rss['items'];
	if ( $items < 1 || 20 < $items )
		$items = 10;
	$url           = esc_url_raw(strip_tags( $widget_rss['url'] ));
	$title         = trim(strip_tags( $widget_rss['title'] ));
	$show_summary  = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0;
	$show_author   = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] :0;
	$show_date     = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0;

	if ( $check_feed ) {
		$rss = fetch_feed($url);
		$error = false;
		$link = '';
		if ( is_wp_error($rss) ) {
			$error = $rss->get_error_message();
		} else {
			$link = esc_url(strip_tags($rss->get_permalink()));
			while ( stristr($link, 'http') != $link )
				$link = substr($link, 1);

			$rss->__destruct();
			unset($rss);
		}
	}

	return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
}

Ivan D. on "Preview and post meta (custom fields) solution !"

$
0
0

Hi !
After an half day of research, we found a solution for preview with post meta (custom fields).

The problem :
If you change a post meta value but not the title, the content or other native fields, the post (or page) doesn’t change for WP…
And when you press the preview button, if there is an autosave, WP delete it because the autosave and the saved post (or page) are the same (title, content,… haven’t change).

I don’t know why WP do that like that but we have the solution (put this code on your function.php file):

/*
   Debug preview with custom fields
*/ 

add_filter('_wp_post_revision_fields', 'add_field_debug_preview');
function add_field_debug_preview($fields){
   $fields["debug_preview"] = "debug_preview";
   return $fields;
}

add_action( 'edit_form_after_title', 'add_input_debug_preview' );
function add_input_debug_preview() {
   echo '<input type="hidden" name="debug_preview" value="debug_preview">';
}

The first hook add a field to check for revisions (debug_preview).
And the second add an hidden field (debug_preview) on edit pages with a value (‘debug_preview’ but any value works).

When WP check for revision, the field ‘debug_preview’ doesn’t exist in database but exist with a value in the edit page, so it’s different and WP make the autosave.

Say “hello back” to preview in WP with post meta :)

I hope this code can help you !

If a WP dev see that, please update the core to autosave each time the preview button is press ;)

Have a nice day !


f1ss1on on "Display only 1 random post from the most recent 20"

$
0
0

Hello, I am trying to display only 1 random post from the most recent 20 posts. Currently, this is the code I have. The issue is, only the latest post is displaying since showposts =>1.

$post_id = get_the_ID();
    $args = array(
      'orderby' => 'post_date',
      'orderby' => 'rand',
      'showposts'=>1,
      'post__not_in' => array($post_id),
      'meta_query' => array(array('key' => '_thumbnail_id'))
    );

    $rand_query = new WP_Query($args);

    while ($rand_query->have_posts()) : $rand_query->the_post();

mstrdh on "[WooCommerce 1.6.5.2] Add custom fee in Shopping Cart"

$
0
0

Hi! I had a difficult task, so I need your help, guys.
I need some fixes in shopping cart.
1. If a customer buys less product that costs less than 1000kr, then 200kr needs to be added to the price. The 200kr should be added as a new product in the checkout. So.. if you buy one product, the checkout should be:
U-stång: 168kr,
Starting cost: 200kr,
Pic 1
Pic 2
http://metalldirekt.se/produkt/u-stang-3/
Best regards!

Tibet I Tech on "WP register form"

$
0
0

Can anyone help me to extract the wp register form? My site is http://dev.bangchen.net On the top right, you can see two ugly links to register and signin/login, when you click on the login, you will see a popup which displays the wp login form, but i am having trouble generating the wp registration form.

I used <?php wp_login_form(); ?> to call the login form but couldn't find the correct php to call the registration form.

Can anyone help?

Pat Friedl on "ThickBox TB_iframe ignores height parameter."

$
0
0

Ok, here's some of the link code I have to launch a ThickBox modal in the page editor window to allow a user to select shortcodes:

<a href="' . FPC_PLUGIN_URL . '/util/plugin-shortcodes.php?height=400&width=600&TB_iframe=true" class="thickbox">[shortcodes]</a>

My problem is that ThickBox completely ignores the height parameter, and I have no way to enforce the height. Is there any way of doing this? It seems like other plugins are using active calls to open ThickBox as opposed to relying on a link with the thickbox class ad that works.

Any help would be greatly appreciated!

twitterdrip on "How to stop httrack and more"

$
0
0

Hello i was wondering how would i include this code

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} almaden RewriteRule ^.* - [F,L]

in wordpress htacess file that contains

# BEGIN WordPress

# END WordPress

# BEGIN wtwp_cache
# END wtwp_cache

# BEGIN wtwp_security
# END wtwp_security

so i can prevent people from scraping me

christof15 on "Core Links - auto selection target blank"

$
0
0

Hi there,

Does anyone know how to make wordpress have an auto selection on target_blank when adding a link through the core link manager. (I use Link Library for adding a link library to a page.)

Thanks a lot!

Sebastian on "Error reporting API?"

$
0
0

In my plugin, I want to notify the admin of wrong settings or problems. So for example, if the admin submits the settings form, I check the input and want to inform him about values being wrong. However, it seems I have to come up with some custom code to keep track of the error message while processing the form.

This is a bit surprising, because e.g. in Drupal you have a simple
set_message() function allowing to set a message, which is shown in a certain div on the page.

Am I just missing something or does something simple really not exist in WordPress?


davehprohoods on "Having trouble creating multi-site plugin for use with sub-sites"

$
0
0

I am trying to create a plugin where when I go to My Sites > Network Sites, there is a "Network Options" in Settings, and then when I go to a sub-site, there is a "Site Options" in Settings. Also I only want admins to see these options.

I tried add_action('admin_menu', 'options_admin_actions'); but it does nothing (it worked on our 3.5 installation but not on our 3.5.1 installation). I'm not sure if the complicated documentation I'm reading is accurate as they're all a little different and I'm unfamiliar with most of the functions there.

Can someone point me in the right direction on this?

stecmedia on "Using script value in shortcode"

$
0
0

Hi
I am currently working on a site for a client, which needs a price generator. The pricing generator is javascript, and works like this:
Test version
(View the code by using your browser's source text function)

I would now like to take the chosen values and the result and add to the shortcode for my shop-plugin, which looks like this:

[wp_cart_button name="VALUE 1 to VALUE 2" price="RESULT"]

This is where the shop is located, if you would like to view that as well.

The plugin is WP Simple Paypal Shopping cart v3.8.5

I hope this is the right forum, and thanks in advance. Just ask if you need more information, I'm here to get help ;)

GrumpyBum84 on "Simple Menu"

$
0
0

Hi All,

I have been working with PHP for some time now and thought I would give WordPress a shot, but I am getting lost on some basic functionality and I have been pulling my hair out trying to understand what I am doing so wrong.

All I am after is a simple menu item for settings and despite all my research I cannot do it :(
My code is as follows,

add_action('admin_menu', 'testPluginMenu');

function testPluginMenu() {
	add_options_page('Testing Plugin', 'Testing 3 Plugin', 'administrator', 'test-plugin', 'pluginAdminMenu');
}

function pluginAdminMenu() {
	echo '<h1>Test Plugin Admin Menu</h1>';
	echo '<p>This is a test</p>';
}

Code I copied off the WordPress Codex Site, http://codex.wordpress.org/Adding_Administration_Menus

/** Step 2 (from text above). */
add_action( 'admin_menu', 'my_plugin_menu' );

/** Step 1. */
function my_plugin_menu() {
	add_options_page( 'My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options' );
}

/** Step 3. */
function my_plugin_options() {
	if ( !current_user_can( 'manage_options' ) )  {
		wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
	}
	echo '<div class="wrap">';
	echo '<p>Here is where the form would go if I actually had options.</p>';
	echo '</div>';
}

The problem is, the code from codex works and mine does not.
I am pulling my hair out trying to find out what makes then different but the more I go over these the more they look to be the same patteren and code set :(

Can anyone please point this out to me? Yes, I want you to point out my noob mistake as I am going crazy just trying to sort this basic function.

Thanks all

malibur on "How do I filter the Wordpress loop with a permalink variable"

$
0
0

Hi, I have been looking around for a solution, but have a hard time even knowing what to google to find answers.

What i want:

I have a wordpress template that lists all the content of a custom post type called albums

all these albums have a field that contains their release date.

now i'd like a selectbox on that same template to make the loop only show the albums released in the selected year. i.e all albums from 2012.

Is there a way to extend the permalink site.com/albums, to site.com/albums/2012, and make that filter the loop to only show the albums with that release date?

my custom field is called release-date.

in other words can i get that permalink /year become a variable that i can use in the template? or is there a better approach to get that same result?

If anyone can point me to articles or tutorials about this, or even suggest an approach, that would be very helpful.

Thank you so much!

patrickvibes on "Walkner Nav for Gumby CCSS menu?"

$
0
0

I'm struggling to find where to place the closing Div on dropdowns for the Gumby CSS menu - I've tried modifying the bootrap Walker Nav, I just cant see where there statement would be to close the loop through child items.

Line 24 is where I've added in my statement for

<?php

/**
 * Class Name: wp_bootstrap_navwalker
 * GitHub URI: https://github.com/twittem/wp-bootstrap-navwalker
 * Description: A custom WordPress nav walker class to implement the Twitter Bootstrap 2.3.2 navigation style in a custom theme using the WordPress built in menu manager.
 * Version: 1.4.3
 * Author: Edward McIntyre - @twittem
 * License: GPL-2.0+
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 */

class wp_bootstrap_navwalker extends Walker_Nav_Menu {

	/**
	 * @see Walker::start_lvl()
	 * @since 3.0.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int $depth Depth of page. Used for padding.
	 */
	function start_lvl( &$output, $depth = 0, $args = array() ) {
		$indent = str_repeat( "\t", $depth );
		$output	   .= "\n$indent<div class=\"dropdown\"><ul>\n";
	}

	/**
	 * @see Walker::start_el()
	 * @since 3.0.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param object $item Menu item data object.
	 * @param int $depth Depth of menu item. Used for padding.
	 * @param int $current_page Menu item ID.
	 * @param object $args
	 */

	function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
		global $wp_query;
		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

		/**
		 * Dividers & Headers
	     * ==================
		 * Determine whether the item is a Divider, Header, or regular menu item.
		 * To prevent errors we use the strcasecmp() function to so a comparison
		 * that is not case sensitive. The strcasecmp() function returns a 0 if
		 * the strings are equal.
		 */
		if (strcasecmp($item->title, 'divider') == 0) {
			// Item is a Divider
			$output .= $indent . '<li class="divider">';
		} else if (strcasecmp($item->title, 'divider-vertical') == 0) {
			// Item is a Vertical Divider
			$output .= $indent . '<li class="divider-vertical">';
		} else if (strcasecmp($item->title, 'nav-header') == 0) {
			// Item is a Header
			$output .= $indent . '<li class="nav-header">' . esc_attr( $item->attr_title );
		} else {

			$class_names = $value = '';
			$classes = empty( $item->classes ) ? array() : (array) $item->classes;
			$classes[] = ($item->current) ? 'active' : '';
			$classes[] = 'menu-item-' . $item->ID;
			$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );

			if ($args->has_children && $depth > 0) {
				$class_names .= ' dropdown-submenu';
			} else if($args->has_children && $depth === 0) {
				$class_names .= ' dropdown';
			}

			$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';

			$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
			$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';

			$output .= $indent . '<li' . $id . $value . $class_names .'>';

			$attributes = ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
			$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
			$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
			$attributes .= ($args->has_children) 	    ? ' data-toggle="dropdown" data-target="#" class="dropdown-toggle"' : '';

			$item_output = $args->before;

			/**
			 * Glyphicons
			 * ===========
			 * Since the the menu item is NOT a Divider or Header we check the see
			 * if there is a value in the attr_title property. If the attr_title
			 * property is NOT null we apply it as the class name for the glyphicon.
			 */
			if(! empty( $item->attr_title )){
				$item_output .= '<a'. $attributes .'><i class="' . esc_attr( $item->attr_title ) . '"></i>&nbsp;';
			} else {
				$item_output .= '<a'. $attributes .'>';
			}

			$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
			$item_output .= ($args->has_children && $depth == 0) ? ' <span class="caret"></span></a>' : '</a>';
			$item_output .= $args->after;

			$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
		}
	}

	/**
	 * Traverse elements to create list from elements.
	 *
	 * Display one element if the element doesn't have any children otherwise,
	 * display the element and its children. Will only traverse up to the max
	 * depth and no ignore elements under that depth.
	 *
	 * This method shouldn't be called directly, use the walk() method instead.
	 *
	 * @see Walker::start_el()
	 * @since 2.5.0
	 *
	 * @param object $element Data object
	 * @param array $children_elements List of elements to continue traversing.
	 * @param int $max_depth Max depth to traverse.
	 * @param int $depth Depth of current element.
	 * @param array $args
	 * @param string $output Passed by reference. Used to append additional content.
	 * @return null Null on failure with no changes to parameters.
	 */

	function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
        if ( !$element ) {
            return;
        }

        $id_field = $this->db_fields['id'];

        //display this element
        if ( is_object( $args[0] ) ) {
           $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
        }

        parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
    }
}

?>
Viewing all 8245 articles
Browse latest View live




Latest Images