downfast
Forum Replies Created
-
you could even hide the main category so that the user won’t see it and just display the subcats (using tag method as per the previous link)
Instead of multiple categories you could set a Main one and then use tags as sub-categories and be able to have “multiple choice for submission”, here it is my solution which may help: http://wordpress.org/support/topic/display-subcategories
Hey I was just about to clean up the code, should be ok now.
Here it is my solution:
1: In order to get sub catebories, I played around with tags and I was able to create a system where I could show only tags attached to posts within a specific category, this will act as some sort of “sub category”. In the user submit posts plugin, find the file called: submission-form.php, this is the file we’ll edit. Just below
<?php } if ($usp_options['usp_tags'] == 'show') { ?>we do the following:First: Get the cat id:
$cat=5; $yourcat = get_category($cat); if ($yourcat) { echo '<h3>' . $yourcat->name . '</h3>'; }Then we loop all tags and we output it in a list and we make sure we don’t have any duplicates:
<ul> query_posts('category_name=Ambiente'); if (have_posts()) { $allTags = array(); while (have_posts()) { the_post(); if( get_the_tag_list() ) { $tags = wp_get_post_tags( get_the_ID()); foreach($tags as $tag) { $allTags[$tag->name] = $tag; } } } foreach($allTags as $tag) { echo '<li><input class="checkTag" type="checkbox" value="' . $tag->name . '" />' . ' ' . $tag->name . '</li>'; } } wp_reset_query(); ?> </ul>Just repeat this for all your category and change the category id.
Note: I am using:
echo '<li><input class="checkTag" type="checkbox" value="' . $tag->name . '" />' . ' ' . $tag->name . '</li>';Display a list of tags based on category and have a checkbox next to each tag, this is because I am saying to the user: “Hey look all tags already created for each category, maybe you find one you like, if so, check it and the input field for the tag will be automatically populated.
Using this jQuery in the footer to be able to automatically insert in the tag input field the same as what it is writtent next to the check box:
$('.checkTag').click(function() { $("#user-submitted-tags").val( $('.checkTag:checked').map(function() { return $(this).val(); }).get().join(', ') ); });With that, the selected checkbox will populate the tag input field, you can select multiple checkboxes too, and the tags will be written in the input field with a comma for multiple tags selection.
Note: There maybe tons of tags (subcategories), so what I did was to insert a link “Check all existing sub-categories => click > a pop up opens with all the lists. In my case I have used bootstrap3 modal
If the user wants to create a new sub-category (a tag), they won’t select any checkbox and can simply write it in the input field as normal:
<input name="user-submitted-tags" required id="user-submitted-tags" data-required="true" type="text" value="" placeholder="Scrivi la sottocategoria" class="form-control input-lg usp-input">Careful to the classes I have used as these are used in the jQuery bit too.
Done! Now we treates tags as some sort of sub category.
—
The authors:
The plugin is great and you don’t need to register, which means the posts will be written with whatever name you provide but actually wordpress thinks they are written by the admin with just a differnt name. So What I had to do was to get the author name and with the following I am able to:
1: Get the author and display all posts made by it
2: Get the total number of posts the author made
3: Get a link to each posts it made<ul> <?php $args= array( 'posts_per_page' => -1 ); query_posts($args); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li> <?php $args = array( 'posts_per_page' => -1, 'meta_key' => 'user_submit_name', 'meta_value' => get_the_author(), 'meta_compare' => '=' ); $myquery = new WP_Query($args); echo '<h3>' . $myquery->found_posts . ' proposte da ' . get_the_author() . '</h3>'; while ( $myquery->have_posts() ) { $myquery->the_post(); echo '</li> <li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li> '; } ?> <?php wp_reset_postdata(); ?> <?php endwhile; ?> <?php endif; ?> </ul>Done!
The last bit I will do is to ask the user to insert their name and I will attach a random unique string, then tell the user to always use that username when posting in order to not have duplcate username and therefore be able to really show all posts made by 1 author.
e.g.
User 1 says: My name is => Simon, and he writes a post
User 2 says: My name is => Simon, and he writes a post.As we can see they are 2 users using the same name, which makes it impossible di distinguish the 2 different authors.
The solution I am thinking is as I said, create a unique string which will be attached to the Name provided by the user, and just tell them to always use that username when posting. E.g.
simon_uniquexyz
simon_uniquegtdI hope this will help someone.
Forum: Fixing WordPress
In reply to: Show only unique tagsThe solution
<ul> <?php query_posts('category_name=YOU CAT NAME'); if (have_posts()) { $tags = array(); while(have_posts()) { the_post(); if(get_the_tag_list()) { foreach(wp_get_post_tags(get_the_ID()) as $tag) { $allTags[$tag->term_id] = $tag; } } } foreach($tags as $tag) { echo '<li><input class="checkTag" type="checkbox" value="' . $tag->name . '" />' . ' ' . $tag->name . '</li>'; } } wp_reset_query(); ?> </ul>Hi Jeff. Thanks.
What about the authors thingy?
What does involve custom coding? Is it a paid support request?
I have kinda solved the categories and sub categories issue with some tags workaround tho.With authors I mean have a page with the list of all people who have wrote a post with perhaps the number of their posts in brackets e.g.
Etc
Using wp default won’t work as the post submitted users are not actual wp users
http://codex.wordpress.org/Function_Reference/list_authorsForum: Hacks
In reply to: Find post id by a tagSolution:
<ul> <?php query_posts('category_name=Ambiente'); if (have_posts()) : while (have_posts()) : the_post(); if( get_the_tag_list() ){ echo $posttags = get_the_tag_list('<li>','</li><li>','</li>'); } endwhile; endif; wp_reset_query(); ?> </ul>Forum: Hacks
In reply to: Find post id by a tagOk how do I find the categories of this posts?
Basically I am using the plugin: http://wordpress.org/plugins/user-submitted-posts/
In the form you can insert a tag; this tag is attached to a post.
I am using the following and it works but if i duplicate the code below and I change the cat id in order to have all the tags within various categopries where the tags are used, it repeats the same tags for all categories.
<?php $cat=5; $yourcat = get_category($cat); if ($yourcat) { echo '<h3>' . $yourcat->name . '</h3>'; } $args = array( 'categories'=> '5' ); $tags = get_category_tags($args); $content .= "<ul>"; foreach ($tags as $tag) { $content .= "<li><a href=\"$tag->tag_link\">$tag->tag_name</a></li>"; } $content .= "</ul>"; echo $content; ?>Forum: Hacks
In reply to: Find post id by a tagThanks but I know how to find an ID, what I am asking is:
If i give a tag to a post, how can I find this post id by querying its tag?
Forum: Plugins
In reply to: Gd Star Rating: Show only total number of votes in a articleHi thanks but I am using http://wordpress.org/plugins/gd-star-rating/
Any idea?
On another note, Is there a possibility to display authors using wp authors? I understand they are not users but is it there any other way?
Thanks
Forum: Fixing WordPress
In reply to: How to get parent content?I had to use global $post;
Final code:
<?php global $post; $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->post_parent, 'order_by' => 'menu_order', 'order' => 'ASC' ); $attachments = get_posts($args); if ($attachments) { echo '<div id="gallery-1" class="gallery galleryid-3105 gallery-columns-5 gallery-size-thumbnail">'; foreach ($attachments as $attachment) { echo '<dl class="gallery-item">'; echo '<dt classs="gallery-icon">'; $large = wp_get_attachment_image_src($attachment->ID, 'large'); $thumb = wp_get_attachment_image($attachment->ID, 'thumbnail'); echo '<a href="' . $large[0] . '" rel="shadowbox[sbalbum-3105];player=img;">' . $thumb . '</a>'; echo '</dt>'; echo '</dl>'; } echo '</div>'; } ?>Forum: Fixing WordPress
In reply to: How to get attachments of parent page only with query_posts ?I had to use global $post;
Final code:
<?php global $post; $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->post_parent, 'order_by' => 'menu_order', 'order' => 'ASC' ); $attachments = get_posts($args); if ($attachments) { echo '<div id="gallery-1" class="gallery galleryid-3105 gallery-columns-5 gallery-size-thumbnail">'; foreach ($attachments as $attachment) { echo '<dl class="gallery-item">'; echo '<dt classs="gallery-icon">'; $large = wp_get_attachment_image_src($attachment->ID, 'large'); $thumb = wp_get_attachment_image($attachment->ID, 'thumbnail'); echo '<a href="' . $large[0] . '" rel="shadowbox[sbalbum-3105];player=img;">' . $thumb . '</a>'; echo '</dt>'; echo '</dl>'; } echo '</div>'; } ?>Forum: Fixing WordPress
In reply to: Custom post thumbnails not using custom sizesThe issue was with the height of one image not been more or equal as per what i’ve defined, nice to know and thanks!
Basically if your featured image does not have at least the height you supply in the custom post thumb size, it will automatically find the correct proportional height according to its width (yet I assume you’d have the same issue with the width if you define a bigger one than what the actual image has).
To be honest I would have expect it to stretch. Haven’t read or found anything about this specification anywhere, should be pointed out somewhere in codex.
Thanks tho 😉