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

Mr_ZioN on "Get random images from gallery on another page"

$
0
0

Hi,

I'm currently in the process of building a website and I get stuck on this.

I have a gallery with images on a page and I want to get 3 random images and display them on the homepage in a seperate section. I can get the images using get_post_gallery_images, but that only gets the image location. I need the title and caption aswel. I tried several code snippets I found doing a google search. I can get the images that are on the current page.

Last thing I tried which worked was getting all the content of that page, but when the gallery fills up that will be painfully slow later on.

Any help is appreciated!


Mbertu on "Saving option for the first time"

$
0
0

Hi everybody, I'm Michele from Italy. I've a question about the saving option's process.
Both in my plugin and my template I've found a problem. The first time an option is saved the validation callback passed to the register_setting funciton is triggered twice.
First time the input variable have the post fields values, the second time have the output of the first callback execution.
Is this normal?

natepelzel on "Universally Change Iris Palette"

$
0
0

Hey guys,

I use wordpress on most of my client's site, and I recently had the idea to alter the palette below the Iris color picker to match my client's color scheme. Make it quicker for me and easier for them.

I did some digging and found this site. It basically just said to paste this in my functions.php:

// customise palette colours
function firefly_customize_controls_print_footer_scripts() {
?>
<script>
jQuery(document).ready(function($){
$.wp.wpColorPicker.prototype.options = {
palettes: ['#ffffff', '#000000','#ff0000']
};
});
</script>
<?php
}
add_action('customize_controls_print_footer_scripts', 'firefly_customize_controls_print_footer_scripts');

Makes sense in theory, but I'm having the hardest time getting it to work. The script is definitely running. In my troubleshooting I put an alert in the script and it most definitely fired.

Any idea what I'm missing? I checked some color pickers on a few different pages, including one for my theme's built in settings and some in the theme customization page.

I'm pretty strong with php & css, and have been dabbling in javascript/jQuery for a while now, so I'm comfortable but not fluent with it.

Any ideas you all have would be greatly appreciated.

Gogogogo on "My wp-admin hacked"

$
0
0

I was working on this site well when suddenly after trying to update a page i got the message that hacked by gantengers crew.

The urls are(user side) all fine except for the admin side.
I cannot acess any page under wp-admin.

a few days ago my hosting provider changed my permissions to 777 and then again to 755. Could this have affected it.

Worried because this site has like 2000 pages.!
Please help?

tsndschn on "Add caption to attachment permalinks - can't decode permalinks"

$
0
0

Hi there,

I wanted to include the caption in the permalinks of my attachments.

I managed to write the following code:

function nice_attachment_link( $link, $post_id ){
$post = get_post( $post_id );
$caption = $post->post_excerpt;
if ($caption) {
$caption = clear_string($caption);
    return home_url( '/images/' . $caption );
} else {
     return home_url( '/images/' . $post->post_title );
}
}
add_filter( 'attachment_link', 'nice_attachment_link', 20, 2 );

What happens: Very nice permalinks are generated. But once I click on them I'm not redirected to the correct attachment page. If there is no caption and the post title is displayed in the permalink then I get the correct attachment page.

I probably will have to rwrite some rules, is guess, but I didn't get how that works exactly?

As I'm working localhost, I cannot include a link, sorry.

Thanks in advance,
Sarah

foolix on "Creating an Image gallery with Loop - Pagination"

$
0
0

Hi there,
I am trying to create an image gallery for my own custom WP theme.
I am making use of a loop which shows me the thumbnails of the images found among the uploads. This is working fine, however I also wish to have a pagination function for the gallery.
The pagination nav shows up but when I click a link to page 2 or more, the page is not found (404).

(I am not a pro at coding...)
I have used this code (which is five years old) to get where I am at:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loopb = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => 2, 'paged' => $paged ) ); ?>
<?php while ( $loopb->have_posts() ) : $loopb->the_post();

//display posts
?>
<?php endwhile; ?>
<?php
if($loopb->max_num_pages>1){?>
    <p class="navrechts">
    <?php
    for($i=1;$i<=$loopb->max_num_pages;$i++){?>
        <a href="<?php echo '?paged=' . $i; ?>" <?php echo ($paged==$i)? 'class="selected"':'';?>><?php echo $i;?></a>
        <?php
    }
    if($paged!=$loopb->max_num_pages){?>
        <a href="<?php echo '?paged=' . $i; //next link ?>">></a>
    <?php } ?>
    </p>
<?php } ?>

(This code is taken from here: https://wordpress.org/support/topic/adding-pagination-to-a-wp_query-loop#post-1516156 )

Can anyone tell me, why the pagination does not work properly?
Thanks for your time. Foolix

farooqiaryan on "Why logo only shows on Home Page?"

clayhendrix on "Incorrect footer position"

$
0
0

URL: http://www.farmington.church

Users on tablets as well as others with the browser window not maximized see the maroon bar creep up under the slider and the contact information appears to wrap around the slider, although it is not a desirable wrap.

I want the maroon bar and text below it to remain below the slider regardless of the device used.

I know this is an easy fix, I just haven't figured it out yet.

Please help if you can.


Mvin on "Solution: Previous/Next-Post-Navigation only in lowest child category"

$
0
0

Hey everybody,

seeing as this is a notorious issue, I thought I'd share a function of mine that solved the problem.

The Problem

As many of you probably know, the default previous_post_link() and next_post_link() functions of Wordpress are frustratingly limited, even with the following two parameters:

in_same_term - Indicates whether previous/next post must be within the same taxonomy term as the current post. [...] If the post is in both the parent and subcategory, or more than one term, the previous post link will lead to the previous post in any of those terms.

-> Even when activated, this means that previous/next post links cannot be restricted to just the immediate child category and will typically go all over the place.

Excluded terms - Array or a comma-separated list of numeric terms IDs from which the next post should not be listed.

-> Though exluding all the parent categories with this in combination with the above seems like a solution at first, Wordpress unfortunately interpretes this parameter to exlude all posts assigned to the categories. Example: Imagine your hierarchy is "Movies -> Science-Fiction -> Cyberpunk" and you always tag your "Cyberpunk"-Posts in all the parent categories as well. By exluding "Movies" and "Science-Fiction" to restrict the query to just "Cyberpunk", Wordpress will exlude everything instead.

You could tag your posts with the lowest child category only and then exclude its parents, which should work, of course. However, there's often a reason you don't want to do so, in which case, the following should help.

Prev/Next-Post-Navigation in the lowest child category

This function will return a multidimensional array with the structure: $results[x][y], where x is the direction (0 = previous post, 1 = next post) and y is the post data (0 = post title, 1 = post permalink). So for example, $results[1][0] would return the title of the next post. When there is no previous/next post, the array will return an empty string as data.

function lowest_category_post_navigation() {

	// Finding the "lowest" child category
	$categories = get_the_category();
	$lowest_category = $categories[0];

	foreach($categories as $i => $testcategory)
	{
	    if($testcategory->parent == $lowest_category->cat_ID)
	    {
	        $lowest_category = $testcategory;
	    }
	}

	// Some placeholders for the loop
	$currentpost_date = get_the_date() . " " . get_the_time();
	$currentposttrigger = false;

	$prevposttitle = "";
	$prevpostlink = "";
	$nextposttitle = "";
	$nextpostlink = "";

	// Loop to fetch all posts of the lowest category in a query
	// and to save the titles/links of posts adjascent to current post
	$args = array('cat' => $lowest_category->cat_ID,
														'orderby' => 'date',
														'order' => 'DESC');
	$category_query = new WP_Query($args);

	if ( $category_query->have_posts() ) : while ( $category_query->have_posts() ) : $category_query->the_post();

			$querypost_date = get_the_date() . " " . get_the_time();

			if ($currentposttrigger == true)
			{
				$prevposttitle = get_the_title();
				$prevpostlink = get_permalink();
				$currentposttrigger = false;
			}

			if ($currentpost_date === $querypost_date)
			{
				$currentposttrigger = true;

				$nextposttitle = $temp_nextposttitle;
				$nextpostlink = $temp_nextpostlink;
			}

			$temp_nextposttitle = get_the_title();
			$temp_nextpostlink = get_permalink();

		endwhile;
	else:
		// no posts found
	endif;

	wp_reset_postdata();

	// Saving results into array
	$results = array
						 (
						  array($prevposttitle, $prevpostlink),
							array($nextposttitle, $nextpostlink)
						 );

	return $results;
}

Basically what this function does is find the deepest child category of the current post, query that and only that category by date and retrieve the title and link of the previous and next posts.

Hope this helps!

Please Add Screenshots on "How would I automatically append/suffix the post title with post ID"

$
0
0

How would I automatically append/suffix the post title with post ID?

e.g.
If I publish my post with the title "How to make a widget" when I use the <?php the_title(); ?> tag, the post title is displayed as "How to make a widget - 34" (assuming the post ID is 34.

caroline on "Sticky sidebar"

$
0
0

I found this code here http://andrewhenderson.me/tutorial/jquery-sticky-sidebar/ and wanted to try it. Unfortunately I can't make it work.

I understand my div must be renamed to .sticky, but I believe there is something with the jQuery that I don't understand.

Here's my code I use in functions.php:

wp_enqueue_script("jQuery");
$(function(){ // document ready

  if (!!$('.sticky').offset()) { // make sure ".sticky" element exists

    var stickyTop = $('.sticky').offset().top; // returns number

    $(window).scroll(function(){ // scroll event

      var windowTop = $(window).scrollTop(); // returns number

      if (stickyTop < windowTop){
        $('.sticky').css({ position: 'fixed', top: 0 });
      }
      else {
        $('.sticky').css('position','static');
      }

    });

  }

});

Help very much appreciated
/Ca

shawmutsteve on "Page loads twice - but with a twist"

$
0
0

We build dynamic real estate pages. We've noticed that for each single request to generate a page for any given url, our plugin goes through it's initialization twice. The difference appears to be $_SERVER['HTTP_ACCEPT']. On the first time through, HTTP_ACCEPT contains what you would expect -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"

But on the second time through, it only contains "image/webp,*/*;q=0.8". Like it's looking for a favicon or something.

The plugin loads like this:

add_action('plugins_loaded', array(self::instance(), '_setup'));

public static function _setup ()
	{
	global $rover_idx;
	$rover_idx					= new Rover_IDX;

	if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']), 'text/html') !== false))
		{
		require_once ROVER_IDX_PLUGIN_PATH.'rover-init.php';
		require_once ROVER_IDX_PLUGIN_PATH.'rover-content.php';
		}
	}

So we made a change (above)to exit the initilization if HTTP_ACCEPT did not contain 'text/html'. This worked great, until we realized that the Next / Prev browser buttons didn't like it. If you pressed the Prev button, you'd see the previous page, but the [rover_idx...] shortcode would not be translated into content - you'd just see the shortcode on the page.

To reproduce:
- First go to http://vail.demo.roveridx.com/.
- Then go to http://vail.demo.roveridx.com/co/vail/.
- Then hit the back button.

I *think* this should be moved into the Advanced forum section.

Thanks
Steve

michellelyl on "IP Canonicalization Issue"

$
0
0

Hi all,

I really need help on this.
I did a site checkup and found the error below for IP Canonicalization Test.
"Your site's IP 109.199.126.100 does not redirect to your site's domain name".
I've tried using below in the .htaccess file but it's not working
RewriteCond %{HTTP_HOST} ^XXX\.XXX\.XXX\.XXX
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

Can someone please help me?

Thanks

Kucko on "Show variation prices in dropdown (WooCommerce)"

$
0
0

Hello all!

I'm having a hard time making this work for me. Let me explain the problem.
I have a product, in different sizes - 25 cm, 50 cm and 75 cm all with different prices, of course. Now, when I want to show the dropdown on my frontpage (so that the customer can pick a variant directly from frontpage, and doesn't have to click on the product first, and THEN put in cart), it doesn't show a price!

Now, when I click on the product, and select a variant while im in a single product page, it shows the price - and it changes when I select another variant - why doesn't i do it on the front page aswell?

Can someone please help me?
I'm really stuck here..
Btw. I know my way around PHP and WP-code - but maybe I have just hit a wall .. :/

Best regards
Aris Kuckovic

andy277 on "Activate plugins by a theme's functions.php"

$
0
0

Is it possible to activate plugins per theme?

I have a multisite, and I know it is possible to activate plugins per site. But I need plugins to be enabled for specific themes.

Someone asked a similar question - if it is possible to activate plugins by other plugins: http://wordpress.stackexchange.com/questions/4041/how-to-activate-plugins-via-code

This was an accepted answer:

//Activate a plugin programmatically - Akismet example

    function run_activate_plugin( $plugin ) {
    $current = get_option( 'active_plugins' );
    $plugin = plugin_basename( trim( $plugin ) );

    if ( !in_array( $plugin, $current ) ) {
        $current[] = $plugin;
        sort( $current );
        do_action( 'activate_plugin', trim( $plugin ) );
        update_option( 'active_plugins', $current );
        do_action( 'activate_' . trim( $plugin ) );
        do_action( 'activated_plugin', trim( $plugin) );
    }

    return null;
}
run_activate_plugin( 'akismet/akismet.php' );

However someone commented about this not being very safe and I'm also not sure if this would be a good idea to add to a theme's functions.php file.

I added this above code to a themes functions.php to activate some plugins and so far this is working without any problems. Would I run into problems with this, or is there some better code to use? There is also this function activate_plugin() not sure if that function is a better way to activate plugins.

I am not very good with code, any help appreciated.


digitaladquest on "How to sanitize mobile numbers"

$
0
0

Hi I have a field in theme customizer to enter mobile numbers in the format +91 99999 99999 I am not able to sanitize with the code below-

$wp_customize->add_setting( 'themeslug_telephone' ,
array ( 'default' => '',
'sanitize_callback' => 'check_number'
));

function check_number( $value ) {
$value = (int) $value; // Force the value into integer type.
return ( 0 < $value ) ? $value : null;
}

It returns a different value than the submitted one.

Any Help??

kinghippo on "Creating plugin from existing code"

$
0
0

Hello

I have written some code in PHP/MySQL and jQuery that creates a live search suggestion in a search box. The data for the search is populated from a table on my server. I am trying to now use this code as a plugin for WordPress.

I have read over the codex and done a few tutorials to create a plugin, but I'm still lost when it comes to making my code work in WordPress. Based on my reading I think I need to create a few custom functions that input data into some of WP's built in functions?

I know I need to use the $wpdb class to query the database, but I'm not sure how to display all the data. Do I create a custom page type that uses my html/css/js?

My code is can be seen here. I'm sure it's not secure at all and fairly sloppy, but this is all pretty new to me still. I'm kind of lost and feel like I'm running in circles so any help would be greatly appreciated.

Thanks

myjosephines on "Remove /wp-content/themes/ for url?"

$
0
0

Usually I use a plugin to make it easy with redirects/cloaking urls. But this time I had to use some code to add a little function to it.

So the redirects are inside an index.php in a folder. So this is an example of an url currently (I can't move the folder to the root because it needs the wordpress theme-functions to work - I'm calling member id in the file):

http://domain.com/wp-content/themes/meow/out/01/

It works fine, but I would like the url to be like this:

http://domain.com/out/01/

Is there a way to do that?

samwilson on "Remove Archive Title Labels error"

$
0
0

Could it be that they're using PHP < 5.3.0? I think that's when lambdas became available.

up2peace on "Hacked Site needs Restoration"

$
0
0

Hello all,

Apparently our WP site was hacked. The issue seems to be coming from the host, however we now have access to our wp-admin dashboard (with a new name and password) and would like to restore a backup of our site. Is this possible? Our wp-admin dashboard is a blank slate as of now. If this is possible how do I go about restoring our site?

Thanks!

Viewing all 8245 articles
Browse latest View live




Latest Images