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

Cliff on "how to create your own Button in TinyMCE"

$
0
0

This is what i like to do.

1. Create a button in TinyMCE (I know this part -> http://codex.wordpress.org/TinyMCE)
2. When i click on this button, it will pop up asking me for a youtube video URL.
3. I enter the youtube URL (http://www.youtube.com/watch?v=jflEPT-oLDD). It will translate to httpv://www.youtube.com/watch?v=jflEPT-oLDD and paste it in the post as text.

My question is the second part and the third part. I have no clue how to do that.

PS - the third step is to translate the URL so that Youtube Lyte can undertand the URL.

Thanks!


modeman on "How to loop posts even if category does nt have sub-categories"

$
0
0

Hello, i have this code: http://pastebin.com/tF2c63Mb

Now posts show only on sub-categories. I need to show posts even when category doesn't have sub-categories.

I need like this:
Category - > Show posts

Now its like this:
Category - > Posts don't show
Category -> Sub-category - > Posts

I purpose that the code needs to check if category does not have subcategory ant then loop posts.

Maybe anybody knows hot so solve?

cusackd on "Parents and Children, not the human kind."

$
0
0

Hello All,

This is my first time coming here to ask a question and I hope someone can help.

I would like to do the following but having difficulty doing it.

Get all parent categories in a custom post type and put them in a drop down menu
When parent category is selected, populate the next drop down with its children and keep doing the same until their is no children left.

For instance.
Select Country,
Select State,
Select Town

I can only see myself doing this with categories, if anyone has an alternative method that would be awesome.

joeymalek on "core support of autostart, preload attributes"

$
0
0

Hello and welldone to wordpress for supporting html 5 media playing natively.
I yet did not use these new wp features and continued to use earlier plugins only because wordpress core does not support the autoplay and preload attributes for html 5 video/audio media.
I am posting this on purpose here because I expect this to be made available unless I missed to find it so far. I believe it needed by the community to have the wordpress core html 5 media player supporting video autostarting when the visitor arrives on the page. Thanks in advance to all of you contributing to make this happen.

halilturkoglu on "Check if Wordpress is installed"

$
0
0

Hi, I have some questions.
1. I have my own web site running WP (in subdirectory), alongside with my own website. I am trying to find a function (not wp functions), which can check if any Wordpress installations exist.
I need this function to determine the login page (my own login or wp-login).

2. I need to get the user password from WP-DB, to copy it to my web sites own database or need to crypt the password like wp does, to make my own users table and wp_users table synchronized.

Is there any way to these? And how can i do them. Any help appreciated.

2olive on "Custom post type and meta box into custom table"

$
0
0

Hi all.
I wonder how to do this. I've made a custom post type called swimmers with a meta box containing some values of interest and everything is ok. I can insert and save data with no problem.
Now I've got a custom table in the database for the swimming competitions and I wonder if this could pull some of the data from the swimmer post type and from that custom meta box in order to prevent writing the same values over and over again.

In the specific, I'd like to get the swimmer post title (aka the swimmer name) and copy it into the custom table. When can I do it? While I'm saving the meta box or while I'm publishing the post? I think both are possible, but I'm not able to insert the value into the custom table.

This is my code (not working):

function update_table_with_swimmers(){

global $wpdb;
$table_name = $wpdb->prefix . 'swim';
$title = get_the_title();
$values = array(
  'athlete' => $title,
);
$formats_values = array(
  '%s',
);
$wpdb->insert( $table_name, $values, $formats_values );
}

add_filter( 'publish_post', 'update_table_with_swimmers' );

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

What about retrieving values from meta box and copying them into that custom table?

Thank you in advance

Diraen on "Hack the status post menu"

$
0
0

Hi !
I would like to add a « mine » status on the post menu on the admin interface.
I only found hack to hide others' post for editors but nothing that I can adapt to my needs.
Any idea ?

jralston on "PHP echo href problem"

$
0
0

I am having a heck of time trying to echo a link. Here is my code:

if ( ! is_user_logged_in() ) { // Display WordPress login form:
    $args = array(
        'form_id' => 'loginform-custom',
        'label_username' => __( 'Username custom text' ),
        'label_password' => __( 'Password custom text' ),
        'label_remember' => __( 'Remember Me custom text' ),
        'label_log_in' => __( 'Log In custom text' ),
        'remember' => true
    );
    wp_login_form( $args );
    wp_register('You must ', ' and login in order to post on this forum.');
    echo '<a href="' . wp_lostpassword_url() . '">Lost Password</a>';
    $url = wp_lostpassword_url('/');
    echo "<a href=$url>Click here</a>";
} else { // If logged in:

    echo " Welcome! You are logged in.  |   ";
wp_loginout( home_url() ); // Display "Log Out" link.
}

As you can see I've tried 2 ways of displaying the href and neither are working. I have tried many different ways and none are displaying the url as clickable. I can echo the correct url and the "Lost Password" words - but it's not clickable. I cannot get the href part of it to work. It needs to be within the if/else statement. Suggestions please?


kimbo_king on "Page -"

$
0
0

Hi

I have a problem when somebody views my forum on a mobile

My custom header moves with the screen but my 'wordpress menu' doesn't

http://www.togganet.co.uk/blog/forums/

Which file is the 'wordpress manu' in? What do I change in the stylesheet to make this move(relative?)

When I say wordpress menu I mean the menu which shows my pages (Forum Home/ Sign In/ Register/ Lost Password?)

gpspake on "posts_where filter doesn't work in a class."

$
0
0

I'm trying to get all of the posts with a custom post type that have been published in the past 5 days.

Although this is overly difficult, and it doesn't look like a better method will be available until 3.7, I've managed to get it working inside of a custom template by filtering adding a filter to posts_where.

The problem is, I need to do this inside of a class and I can't figure out what I'm doing wrong. I'm almost certain that it is my code that is the problem.

Here is the code that works:

function filter_where( $where = '' ) {    // posts in the last 5 days
  $where .= " AND post_date > '" . date('Y-m-d', strtotime('-5 days')) . "'";
  return $where;
}

add_filter( 'posts_where', 'filter_where' );

$args = array(
 'post_type' => 'listserv',
 'tax_query' => array(
   'relation' => 'AND',
   array(
     'taxonomy' => 'listserv',
     'field' => 'slug',
     'terms' => 'staff-listserv'
  )
 )
);

$query = new WP_Query( $args );
echo '<div id="content" style="">';
while( $query->have_posts() ) : $query->the_post();

echo '<a href="#">'. get_the_title() .'</a><br/>';

endwhile;
echo '</div>';

remove_filter( 'posts_where', 'filter_where' );
?>

The problem is, when I put everything in to a class and move the second part in to a method, it simply returns the 8 most recently published posts and pages.

Here's what that code looks like:

class Test_Range {

	private function filter_where( $where = '' ) {    // posts in the last 30 days
	    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-40 days')) . "'";
	    return $where;
	}

	public function range_announcements() {

		$filter_where = $this->filter_where();

		add_filter( 'posts_where', $filter_where);

			$args = array(
							'post_type' => 'listserv',
							'suppress_filters' => false,
							'tax_query' => array(
								'relation' => 'AND',
								array(
									'taxonomy' => 'listserv',
									'field' => 'slug',
									'terms' => 'staff-listserv'
								)
							)
						);

		$query = new WP_Query( $args );
		$announcements = '<div id="content" style="">';
		while( $query->have_posts() ) : $query->the_post();

    $announcements .= '<a href="#">'. get_the_title() .'</a><br/>';

    endwhile;
    $announcements .= '</div>';

		echo $announcements;

		remove_filter( 'posts_where', $filter_where );
	}

}

$testing_the_range = New Test_Range();
$testing_the_range -> range_announcements();

I've been messing with this for hours and I'm not sure what to try next. Any suggestions?

wnnnews on "jQuery undefined error fix needed"

$
0
0

Our main slider is not working.
Showing this jquery not defined in our home.php
Need rewrite sample ideas to correct.
Thx for helping.
________________

<script type="text/javascript">
(function($) { $(document).ready(function(){
$("#photoGalleryBar .container").jCarouselLite({
<?php if($wpnv_options['midautorotate'] == 1){ ?>
auto:<?php if ( $wpnv_options["midpausetime"] <> "" ) { echo $wpnv_options["midpausetime"].'000'; } else { echo '5000'; } ?>,
<?php } ?>
scroll: <?php if ( $wpnv_options["midscroll"] <> "" ) { echo $wpnv_options["midscroll"]; } else { echo '4'; } ?>,
speed: <?php if ( $wpnv_options["midspeed"] <> "" ) { echo $wpnv_options["midspeed"].'000'; } else { echo '2000'; } ?>,
visible: 5,
start: 0,
circular: false,
btnPrev: "#previous_button",
btnNext: "#next_button"
});
})})(jQuery)
</script>

jnwry on "add drop down menu to register post type"

$
0
0

Hi,
I'm trying to figure out how to integrate register post type with my plugin. What I need is that each author have access to post to his/her course. So I need a drop down menu that would select the course he wants to post to. Thanks in advance.

Marcushill746 on "Help to Add a 'Load More' Button to list of posts"

$
0
0

Hey,

So I've been putting together my own theme, and the only thing I have left to do is implement some kind of 'Load More Posts', infinite-scroll type thing to the page that displays my blog posts. Here is the code as it stands:

<?php

              // Grid Parameters
              $counter = 1; // Start the counter
              $grids = 5; // Grids per row
              $titlelength = 60; // Length of the post titles shown below the thumbnails

              // The Query
              $args=array (
                'post_type' => 'post',
                'posts_per_page' => -1
                );
              $the_query = new WP_Query($args);

              // The Loop
              while ( $the_query->have_posts() ) :
                $the_query->the_post();

              // Show all columns except the right hand side column
              if($counter != $grids) :
            ?>
              <div class="">
                <div class=" ">
                  <a class="" href="<?php the_permalink(); ?>" ><?php the_post_thumbnail(thumbnail); ?></a>
                </div><!-- .postimage -->
                <div class="">
                  <a class=""href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <p class="">
                      <?php if (mb_strlen($post->post_title) > $titlelength)
                        { echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }
                      else { the_title(); } ?>
                    </p>
                  </a>
                </div>

              </div><!-- .griditemleft -->
              <?php

              // Show the right hand side column
              elseif($counter == $grids) :
              ?>
              <div class="">
                <div class="">
                  <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(thumbnail); ?></a>
                </div><!-- .postimage -->
                <div class="">
                  <a class="" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <p class="">
                      <?php if (mb_strlen($post->post_title) > $titlelength)
                        { echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }
                      else { the_title(); } ?>
                    </p>
                  </a>
                </div>
              </div><!-- .griditemright -->

              <div class="clear"></div>
              <?php
                $counter = 0;
                endif;
                $counter++;
                endwhile;
                  wp_reset_postdata();
              ?>

(code implemented from here: http://pabstwp.de/wordpress-thumbnailseite-mit-artikelbildern/)

With posts_per_page set to -1 as it is right now, all the posts that I have ever posted will be loaded, which is less than ideal. Changing the number does of course limit the posts displayed, but I am not sure how to correctly implement pagination/infinite-scroll with the code that I have right now.

Can anyone point me in the right direction?

robinburrer on "Nested custom post type pagination"

$
0
0

Hi forum,
after spending almost a day on this problem I hope that you can help me.
I have a custom post type "employee". In a wp_query I want to display all entries and want to have them paginated as well. That all works - on a regular page it does at least.

However if I insert the same code on my "single-institution.php" (institution is a custom post type as well that ) the pagination does not work anymore. It shows up, it links to the "correct" page (page/2/) but the link always leads back to the first page. It seems the following pages are not generated at all.

So is this possible at all? Can I have a working pagination for a custom post type on a "single-custom post type page"?

This is what the query code looks like:

$args=array(
           'post_type' => "employee",
           'post_status' => 'publish',
            'caller_get_posts' => 1,
            'orderby'           => 'menu_order',
           'order' => 'ASC',
           'posts_per_page' => 3,
           'paged' => $paged
            );

$temp = $wp_query;
$wp_query = null; 

$wp_query = new WP_Query($args);

// then I loop through the query

previous_posts_link('&laquo; Newer') ;
next_posts_link('Older &raquo;');

 wp_pagenavi(); 

//wp_reset_query();  // Restore global post data stomped by the_post().    

// Reset the  query
$wp_query = null;
$wp_query = $temp;

The argument array of the "institution" post type lools like this - in case this could be relevant:

$args = array(
         'label' => __('Institution'),
         'labels' => $labels,
         'public' => true,
         'publicly_queryable' => true,
         'show_ui' => true,
         '_builtin' => false,
         'show_in_menu' => true,
         'query_var' => true,
         'rewrite' => array("slug" => "in"),
         'capability_type' => 'post',
         'has_archive' => true,
         'hierarchical' => true,
         'menu_position' => 20,
         'supports' => $supports
      );

All help is appreciated!

Robin

Shapeshifter 3 on "3-Column Bootstrap Scaffolding"

$
0
0

Can anybody tell me the correct way to implement 3-columns into individual Static Pages or Posts using Bootstrap version 2.3.2. I've gone to the Bootstrap website; tried to follow their instructions; but here's what I come up with:

http://toolbox-4-websites.com/design/responsive/

Code shows up in the display, instead of creating 3-columns for content.


pdme on "Automatically inserted post needs update?"

$
0
0

I have a function which automatically inserts a woocommerce product once a custom type post called daily_cartoon has been added.

This is the code of the function:

function convert_daily_cartoon_into_product($post_id){

	if( ( $_POST['post_status'] == 'publish' ) && ( $_POST['original_post_status'] != 'publish' ) ) {

		// Create post object
		$post = array(
		  'post_title' => $_POST['post_title'],
		  'post_type' => 'product',
		  'post_status' => 'publish',
		  'tax_input' => array( 'product_cat' => 14 )
		);

		// Insert the post into the database
		$new_print = wp_insert_post( $post );

		update_post_meta( $new_print, '_thumbnail_id', get_post_thumbnail_id( $post_id ) );
		update_post_meta( $new_print, '_regular_price', 5 );
		update_post_meta( $new_print, '_price', 5 );
	}

}

add_action('publish_daily_cartoon', 'convert_daily_cartoon_into_product');

Everything looks fine: the product is added, complete with all the data, i.e. price, category, status published, etc.

But for some reason, it doesn't show up on the website product page until I go edit the new product and click 'update' - even though I change nothing.

Anyone?

mikelawton86 on "Wrapping 4 posts in a two divs"

$
0
0

HI,

I'm trying to wrap 4 individual posts with a category id of 3 into two individual divs i.e

<div class="postContainer">
POST1
POST2
POST3
POST4
</div>

<div class="postContainer">
POST5
POST6
POST7
POST8
</div>

Am i right in thinking that this should work:

<?php query_posts('cat=3'); ?>

<?php while( have_posts() ) : the_post(); //start of the loop ?>

<?php if( $wp_query->current_post%4 == 0 ) echo "\n".'<div class="postContainer clearfix">'."\n"; ?>
<div class="postDivider">

	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

	<div class="date"><?php the_time('m.d.Y'); ?></div>

	<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
	<div class="featured-post">
	<?php _e( 'Featured post', 'twentytwelve' ); ?>
	</div>
	<?php endif; ?>
	<header class="entry-header">
	<a href="<?php the_permalink(); ?>"><img src="<?php the_field('homepage_image'); ?>" /></a>
	<?php if ( is_single() ) : ?>
	<h1 class="entry-title"><?php the_title(); ?></h1>
	<?php else : ?>
	<h1 class="entry-title">
	<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
	</h1>
	<?php endif; // is_single() ?>

	</header>

	<?php if ( is_search() ) : // Only display Excerpts for Search ?>
	<div class="entry-summary">
	<?php the_excerpt(); ?>
	</div>
	<?php else : ?>
	<div class="entry-content">
	<?php // the_content('Read on...'); ?>
	<?php the_excerpt(); ?>

	<?php $this_post = $post->ID ?>
	<?php the_secondary_content('Excerpt', $this_post); ?>

	<a class="permalink" href="<?php the_permalink(); ?>">MORE ></a>

	<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>

	<div class="thelinks"><a href="?page_id=13">FASHION</a> / <a href="?page_id=11">TRAVEL</a> / <a href="?page_id=10">VIDEOS</a></div>

	<div class="socialmedia clearfix mAuto">
	<a class="addthis_button_twitter"></a>
	<a class="addthis_button_facebook"></a>
	<a class="addthis_button_pinterest_pinit"></a>
	</div>
	</div>
	<?php endif; ?>

	</article>

</div>
<?php if( $wp_query->current_post%4 == 3 || $wp_query->current_post == $wp_query->post_count-1 ) echo '</div>'."\n"; ?>
<?php endwhile; //end of the loop ?>

Thanks in advance.

say_what on "Pagination problem"

$
0
0

I have two custom rewrite rules:

add_rewrite_rule('foo/bar/?', 'index.php?post_type=foo', 'top');
add_rewrite_rule('foo/bar/([a-z]+)/?',
'index.php?post_type=foo&bar=$matches[1]', 'top');

Which gives me posts that match a custom variable bar. However, I want to handle pagination too, thus when a number succeeds /bar/ wordpress should treat it as a page number. I wrote:

add_rewrite_rule('foo/bar/([0-9]+)/?',
'index.php?post_type=foo&paged=$matches[1]', 'top');

In my custom function which is attached to pre_get_posts, I process the page number:

if($query->get('paged')) {
    $query->set('paged', intval($query->get('paged')));
}

However, when user accesses, say, foo/bar/2, wordpress automatically appends /page/2/, e.g. in the address bar I get the following url: foo/bar/2/page/2/.

Although the pagination itself works fine (I get the desired records as expected for each page) this /page/n/ messes up my links on the page and it is an unnecessary duplication in my url. How can I get rid of it?

johanrg on "portfolio"

2olive on "Get post meta to show in admin"

$
0
0

Hi all.
I'm writing a plugin for a swimming team. I have two custom post types (swimmers and competitions) with their respective meta box.
The titles of those CPTs are the athletes' name and the competitions' name.
I've created a custom table to insert the time for each athlete in each competition. I followed this tutorial
http://mac-blog.org.ua/wordpress-custom-database-table-example-full/

In a previous version of the plugin I had to input all data (name of competition, name of athlete and time) in this last table.
Now I'm trying to get the data already saved and show them in the admin page.
I'm able to show the name of competitions with this code

<td>
 <?php
   $selected = 0;
   $post_type = 'competitions';
   $post_type_object = get_post_type_object($post_type);

   $posts = get_posts(array('post_type'=> $post_type,'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1, 'order' => 'ASC', 'orderby' => 'title' ));

  echo '<select name="name" id="name" style="width: 95%">';

  foreach ($posts as $post) {
    setup_postdata( $post );
    echo '<option value="', $post->ID, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>';

   $selected = $post->ID;
}
  echo '</select>';
?>
</td>

if ($selected)
   $item['comp_date'] = get_post_meta( $post->ID, '_comp_data', true );
<td>
  <input id="comp_date" name="comp_date" type="date" style="width: 95%" value="<?php echo esc_attr($item['comp_date']); ?>"          size="50" class="code" ?>">
</td>
...
<?php wp_reset_postdata(); ?>

I can retrieve the post meta (in this case the date of the competition) but if I select another one, this data remains the same. How can I fix this issue? How can I update the data? I try to explain myself with an example:

In the admin page for the custom table
I select competition 1 so
date field is populated with date for competition 1
pool field is populated with pool of competition 1

If I select competition 2
date field is populated with date for competition 2
pool field is populated with pool of competition 2

but all I get is
Select competiton 2
date field is populated with date for competition 1
pool field is populated with pool of competition 1

Anyone can help?
Thanks in advance

Viewing all 8245 articles
Browse latest View live




Latest Images