WordPress.org

Ready to get started?Download WordPress

Forums

BP My Home
[resolved] need custom work (58 posts)

  1. deepbevel
    Member
    Posted 3 years ago #

    imath,

    I'm looking to have something made that allows inserting multiple existing posts into a new single post from the front end. Im using shortcode right now, the user can copy and paste it into a new post and it seems easy enough to me, but my client really wants a "click button to add to your post" which will accomplish the same.
    The goal is for the user to assemble custom travel itinerary from a selection of locations. I would be glad to concider any alternative methods which could accomplish this.

    I tried your shortcode plugin but it won't work for me because it only works in a forum. The travel itinerary is premium content and the user posts have to be private, or in a private category. The original itinerary posts are protected files (S2 Memeber).

    Please let me know if you might be interested, or could perhaps refer me to someone. I've explored literally over 100 plugins and nothing can do what I need.

    Thanks

    http://wordpress.org/extend/plugins/bp-my-home/

  2. imath
    Member
    Plugin Author

    Posted 3 years ago #

    Ok,

    If i were you, i'll try to adapt this exemple to your needs...

    in single.php i add this code before the comment template :

    <div class="copy-paste">
    	<input type="hidden" id="copy-paste-shortcode" value="[shortcode postid='1']">
    	<a href="javascript:void(0)" title="copy this post content">copy this post content</a>
    </div>

    then in functions.php, i add this code :

    function imath_copy_paste(){
    	if(is_single()){
    		?>
    		<script type="text/javascript">
    			jQuery('.copy-paste').click(function(){
    				var shortcode = jQuery(this).find(":first").val();
    				jQuery("#comment").val(jQuery("#comment").val()+shortcode);
    			});
    		</script>
    		<?php
    	}
    }
    
    add_action('wp_footer','imath_copy_paste');

    Then if i display a post, when i click on the link the comment form is filled with [shortcode postid='1']

  3. deepbevel
    Member
    Posted 3 years ago #

    Wow, thanks! I'm really excited to try this. I'll let you know how it goes. You're a great help.

  4. deepbevel
    Member
    Posted 3 years ago #

    I tried it and of course it worked just like you said. However I probably didn't communicate very well that it needs to be for many different posts. If I applied your solution correctly, it appears that it would always be the same shortcode copied into the comment feild?

    My project involves what will be hundreds of posts, each being travel itinerary for a specific travel location. Each location-post could be as many as 10 pages. The user is supposed to be able to select as many as 5 or 6 locations, and combine them in such a way that they can be downloaded as a single pdf.

    I figured blogging software could be a good way to approch it, and it works great simply providing shortcodes for the user to paste into a post and get 30 or 40 pages of selected content. However my client is stuck on wanting a button function that copies the content into the new post automatically. I just don't see how I can do that.

    But thanks so much just the same, I think I may have to just give up and tell my client we simply have to settle for my current solution. Seems we're going to a lot of trouble for those few users who can't copy and paste!

  5. imath
    Member
    Plugin Author

    Posted 3 years ago #

    well, you can do a query_posts() outside of the loop and display boxes with a picture from the post and a button/link to add the content into the textarea. Using my example you simply have to make a foreach and then under the pic, you would have something like this :

    <div class="copy-paste">
    	<input type="hidden" id="copy-paste-shortcode" value="[shortcode postid='<?php echo $post->ID;?>']">
    	<a href="javascript:void(0)" title="copy this post content">copy this post content</a>
    </div>

    nothing is impossible, it just takes longer ;)

  6. deepbevel
    Member
    Posted 3 years ago #

    Thanks, I tried it, but I can only add code for specific content if the code is added to a single post or page. I tried that but it only shows the code, so I assume this is supposed to go in functions.php or something. Then I realized you said I have to "query posts" and make a "foreach" which I would'nt understand how to set up, or even where to set it up.

    I did look into it but there's too much of the language I don't understand, I'd have to back up and start from the begining. Unfortunately I don't think I have time. I intend to learn
    this stuff a little better eventually though. You've already been very helpful in that regard.

  7. deepbevel
    Member
    Posted 3 years ago #

    Okay, the query_posts() I think I can manage, but I don't understand what the foreach actually does or why it's needed. I've been trying to read about it but the examples aren't making sence to me. Any good reference would be much appreciated.

  8. imath
    Member
    Plugin Author

    Posted 3 years ago #

    may be you can try something like this :

    <?php
    global $post;
    query_posts('cat=[cat_ID]&posts_per_page=5');?>
    <?php if ( have_posts() ) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <!-- html code -->
    <div class="small-post">
    <div class="entry">
    <h4><?php the_title();?></h4>
    <img src="<?php echo get_post_meta($post->ID,'image',true);?>"/>
    </div>
    <div class="copy-paste">
    	<input type="hidden" id="copy-paste-shortcode" value="[shortcode postid='<?php echo $post->ID;?>']">
    	<a href="javascript:void(0)" title="copy this post content">copy this post content</a>
    </div>
    </div>
    <!-- /html code -->
    <?php endwhile; ?>
    <?php else : ?>
    <!-- html code if nothing found -->
    <?php endif; ?>
    <?php wp_reset_query();?>
  9. deepbevel
    Member
    Posted 3 years ago #

    I'm not sure if I'm using it right, it's showing the links when I put it in single.php, but I don't know where it looks for the shortcde, or where I should put it so it can be copied. Is it copied to the clipboard, or is it supposed to send it to the comment field?, or another post?

  10. deepbevel
    Member
    Posted 3 years ago #

    Okay, I added to functions.php:

    function imath_copy_paste(){
    if(is_single()){
    ?>
    <script type="text/javascript">
    jQuery('.copy-paste').click(function(){
    var shortcode = jQuery(this).find(":first").val();
    jQuery("#comment").val(jQuery("#comment").val()+shortcode);
    });
    </script>
    <?php
    }
    }

    add_action('wp_footer','imath_copy_paste');

    Then I added the most recent code you gave to single.php. It copies "[shortcode postid='443']" into the comment field, but [shortcode postid='443'] doesn't produce the post content when I insert it into a new post. Even if it worked, It's still requiring the user to copy and paste, which is what I'm trying to elliminate.

    I'm confused about how it's supposed to work for my purpose, I don't understand how I can get the shortcode to show up in a new post and produce the content. If that is what you intended, I have a feeling I'm not using this right, although I wouldn't know. I'm not even sure if this is intended to be used with the previous code you gave, but it doesn't copy-paste without it the function.php code you gave me.

  11. deepbevel
    Member
    Posted 3 years ago #

    I think I figured it out, I substituted the [shortcode postid='443']
    with the actual shortcode for a plugin called "MindValley Include Post Content" so it's now [mv_include id='<?php echo $post->ID;?>' ]
    and it does indeed auto-paste the code into the comment feild, I just wish the comment field could render the shortcode! or if the code could somehow end up in U can Post, or any kind of post field.
    Even though I still have essentially the same issue I enjoy learning how to do this, pretty cool. Thanks.

  12. deepbevel
    Member
    Posted 3 years ago #

    In the code for functions.php, is there a way to substitute ("#comment") with ("#post") or ("UcanPost")
    I have UcanPost in the sidebar for single.php.

  13. deepbevel
    Member
    Posted 3 years ago #

    I installed a plugin which renders shortcode in the comments, it works! Now I really have something to work with! Heaps of Graditude to you imath.

  14. deepbevel
    Member
    Posted 3 years ago #

    I don't know what happened, I deactivated BuddyPress and reinserted the code, but now it doesn't copy anything into the comment field.
    I did a new install of WP and tried it again, but still no copy happening. Maybe it only works with BuddyPress? I'll reinstall it and try again..

  15. deepbevel
    Member
    Posted 3 years ago #

    Sure enough, now it works again. Strange, I don't understand why because WP and BuddyPress both have single.php and functions.php.
    Anyway at least I can now continue to ponder how this might work for my purpose.
    I have a map of the U.S. I made in Flash. When you click a state, a box appears over the state with a list of all the travel locations in that state. When you click a location name in the list it opens a link to a post with itinerary for that location.
    I need a similar way to organize the posts, so users can reference a single post and still copy it's contents into a field along with the content of other posts. But how can I link to a single post which is being called in a query? It seems the query is what enables the copy-paste code to work. I'm stummped!

  16. deepbevel
    Member
    Posted 3 years ago #

    I actually found a plugin that claimed to put all comments together on a page, and it does, the only catch is the comments have to be made through a widget, and not the ussual comment field where my shortcode gets pasted!

    ever get the feeling all plugins are designed to do everything except what you need them to do? It's a conspiracy I'm sure!

    I think I've been going at this too long, I'm going for a run.

    If you care to take a peek, it's a WP install specificlly for the purpose of figuring out this issue. The only plugins are

    MindValley Include Content (page/post shortcode I'm using with your code.)

    Shortcode Exec PHP (makes PHP work in comments)

    WP Wall (shows most recent comments on a page, but only if they are made through a widget.)

    http://www.foursticks.net/TravelBlog1000/

  17. deepbevel
    Member
    Posted 3 years ago #

    I Found another plug that puts recent comments on a page, So now I'm wondering if I can apply some kind of privacy thing so the current comment author can only see their own comments. That way the current author comments will always be the most recent. ?

    Then I may be able to figure out how to get your copy-paste link to show up for the current single post, and not use the query. All the comments (copied content) would be under different posts, but they would also show up together on the comment page. From there, they should be able to be downloaded as a single PDF. I hope!

    Couldn't have gotten this far without you, I can't thank you enough!

  18. imath
    Member
    Plugin Author

    Posted 3 years ago #

    Hi deepbevel,

    1/ why the javascript code stopped working when you deactivated BuddyPress ?
    -> Because BuddyPress enqueues jQuery and twentyten doesnt

    2/ The snippet i gave you was a quick example to show you how you can paste content into a field. And i took an example using single.php and the comment field. But you have to adapt this to your need. If you need to write a new post with the content of other posts from the front end, then you first need to have a form that makes it possible to post from the front end. For instance tdo-mini-forms.

    3/ If tdo mini forms is used, then when you create a form with it, you will have a page with a form and the fields you configured in tdo backend. Let's imagine one of the field is the content field of the new post. It will be a textarea, check the name and id of it in the page tdo mini form created. If no id were put by tdo you can hack the form adding one from the tdo backend. Let's say the id of this field is "tdo-new-post-content".
    So we have a page containing a form that enables you to add new post from front end. Let's say this page has this title : "Example"

    4/adding js scripts when the page "Example" is loaded : in functions.php of your active theme.
    4.a making sure jquery is enqueued :

    function make_sure_jquery_is_loaded(){
    	if(is_page("Example")){
    		wp_enqueue_script('jquery');
    	}
    }
    add_action('get_header','make_sure_jquery_is_loaded');

    4.b adding the "copy paste" function

    function imath_copy_paste(){
    	if(is_page("Example")){
    		?>
    		<script type="text/javascript">
    			jQuery('.copy-paste').click(function(){
    				var shortcode = jQuery(this).find(":first").val();
    				jQuery("#tdo-new-post-content").val(jQuery("#tdo-new-post-content").val()+shortcode);
    			});
    		</script>
    		<?php
    	}
    }
    
    add_action('wp_footer','imath_copy_paste');

    As you can see i replaced #comment by the id i expect in tdo mini forms (tdo-new-post-conten)

    5/ adding the list of post contents. As tdo mini forms uses a shortcode to add its form to the page example, maybe the best way is to use a specific template for the page. in your theme you can copy the content of "page.php" into a new file "post-from-content.php" making sure the header of it looks like this :

    <?php
    /*
    Template Name: post from content
    */
    get_header(); ?>

    Go back to WordPress BackEnd and edit the Example page choosing the template 'post from content'.

    Now you can edit the page template post-from-content.php by adding this code just after the div with id content and role main (if you're using twentyten) :

    <div id="list-posts">
    	<?php
    	global $post;
    	query_posts('cat=[cat_ID]&posts_per_page=-1');?>
    	<?php if ( have_posts() ) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    		<div class="small-post">
    			<div class="entry">
    				<h4><?php the_title();?></h4>
    			</div>
    			<div class="copy-paste">
    				<input type="hidden" id="copy-paste-shortcode" value="[deepbevel_need postid='<?php echo $post->ID;?>']">
    				<a href="javascript:void(0)" title="copy this post content">copy this post content</a>
    			</div>
    		</div>
    	<!-- /html code -->
    	<?php endwhile; ?>
    	<?php else : ?>
    		<!-- html code if nothing found -->
    	<?php endif; ?>
    	<?php wp_reset_query();?>
    </div>

    You can replace [cat_ID] with the id of the category of the posts you want to copy. When you now open the page example, you have the list of posts over the form (add some style to make them display horizontally).

    6/Handling 'deepbevel_need' shortcode
    If you begin use it, you will be able to paste shortcodes into the textarea. But if you submit a new post and display it then you wont have the content of the posts, so you need to tell WordPress what to do when it finds your shortcode. To do that simply go back to functions.php and add this code :

    function deepbevel_need_handle_shortcode($atts){
      extract(shortcode_atts(array('postid' => '0'), $atts));
      query_posts('p='.$postid);
      ?>
      <div class="copied-post-container">
      <?php
      if ( have_posts() ) : while ( have_posts() ) : the_post();
      ?>
        <h5><?php the_title();?></h5>
        <?php the_content();?>
      </div>
      <?php endwhile; else:?>
      <b>no post found</b>
      <?php
      endif;
      ?>
      </div>
      <?php
      wp_reset_query();
    }
    
    add_shortcode('deepbevel_need', 'deepbevel_need_handle_shortcode');

    Now you should see the post contents you copied in your new post. Hope it helped, have fun ;)

  19. deepbevel
    Member
    Posted 3 years ago #

    Okay, I have it all set, however the shortcode is not showing up in the form when I click the link. I think I may have not named the form page correctly, I'm not sure if you mean the actual name of the page, the slug, or if I need to use the id #. Also not sure about the syntax for adding the post category, do I include the brackets?

    I'll try some different things and see if I can get it to work.

  20. deepbevel
    Member
    Posted 3 years ago #

    this is how I did the category in the post-form-content.php:

    <div id="list-posts">
    <?php
    global $post;
    query_posts('cat=1 &posts_per_page=-1');?>

    and this is how I modified functions.php:

    <?php
    function make_sure_jquery_is_loaded(){
    if(is_page("default-form")){
    wp_enqueue_script('jquery');
    }
    }
    add_action('get_header','make_sure_jquery_is_loaded');

    function imath_copy_paste(){
    if(is_page("default-form")){
    ?>
    <script type="text/javascript">
    jQuery('.copy-paste').click(function(){
    var shortcode = jQuery(this).find(":first").val();
    jQuery("#42").val(jQuery("#42").val()+shortcode);
    });
    </script>
    <?php

    I'm not sure how to know if I have the post form name and id right, or I'm not clear on which goes where. The post form page url is:

    http://www.foursticks.net/TravelBlog1000/wp-admin/post.php?post=42&action=edit

    so I assume the id is 42?

    the slug is "default-form" so I assume that's the name?

    still, when I use the above everything looks like it should, but the shortcode does not get added into the form when the link is clicked.

    Also, I'm still a bit concerned that this won't work for me, since it appears I still have to show a page with all the posts together on the same page as the form. Is this correct? If so, is it possible to use the form as a widget so it can show up with any single post, and allow that post shortcode to be copied to the widgetized form?

  21. deepbevel
    Member
    Posted 3 years ago #

    I just realized I don't see where the java scrit is getting the shortcode from, I don't know if I'm supposed to supply it or if so, where?

    And although I followed your instructions and made the page templatefor the post form, I don't know why I need it, I don't inderstand how it allows the post content to be displayed, don't all posts show on the front page unless you do something to prevent it?

  22. deepbevel
    Member
    Posted 3 years ago #

    this is the code for what appears to be the id and name for the form, I tried what appeared obvious 'tdomf_form%%FORMID%%' but it didn't work, possibly because I don't know if I have the syntax right. Do I still include the ("#")

    <!-- Form 1 start -->
    %%FORMMESSAGE%%
    <!-- form start -->
    <form method="post" action="http://www.foursticks.net/TravelBlog1000/wp-content/plugins/tdo-mini-forms/tdomf-form-post.php" id='tdomf_form%%FORMID%%' name='tdomf_form%%FORMID%%' class='tdomf_form' >
    %%FORMKEY%%
    <div><input type='hidden' id='tdomf_form_id' name='tdomf_form_id' value='%%FORMID%%' /></div>

  23. deepbevel
    Member
    Posted 3 years ago #

    Yeah, I can't really proceed unless I know how to id the form and it's page, I've tried everythng I can think of, maybe something else is wrong? then maybe its just a matter of syntax, I always have trouble getting info about TDO mini forms, the forum is mostly just a lot of unresolved issues and no answers. I looked at the form hacker but I can't determin how my changes should be entered, there's too many name and id entries, I'm not sure which I need or which does what.

    One thing I'm definately uncertain of is if I should be using BuddyPress, you said default WP doesn't use jquery so I reinstalled BuddyPress, everything still shows up, but still nothing getting copied into the form, just like with 2010.

  24. imath
    Member
    Plugin Author

    Posted 3 years ago #

    I think you're close to make things work ;)

    The id to look for is the one of the textarea in the form (the one that will be added as the post content), so not the one of the form (not #tdomf_form1).

    Go to the hack menu of tdo and search for a textarea then get its id and replace #tdomf_form1 by the id of the textarea in imath_copy_paste()

  25. imath
    Member
    Plugin Author

    Posted 3 years ago #

    ok i registered to your blog in order to see the source code of the form. Waiting to get the activate link by email, then i'll tell you the id to use.

  26. imath
    Member
    Plugin Author

    Posted 3 years ago #

    well i'm not getting the email... sorry cant help you further :(

  27. deepbevel
    Member
    Posted 3 years ago #

    I set your password, hopefully you'll check it out. So far so good. I noticed that when I remove the form shortcode from the page, the widget becomes the activ post field. As you might guess I'm hoping I can show your copy-paste code on multiple pages. Each page would be one of the U.S. states, and have only that states' locations as posts. I'm trying to think about what that would involve concerning the existing code..I suppose there would be no need for a post query, but I have to do something about the "if" that looks for the form page before enabling jquery. I guess I'd need it enabled all the time?

  28. deepbevel
    Member
    Posted 3 years ago #

    I've got it set so the posts go to the widget

    How can I expand your functions.php code to include other pages besides "default-form"?

    <?php

    function make_sure_jquery_is_loaded(){
    if(is_page("default-form")){
    wp_enqueue_script('jquery');
    }
    }
    add_action('get_header','make_sure_jquery_is_loaded');

    function imath_copy_paste(){
    if(is_page("default-form, state-2")){
    ?>

    there's going to be 50 pages , one for each state. Each state has it's own specific post-locations, so the location posts which get copied and pasted will be in 50 different categories, each category specified in the code for it's corrosponding page template. At least thats my evil plan.

    I tried simply adding the other page, like this:

    if(is_page("default-form, state-2")){

    but it doesn't work like that.

    like I said above, the "state-2" page has its own template so it can show the category with posts for that state. All the states will have their own page template.

    This is getting good!

  29. deepbevel
    Member
    Posted 3 years ago #

    All I did was remove the page name for the form in your functions.php code. The copy-paste still associates with the pages that use the custom page template, so it appears to be all good!

    However I have some kind of bug where the sidebar becomes unusable on the pages where TDO posts appear. I used a plugin to keep the form from showing up on pages that display it's posts, but there's still something wrong with the sidebar.

    I'd have a seperate form on each page, but that would create an issue with the text field id as specified in the functions.php code.

    I may just try a different plugin for hiding the widget where ever it's posts appear.

  30. imath
    Member
    Plugin Author

    Posted 3 years ago #

    "I'd have a seperate form on each page, but that would create an issue with the text field id as specified in the functions.php code."
    then you have to add if statements in order to adapt the js to each id :

    function imath_copy_paste(){
    	if(is_page()){
    		?>
    		<script type="text/javascript">
    			jQuery('.copy-paste').click(function(){
    				var shortcode = jQuery(this).find(":first").val();
                                    <?php if(is_page("default-form")):?>
    				jQuery("#tdo-textarea1").val(jQuery("#tdo-textarea1).val()+shortcode);
                                    <?php elseif(is_page("state-2")):?>
    				jQuery("#tdo-textarea2").val(jQuery("#tdo-textarea2).val()+shortcode);
                                    <?php //elseif(is_page("and so on")):?>
                                    <?php endif; ?>
    			});
    		</script>
    		<?php
    	}
    }
    
    add_action('wp_footer','imath_copy_paste');

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags