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

edow on "How to show the posts with the highest votes on homepage"

$
0
0

Hi,

I use this code to show the post score which bcworkz made for me:

<?php
$counts = aigoo_get_score();
extract( $counts );  //restores compacted variables

<span>+'.$score.'</span>
?>

This is in my functions.php:

<?php
/* Display likes/unlikes */
function aigoo_get_score() {
   $comments = get_comments( array('post_id' => get_the_ID(),) );
			$likes = array();
			$unlikes = array();
			foreach( $comments as $comment ) {
				if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
					else $likes[] = $comment;
			}
    $likescore = count( $likes );
	$unlikescore = count( $unlikes );
	$score = count($likes) - count($unlikes);
	$totalvotes = count($likes) + count($unlikes);
	return compact('likes', 'unlikes', 'likescore', 'unlikescore', 'score', 'totalvotes');
}
?>

Now comes the new part of code I just use. The following code is showing the latest 5 posts with the most comments in a specific category on my homepage:

<?php
			$popular = new WP_Query( array(
				'post_type'             => array( 'post' ),
				'showposts'             => 5,
				'cat'                   => 'activiteit',
				'ignore_sticky_posts'   => true,
				'orderby'               => 'comment_count',
				'order'                 => 'dsc',
				'date_query' => array(
					array(
						'after' => '0',
					),
				),
			) );
		?>
		<?php while ( $popular->have_posts() ): $popular->the_post(); ?>
			<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> (<?php comments_number( 'Nu stemmen!', '1', '%' ); ?>)</li>
		<?php endwhile; ?>

How can I make it happen that instead of showing the posts with the most comments it shows the posts with the highest voted comments on my homepage? (See the first and second code.)

I don't know if it's even possible. Hopefully someone can help me with this.

Problem 2:
I also notice that when I duplicate this code and change the categoryname it lists both only one category even when the category name is different.


NatESkiN on "Passing a variable to a function that calls "wp_head""

$
0
0

Hello everyone,

I'm working on a theme based on Twentyfourteen. I'm working on a hack to show a different background when a "featured post" in action "wp_head" declared my file functions.php.

I've tried a thousand different options. Passing a variable to the function that called the "wp_head" (which passed the variable twice) or adding a filter, but it still fails. This I have tried in the "content-featured-post.php" file.

I'm a little desperate and I do not get a solution. Could you give me some idea?

Thank you.

Baden on "String localization for variables"

$
0
0

In the following example string_1 and string_2 are used as the select value of an option element, however the display text is translated.

$option_arr = array('string_1', 'string_1');
foreach($option_arr AS $opt){
	echo '<option value="'.$opt."'>'.__($opt, 'text_domain').'</option>';
}

This works so long as string_1 and string_2 are manually entered into the .pot file.

So that these strings may be discovered by i18n tools such as makepot.php, is there a better practice than simply declaring the strings manually like so:

//these are only so that makepot.php knows they exist
$string_1 = __('string_1', 'text_domain');
$string_2 = __('string_2', 'text_domain');

WdPress on "wordpress print out post values before save to database"

$
0
0

How to display post values in custom post type page before store to db.

iWPer on "Dynamic select box in Contact Form 7"

$
0
0

Hi,

I used Contact Form 7 - Dynamic Text Extension for a dynamic text-field, this works perfectly.
I now want to add a dynamic select box to my form, which is not possible with the plugin. I added the Advanced Custom Fields plugin to add a check-box list to my pages and inserted the form in a template. So when I make a page I can select all the possible values for the select-box.

I found a lot of discussions and solutions but I am unable to implement any of them in my setup; or maybe they don't work anymore because of their age (updates between then and now.)

http://wordpress.org/support/topic/auto-fillpre-fill-depending-on-post
http://wordpress.org/support/topic/plugin-contact-form-7-populate-select-box-from-database?replies=14

Anyone able to point me in the right direction ?

THANKS !!

ajcke on "wp_list_pages Output Parent and Child Pages"

$
0
0

I've been using the code below to auto display pages and child pages in a sidebar. Our site has a few parent pages and the rest of the pages are all nested within these. Right now the code displays the parent page, child pages, and all grandchildren pages no matter what page a user is on. I would like to modify the code to display the parent page for the title and child pages ONLY in the ul. It would also be cool to be able to leave out a page if needed.

<?php
  if($post->post_parent) {
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  $titlenamer = get_the_title($post->post_parent);
  }

  else {
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  $titlenamer = get_the_title($post->ID);
  }
  if ($children) { ?>

  <h2> <?php echo $titlenamer ?> </h2>
  <ul>
  <?php echo $children; ?>
  </ul>
<?php } ?>

Example of Output
If a user is on any of the pages below the menu looks the same:
<h2>Athletics</h2>

  • Baseball
    • HS Baseball
  • Basketball
    • HS Basketball – Boys
    • HS Basketball – Girls
    • JH Basketball – Boys
    • JH Basketball – Girls
  • Cheerleading
    • HS Cheerleading
    • JH Cheerleading
  • Football
    • HS Football
    • JH Football
  • Softball
    • HS Softball
  • Track & Field
    • HS Track & Field – Boys
    • HS Track & Field – Girls
    • Indoor Track
    • JH Track & Field – Boys
    • JH Track & Field – Girls
  • Volleyball
    • HS Volleyball
    • JH Volleyball

Desired Output Example
If a user is on the basketball page the menu only looks like this:
<h2>Basketball</h2>

  • HS Basketball – Boys
  • HS Basketball – Girls
  • JH Basketball – Boys
  • JH Basketball – Girls

If a user is on the athletic root parent page the menu would look like this:
<h2>Athletics</h2>

  • Baseball
  • Basketball
  • Cheerleading
  • Football
  • Softball
  • Track & Field
  • Volleyball

salihkulangara on "Filter Content for Attachment and Modify it"

$
0
0

I want to do this, just search the content for any attachments, and if attachments, usually the embedded images inside post, show the Custom size versions(that i have defined in functions.php) of those image in front end. I think we want to do a filter on, the_content, wp_get_attachment_image , etc.... . I am not sure about that, So if there anyone who can help me??

otti.steinhauer on "How to send a SMS"

$
0
0

Hello,
at my plugin I'm already sending automatic mails with wp_mail() function. Now I want to send SMS and I don't know how to do that.
I have got via a form the number of a mobile phone and I can create the message via code. So what is the best way to send the message as SMS to the number?

Thanks

Ottilie


patsfans on "Eliminating "Pages: " Prefix on pagination"

$
0
0

I'm trying to set up pagination buttons when I break up my posts with the <!--nextpage--> tag that say "CONTINUE" and "PREVIOUS", and am trying to eliminate the "Pages: " prefix that appears in front of them. Does anyone happen to know what template that's in so I can remove it?

Ian

Call_Me_Matthew on "How to assign a Page Template to certain URL Patterns?"

$
0
0

Is there a way to set up a page template that assigns itself to pages of a particular url structure?

For example, say you have these urls:

http://www.mysite.com/beachhouse/snippet
http://www.mysite.com/hospital/snippet
http://www.mysite.com/farm/snippet
http://www.mysite.com/mansion/snippet

I don't want to have to create pages manually for every "snippet' subpage on my site. Instead, I want to create a page template that will load automatically when a url with a pattern of "http://mysite.com/x/snippet" is visited.

I've already created a template file that loads content dynamically depending on the parent page(it takes the parent's slug from the url and serves up content based on that). I just need help figuring out how to assign it to a specific url pattern, as opposed to a page.

Thanks for any help!

learnandcode on "Redirect after form submission"

$
0
0

Hello.
I have widget that is prepared for making appointment and I need to redirect to another site after submission. But as I never dealt with WordPress nor php I have big trouble with determine what function exactly is responsible for form submission. Form action is connected with
/wp-admin/admin-ajax.php

And at the end I have normal form submit button. That's all I found. Where should I search for a form submission function.

jeriksson on "Get post title as the_post_thumbnail alt tag, how?"

$
0
0

Hi,

I'm a novice at this, i can't figure out how to get the post title as the post_thumbnail alt tag, i've read a couple of threads and tried using this code but it won't work, i'm suspecting i've missed something or formated the code incorrectly, can someone take a look at it?

<div class="entry-summary">
		<div class="excerpt-thumb">
			<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>
			<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gopiplustheme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
				<?php  the_post_thumbnail( array( 'alt' => trim( strip_tags( $attachment->post_title()));
			</a>
			<?php endif;?>
		</div>

original theme code looks like this:

<div class="excerpt-thumb">
			<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>
			<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gopiplustheme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
				<?php the_post_thumbnail('excerpt-thumbnail', 'class=alignleft'); ?>
			</a>
			<?php endif;?>
		</div>

thank you!

angela.marie.giaco@gmail.com on "Social Media Pop Up (Preferably without Plugin)"

$
0
0

Here is what I am trying to do:

When a customer gets to a specific page, I would like a popup to appear on page load. Within the popup I would like to display an area to share a website on Facebook (and Twitter, Google Plus if possible). The trick is that the page to be shared is the homepage, not the current page that has displayed the popup. Once they have shared on Facebook I would like the customer to be redirected to another of our pages (that will have a code on it for a discount).

I'd preferably like to use as least amount of plugins as possible, but if that's the only option then I can deal with it. If anyone could advise me on the best way to accomplish this, I would very much appreciate it.

My site is http://clearchoicephotobooth.com.

Thank you.

brisimmons105 on "link to latest post in category on a category list?"

$
0
0

I've got a code that currently lists out all my categories, in alphabetical order, with anchors to each letter.

When I click on one of the categories, it links me to the category archives page by default, but is there a way to link it directly to the latest post in that category instead of the category archive page?

Here is my code currently:

http://pastebin.com/mVJtv67x

joaoimai on "Hide a specific category from page navigation"

$
0
0

Hello.

I have a category that I wanted parallel from the main blog.
So I didn't want it to appear on the page navigation buttons. Only when it is at the category page.

Anyone know the easiest to do it?

I would need to exclude the category from the main navigation, and have a parallel page navigation exclusive for the hidden category. Is that right?

(If possible, the option for "recent posts" list too)

Thank you very much!


peter-hamilton on "Plugin jQuery and CSS Overload?"

$
0
0

Good topic, I am also wondering the same.

Running BBpress and about 6 plugins and site is very slow.

Google pagespeed gives me 64 points and lots of issues.

Looking forward to an answer.
P.H.

asidre on "WP_Query ignoring the posts_per_page argument."

$
0
0

I have a custom post type which i want to use pagination
hence i have the code set up like below:

global $wp_query;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
	'post_type' => 'cpt',
	'posts_per_page ' => 5,
	'offset' => 0,
	'orderby' => 'title',
	'order' => 'ASC',
	'paged' => $paged,
	'post_status' => 'publish'
);

$wp_query =new WP_Query($args);
print_r($wp_query->query_vars);

then the loop:

<?php if($wp_query->have_posts()) : ?>
<?php while($wp_query->have_posts() ): $wp_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php endif; ?>

Result of the query_vars:

Array ( [post_type] => cpt [posts_per_page ] => 5 [offset] => 0 [orderby] => title [order] => ASC [paged] => 1 [post_status] => publish [error] => [m] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [menu_order] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [post_parent__in] => Array ( ) [post_parent__not_in] => Array ( ) [author__in] => Array ( ) [author__not_in] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [posts_per_page] => 10 [nopaging] => [comments_per_page] => 50 [no_found_rows] => )

ultimately I want to properly get the max_num_pages variable, however this is not possible because it brings 10 posts by default and I cannot control this value.
Somehow it seems to be overriding the posts_per_page argument before the sql executes.

If I do
$posts = get_posts($args);
instead of
$wp_query = new WP_Query($args);
$posts = $wp_query->posts

it returns 5 posts correctly. But there is a dilemma which i cannot get the max_num_pages value from it.

Thanks in advance for any tips.

Luke Janicke on "How to customize "Insert Media" output?"

$
0
0

I want my editors to be able to use the default "Insert Media" feature but I want to customize the output. By default, "Insert Media" produces something like this:

[caption id="attachment_414" align="aligncenter" width="600"]<a href="http://www.theharbiner.com/?attachment_id=414" rel="attachment wp-att-414"><img src="http://www.theharbiner.com/media/2014/06/baskets-of-tea-1-600x397.jpg" alt="Baskets of Tea" width="600" height="397" class="size-medium wp-image-414" /></a> Varieties of tea on display and for purchase.[/caption]

Wow! That’s a lot. And it contains a mix of shortcode, hardcoded HTML and a lot of hard-coded attributes.

What I want the output to be is (for a single image):

[image id="414"]

Simple!

This would be easier for my editors (who don’t know HTML) and it’s future proof – I can regenerate images at different sizes and change HTML and attributes any time as I develop the theme. It also looks good alongside the Markdown that I’m making all my editors use.

I have already written the shortcode functions to output the desired HTML in my theme. What I need to do is filter the returned output of the actual "Insert Media" function in the post editor.

Is this possible? What is the filter to use?

Note: The answer is not img_caption_shortcode. That filter is for modifying the HTML output by the theme.

totland on "How to duplicate Vimeo shortcode"

$
0
0

I use the standard Vimeo shortcode for embedding Vimeo videos (http://en.support.wordpress.com/videos/vimeo/), and really like the responsive markup it produces.

I also have my own video player that I would like to embed in the EXCACT same way, by simple pasting http://www.mydomain/v/12345 in the text editor (12345 is the id of the video). Should parse out the id, insert an iframe with a slightly different url (say http://www.mydomain/v/player?id=12345) etc. Basically the same stuff that happens with the Vimeo shortcode.

Do I have to edit core files, and in that case which and what, or could I add something to my functions.php file?

All help is much appreciated!

shazdeh on "urlencode_deep function and wrong URL"

$
0
0

This seems like a bug with urlencode_deep function:

print_r( urlencode_deep( array( 'width' => '80%' ) ) );

The result of that is:

Array
(
    [width] => 80%25
)

Notice the extra 25 in the parameter.

The why:
I'm using add_query_arg function which in turn uses urlencode_deep function on all the parameters from the URI passed to the function. The problem is urlencode_deep function messes up one of parameters sent, so this:

http://site.com/?width=80%

Which is valid URL, inside the add_query_arg function becomes:

Array
(
    [width] => 80%25
)

Any idea why?

Viewing all 8245 articles
Browse latest View live




Latest Images