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

Franky57 on "How to override wp_list_pages and wp_list_bookmarks without modify core code ?"

$
0
0

Hi all !

I am finding a way to override some core functions of WordPress (wp_list_pages and wp_list_bookmarks) within my function.php theme file because I am so tired to always modify core code when I update WordPress.

In the way to make easier my css styling, I proceed of this changes in post-template.php and bookmark-template.php core file.

In one hand, I added in the $default array of the post-template.php wp_list_pages function the following parameters:

'before' => '', 'after' => ''

in the way to modify the Walker_Page start_el method at line 1062 from:

$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';

to:

$output .= $indent . '<li class="' . $css_class . '">' . $before . '<a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>' . $after;

(as we can see these parameters in the wp_list_bookmarks function)

In the other hand, I added in the $default array of the bookmark-template.php _walk_bookmarks and wp_list_bookmarks functions the following parameter:

'relativepath' => 0

in the way to modify the part of code at line 102 in _walk_bookmarks function from:

if ( $bookmark->link_image != null && $show_images ) {
	if ( strpos($bookmark->link_image, 'http') === 0 )
		$output .= "<img src=\"$bookmark->link_image\" $alt $title />";
	else // If it's a relative path
		$output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";

	if ( $show_name )
		$output .= " $name";
	} else {
		$output .= $name;
}

to:

if ( $bookmark->link_image != null && $show_images ) {
	if ( $relativepath == 0 ) {
		if ( strpos($bookmark->link_image, 'http') === 0 )
			$output .= "<img src=\"$bookmark->link_image\" $alt $title />";
		else // If it's a relative path
			$output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
	} else {
		$output .= "<img src=\"" . wp_make_link_relative($bookmark->link_image) . "\" $alt $title />";
	}

	if ( $show_name )
		$output .= " $name";
} else {
	$output .= $name;
}

(I need to have relative path for the src attribute of my img tag and I don't find on other way even with hooks and filters)

I know it's dangerous to modify core code but I don't find on internet the way to obtain what I needed without hacking WordPress core files.

Is anybody have an idea to get around my hacking code ?

Thanks


paulcoppock on "How to hide div if featured image caption does not exist?"

$
0
0

I'm using this function to display the caption for featured image:

function the_post_thumbnail_caption() {
 global $post;

 $thumbnail_id    = get_post_thumbnail_id($post->ID);
 $thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));

  if ($thumbnail_image && isset($thumbnail_image[0])) {
   return '<div class="front-caption">'.$thumbnail_image[0]->post_excerpt.'</div>';
  } else {
    return;
  }
}

and I'm using:
the_post_thumbnail_caption();
in the template page to display the caption. I've style the div class "front-caption" with borders. If the caption does not exist it still displays the empty but styled div with borders.

Anyone know how to hide the div if no caption exist?

Thank you in advance.

DragonDon on "adding a simple search to a setion"

$
0
0

Greetings all,

I've been trying to setup a search form and it is driving me nuts. Here's the setup.

WP 3.6
Simplethemes.com Element Theme (http://www.simplethemes.com/wordpress-themes/demo/element)
I am using their 'teaser' as the top of the page (a kind of pseudo header section if you will) and in it I want to put the company logo and a search section. Logo on left, search on right.

I got the logo there but for the life of my, I can get a search section to properly position at all. Kinda at the limit of my CSS knowledge, which is admittedly not all that extensive but I can follow along well enough.

I am using inline CSS coding (yes, yes, I know about not doing that being a general consensus but for now this is how it is).

This theme allows me to put widgets in the 'teaser' section but if I put in a image and a search widget, they stack vertically.

Here is the test site: http://investresource.test-lca-website.com/

Suggestions welcome. ALthough, things may change by the time you see this as I need to get this fixed asap.

Thanks in advance!

Ralac on "WP media show toolbar with selected images"

$
0
0

How can i show the toolbar with the selected images as seen on the image above on a custom media frame:

http://i44.tinypic.com/23k8ars.png

custom_uploader = wp.media.frames.file_frame = wp.media({
				title: 'Choose Image',
				button: {
					text: 'Choose Selection'
				},
				multiple: true,
			});

Thanks!

dokgu on "Download-Monitor auto inserts code"

$
0
0

I've installed the latest download-monitor plugin and I wanted to modify the way it displays the download link.

So what I did was to put this in the editor:

<span class="file-details">
    <h5>File Details</h5>
    <ul id="fileDetails">
        <li>
            <span class="fileType">File Type</span>
            <strong><?php print(strtoupper($dlm_download->get_the_filetype())); ?></strong>
        </li>
        <li>
            <span class="fileDownloads">Downloads</span>
            <strong><?php printf( _n( '1', '%d', $dlm_download->get_the_download_count(), 'download_monitor' ), $dlm_download->get_the_download_count() ) ?></strong>
        </li>
        <li>
            <span class="fileSize">File Size</span>
            <strong><?php print($dlm_download->get_the_filesize()); ?></strong>
        </li>
    </ul>
    <a class="download-link" title="<?php if ( $dlm_download->has_version_number() ) printf( __( 'Version %s', 'download_monitor' ), $dlm_download->get_the_version_number() ); ?>" href="<?php $dlm_download->the_download_link(); ?>" rel="nofollow">
        <strong>Download</strong>
    </a>
</span>

But when I look at the rendered page, the source says that the <span class="file-details"> is contained in a p tag and it only contains a br tag.

My intended content for the span is now located outside of the span. Please help me with this, I'm very new to WordPress modifications but I can code.

Basically, the structure that I wanted to have is like this: http://imageshack.us/a/img812/3978/1c7x.png

But the structure that is rendered is like this: http://imageshack.us/a/img541/7277/d2a.png

You can view my problem at: http://dokgu.com/social-mediacons/

halfhuman on "Insert new input field"

$
0
0

How do I add new input field on this code?

public function form( $instance )
    {
        $user_id = isset ( $instance['user_id'] ) ? $instance['user_id'] : array();
		$user_id_num = count( $user_id );
		$user_id[ $user_id_num + 1 ] = '';
		$user_html = array();
		$user_id_counter = 0;

		foreach (array_values($user_id) as $name => $value)
		{
			$user_html[] = sprintf(
				'User ID<br/><input type="text" name="%1$s[%2$s]" value="%3$s" class="widefat">',
				$this->get_field_name( 'user_id' ),
				$user_id_counter,
				esc_attr( $value )
			);
			$user_id_counter += 1;
		}

        print 'New User' . join( '<br /><br />', $user_html );
    }

Basically I wanted to add new input field Location right next to the User ID field and then change the foreach so it also get the new user_location. How to I rewrite the code to achieve what I wanted?

navyspitfire on "Target only pages in the same category"

$
0
0

I've been scrapping together pieces of code, but with this code I am trying to have it so it only targets pages in the same category. Ideas?

<div class="port-nav left">
        <?php
            /**
             *  Infinite next and previous post looping in WordPress
             */
            if( get_adjacent_post(false, '', true) ) {
        ?>
                <p class="prev"><?php previous_post_link('%link'); ?></p>
        <?php
            } else {
                $first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post();
                    echo '<a href="' . get_permalink() . '">&larr; Previous Post</a>';
                wp_reset_query();
            };
        ?>
        <?php
            if( get_adjacent_post(false, '', false) ) {
        ?>
                <p class="next"><?php next_post_link('%link'); ?>
        <?php
            } else {
                $last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post();
                    echo '<a href="' . get_permalink() . '">Next Post &rarr;</a>';
                wp_reset_query();
            };
        ?>
    </div>

anamaher on "Scheduled posts view on public"

$
0
0

hello,
i would like to ask about how to code Scheduled posts on a widget
i know how to make the widget available but what is the code for viewing the Scheduled posts on public as a category or page template or widget
Thank you


jason w on "Link htpasswd with Wordpress user logins"

$
0
0

Hi,

I have set up a wordpress website that has htpasswd protecting it when anyone accesses the site, all users login with a default password currently. Then once logged in the user can login to wordpress via a login plugin with there own username and password (so they can commment on posts).

I want to link the htpasswd to the wordpress logins so users only have to login once, how can this be done?

Thanks

caioxavier on "Help with category page"

$
0
0

Hey guys, I'm new to WP and PHP so I can't really rely on my hardcoding skills to get what I want, so I need your help. It should be simple:

I have category pages and child categories in some of them. I want to display in the category page, links to the current parents and child categories, so the user can filter the posts.

Imagine we are broswing Category 1, with has 2 child categories. All I want is to display:

Category Title

[All] - [Child 1] - [Child 2]

[the loop]

Only the content and category title would be displayed if there are no child categories.

I'm aware I could do this by making specific page templates, but I want to keep everything lean and dynamic, so my client can change the categories as he pleases.

Thank you guys in advance!

DrHell on "Dynamic Dropdown lists for Categories, Sub-Categories, Posts!"

$
0
0

Greetings people!

I'm using WordPress 3.5 as CMS to develop my personal website.

The reason I'm writting, is that I need a way to implement a code or plugin to allow users to navigate through posts using dependent(chained) dropdown lists.

In other words I would like 3 dropdown menus to be dynamically populated based on the selection chosen in the previous dropdown lists.

This would consist of:

Dropdown 1: Category *
Dropdown 2: Sub- Category *
Dropdown 3: List of posts in Sub-Category *

*Dropdown 1 would be pre populated with categories.
*Dropdown 2 would list the sub categories of menu 1 based on the user selection.
*Dropdown 3 would list the posts in the sub category chosen in menu 2.

To help you understand further, in my website I have the Category "TV Series" which has as sub-categories(child) other series, like "Dexter", "CSI:Miami" etc.
Series also have other sub-categories(child) the number of seasons, like "Season 1" "Season 2" "Season N". Each season contains the appropriate posts.

The Hierarchy is like this:

Tv Series

-Dexter
--Season 1
--Season 2
--Season n

-CSI:Miami
--Season 1
--Season 2
--Season n

So for example the dynamic dropdowns I would like to use are the following:

Dropdown 1: Select TV Show (Category)
Dropdown 2: Select Season (sub-category)
Dropdown 3: Select Episode (posts)

I would really appreciate if you could help me with the matter as I was searching the web for the past few days without any results.

Thanks in advance.

dubzzdigital on "Adding a Pinterest button with php code?"

$
0
0

Hi everyone,

I am wanting to add a Pinterest button into the purple slogan bar of our homepage at Cottage Flair.

Any ideas where/how I would fit it into this:

/****************************************************************************************/

if ( ! function_exists( 'attitude_home_slogan' ) ) :
/**
* Display Home Slogan.
*
* Function that enable/disable the home slogan1 and home slogan2.
*/
function attitude_home_slogan() {
global $attitude_theme_options_settings;
$options = $attitude_theme_options_settings;

$attitude_home_slogan = '';
if( ( !$attitude_home_slogan = get_transient( 'attitude_home_slogan' ) ) && ( !empty( $options[ 'home_slogan1' ] ) || !empty( $options[ 'home_slogan2' ] ) ) ) {

if ( "0" == $options[ 'disable_slogan' ] ) {
$attitude_home_slogan .= '<section class="slogan-wrap clearfix"><div class="container"><div class="slogan">';
if ( !empty( $options[ 'home_slogan1' ] ) ) {
$attitude_home_slogan .= esc_html( $options[ 'home_slogan1' ] );
}
if ( !empty( $options[ 'home_slogan2' ] ) ) {
$attitude_home_slogan .= '<span>'.esc_html( $options[ 'home_slogan2' ] ).'</span>';
}
$attitude_home_slogan .= '</div><!-- .slogan -->';
if ( !empty( $options[ 'button_text' ] ) && !empty( $options[ 'redirect_button_link' ] ) ) {
$attitude_home_slogan .= ''.esc_html( $options[ 'button_text' ] ).'<!-- .view-work -->';
}
$attitude_home_slogan .= 'Newsletter<!-- .view-work -->';
$attitude_home_slogan .= '</div><!-- .container --></section> <!-- .slogan-wrap -->';
}

set_transient( 'attitude_home_slogan', $attitude_home_slogan, 86940 );
}
echo $attitude_home_slogan;
}
endif;

/****************************************************************************************/

Thank you muchly for any suggestions! Cheers!

Pyrate.Ned on "Author dropdown with link to author page functionality like wp_get_archives"

$
0
0

Well I looked for a while for a dropdown of authors with the same functionality as wp_get_archives. Which makes a dropdown with a javascipt onchange which brings your to the archive you pick. After searching and reading around on google for an hour or so and looking at a few plugins. I realized I couldn't find what I was looking for so I was going to have to make the code or hack up some code. So here is what I did, I started with the functionality of wp_dropdown_users() and more then less just hacked it up to do what wp_get_archive dropdown_box does. Just copy this function into your themes functions.php

function wp_get_author( $args = '' ) {
	$authorURL = "YOUR-WORDPRESS-URL?author=";
	$defaults = array(
		'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
		'orderby' => 'display_name', 'order' => 'ASC',
		'include' => '', 'exclude' => '', 'multi' => 0,
		'show' => 'display_name', 'echo' => 1,
		'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',
		'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false
	);

	$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	$query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
	$query_args['fields'] = array( 'ID', 'user_login', $show );
	$users = get_users( $query_args );

	$output = '';
	if ( !empty($users) && ( empty($hide_if_only_one_author) || count($users) > 1 ) ) {
		$name = esc_attr( $name );
		if ( $multi && ! $id )
			$id = '';
		else
			$id = $id ? " id='" . esc_attr( $id ) . "'" : " id='$name'";

		$output = "<select name='{$name}'{$id} class='$class' onchange='document.location.href=this.options[this.selectedIndex].value;'>\n";
		if ( $show_option_all )
			$output .= "\t<option value='0'>$show_option_all</option>\n";

		if ( $show_option_none ) {
			$_selected = selected( -1, $selected, false );
			$output .= "\t<option value='-1'$_selected>$show_option_none</option>\n";
		}

		$found_selected = false;
		foreach ( (array) $users as $user ) {
			$user->ID = (int) $user->ID;
			$_selected = selected( $user->ID, $selected, false );
			if ( $_selected )
				$found_selected = true;
			$display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')';
			$output .= "<option value=\"\"></option>";
			$output .= "\t<option value='$authorURL$user->ID'$_selected>" . esc_html($display) . "</option>\n";
		}

		if ( $include_selected && ! $found_selected && ( $selected > 0 ) ) {
			$user = get_userdata( $selected );
			$_selected = selected( $user->ID, $selected, false );
			$display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')';
			$output .= "\t<option value='$authorURL$user->ID'$_selected>" . esc_html($display) . "</option>\n";
		}

		$output .= "</select>";
	}

	$output = apply_filters('wp_get_author', $output);

	if ( $echo )
		echo $output;

	return $output;
}

You need to edit this line and near the begging of the code.
$authorURL = "YOUR-WORDPRESS-URL?author=";

and you can also edit or remove this line
$output .= "<option value=\"\"></option>";
if you want the default option to be something like Pick an Author you would would change that link of code to be
$output .= "<option value=\"\">Pick an Author</option>";
or if you wanted it to just like the first author then you can just remove that link altogether.

Then in your template just add
wp_get_author(array('name' => 'author'));

I hope this code will help some people who are looking for a author dropdown list with links to the authors pages with a list of there posts. Please leave a comment if this code helped you =)

cubryto on "Filter content with preg_replace"

$
0
0

Hi,
I have the content with the following format

1) This is question 1?
Answer: Answer for question 1

2) This is question 2?
Answer: Answer for question 2
...

I would like to use prey_replace to replace the answer after the word "Answer:". So it will look like this

1) This is question 1?
Answer: Some strings

2) This is question 2?
Answer: Some strings
...

I am not familiar with regular expression. I've trying but cannot get what I want. I hope someone can help me on this one. Thank you.

Dan Rossiter on "Please change the plugin submission form "Plugin Name" field to "Plugin Slug""

$
0
0

I was submitting a plugin earlier this evening and couldn't for the life of me figure out why the form kept complaining that my requested "Plugin Name" was taken.

The issue was that when I included the name, it was sanitized to a slug which did in fact conflict with another slug. It was also not what I was wanting my slug to be. Once I realized what this issue was, I just entered the slug I wanted and everything worked.

If it's not possible to change the field title, could we at least have a small description that clarifies what is being checked for uniqueness? This would have saved me a couple of minutes and I'm sure I'm not the only one.

Thanks!
-Dan


zitanix on "How To Retrieve An Image Attachment's Alt Text?"

$
0
0

hello

How To Retrieve Thumbnail Image Attachment's Alt Text?

in version 3.4.2 i used this code :

<?php
$thumb_id = get_post_thumbnail_id($post->id);
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
if(count($alt)) echo $alt;
?>

but after update to version 3.5 this code not working any more :(

Dorito22 on "Created functions.php - Now header image appears in title area"

$
0
0

Hello,

Working with the 2010 Theme, I wanted to make my entire site wider (990px). I did that, but the header and menu bar needed to be updated. Eventually I found a post about creating a functions.php file for my child theme (I did not previously have one). So I did that and used code I found in a different thread:

<?php
	define('HEADER_TEXTCOLOR', 'ffffff');
	define('HEADER_IMAGE', get_bloginfo('stylesheet_directory') . '/images/header-default.jpg');
	define('HEADER_IMAGE_WIDTH', 940);
	define('HEADER_IMAGE_HEIGHT', 130);

	// The site header function
	function site_header_style() {
	    ?><style type="text/css">
	        div#header {
	            background: url(<?php header_image(); ?>);
	        }
	    </style><?php
	}

	// The admin header function
	function admin_header_style() {
	    ?><style type="text/css">
	        #headimg {
	            width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
	            height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
	        }
	    </style><?php
	}

	// Enable!
	add_custom_image_header('site_header_style', 'admin_header_style');

?>

I copied and pasted it exactly and then changed width and height to 990 and 238.

Now my title area is using part of the header image as a background. There's a strip of the header image in the title area, a space and then the actual header image. Any help would be greatly appreciated.

My site is here: http://sumptuousart.com

Thank you,
~Steve

bramwittendorp on "MySQL database installation is not working"

$
0
0

For my first WordPress plugin I chose to make it my self difficult because I want to use a new table in the WordPress database installation.

However if I install the plugin the database tables are not created for some sort of reason. I checked the query in phpMyAdmin and it runs fine in there so there aren't any errors in the query, but what am I doing wrong?

<?php
// database creation
function create_rozenactie(){

$sql1 = "CREATE TABLE rozenactie (
  order_id int(11) NOT NULL AUTO_INCREMENT,
  ontvanger varchar(225) NOT NULL,
  klas_ontvanger varchar(50) NOT NULL,
  boodschap varchar(250) NOT NULL,
  aantal int(11) NOT NULL,
  bedrag int(11) NOT NULL,
  afzender varchar(225) NOT NULL,
  klas_afzender varchar(225) NOT NULL,
  email varchar(250) NOT NULL,
  betaalmoment varchar(250) NOT NULL,
  betaald varchar(200) NOT NULL,
  anoniem varchar(20) NOT NULL,
  PRIMARY KEY  (order_id)
);";

require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql1) or die("Instalatie tabel Rozenactie mislukt");

}

function create_algemeen(){

$sql2 = "CREATE TABLE algemeen(
  actief varchar(25) NOT NULL,
  prijs varchar(11) NOT NULL
);";

require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql2) or die("Instalatie tabel Algemeen mislukt");
}

function insert_general_settings(){
global $wpdb;

$aanpassen = $wpdb->insert( algemeen, array('actief' => 'true', 'prijs' => '1') );
$aanpassen;
}
?>

alanicolasouza on "wp_list_bookmarks in foreach don't work"

$
0
0

Hey everyone.

The $categories is a array with the category slug. This code works just to the first cycle, which means, only the first category is printing.

foreach($categories as $category){
  if( wp_list_bookmarks('category_name='.$category.'&echo=0') ){
        wp_list_bookmarks( 'title_li=&category_name='.$category.'&before=<li>&orderby=name' ).
  }
}

Aill3urs on "Woocommerce Redirect"

$
0
0

Hi

I have add in fonction.php this

add_filter('woocommerce_login_redirect', 'ras_login_redirect');

function ras_login_redirect( $redirect_to ) {
global $current_user, $wpdb;
$role = $wpdb->prefix . 'capabilities';
$current_user->role = array_keys($current_user->$role);
$role = $current_user->role[0];

if($role=="adminsitrator"){
$redirect_to = 'http://anypage.com';
return $redirect_to;
}else{
$redirect_to = 'http://anotherpage.com';
return $redirect_to;
}
}

But it s look like it can t take the current user role

Any Idea ?

Regards

Viewing all 8245 articles
Browse latest View live




Latest Images