imscissors
Forum Replies Created
-
Forum: Hacks
In reply to: Taxonomy-related posts in single.phpOkay.. before I go any further I need to clarify something with you.
Can you just give me a example case which would be your ideal result (ie. these are the 5 post i have, this is where i’m placing each, and this is how i’m tagging each)…
Then what your expected result would be from the case. I think I understand what you’re saying, but I want to be sure before I tell you something.
Thanks,
BryanForum: Hacks
In reply to: Taxonomy-related posts in single.phpOkay…
Why don’t you just use what I gave you, and just base your associations off of tags, since you’re already doing that.
There’s no need to query within a specific custom taxonomy if you only assign the association tag to the post you want to display. Maybe, I’m misunderstanding but here’s how I see it…
You have a post in the “clients” custom taxonomy. Now you want to associate other posts to it and use that association in a query in order to loop and display the associated posts.
The custom fields function here is to be used as sort of an anchor, and a way to set a variable to use in your query dynamically rather than hard coding it.
So John Smith is in the “clients” taxonomy. You want to display all works from John Smith in the sidebar. On this post you set the association custom field, which will be pulled, set as a variable, and used in the query.
It doesn’t matter what custom taxonomy the other posts fall in, because you’re only linking them by tag. You don’t really need to limit them by custom taxonomy.
So now you would tag all his works (the posts) with the same association tag (an actual tag, not a custom field – the cf is only set on the “anchor” post).
The custom field would be pulled from the post about John Smith used to query all the posts, and return only ones with a tag matching the association tag.
I think this accomplishes the same thing, no? I can see your point if your reluctance is having to set the custom field on the anchor post, and would rather be rid of it, but then there is not a way I can see to make the query dynamic (changing with every new anchor post and displaying the relevant items in the loop).
Let me know if I’m missing something… Also, check out this post by Justin Tadlock:
https://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database
Cheers,
BryanForum: Hacks
In reply to: Taxonomy-related posts in single.phpFcarthy,
So if I understand you correctly, you want to query for all post within a specific custom taxonomy and that has a specific tag… that right?
Forum: Hacks
In reply to: Taxonomy-related posts in single.phpPs.. one small drawback. I’ve found this doesn’t work if the association tag you use has a space in it. You see I used MarkPainterguy as the tag.
Does anyone have a solution for this? I haven’t really looked into it all that much because it’s not so important for my use, but for an end user being able to use tags that include spaces as the association tag would be ideal.
Bryan
Forum: Hacks
In reply to: Taxonomy-related posts in single.phpHey,
Ok… I think I’ve got a pretty good solution for you, that works very well. This is something I recently coded for a project I’m working on and it works like a charm and works off tags as you’d like (and supports multiple tagging as well as wordpress conditional tagging like tag1+tag2, etc)…
Step 1 is to create a custom field with a key and a value. Obviously the key will be the same for every post, the value will change based on association.
I’m using custom meta boxes to define the custom field, but it’s not necessary, unless you want to. You can of course create the appropriate custom field from the post edit page.
So we have a post “Mark Painterguy” and we want to add a list of all his paintings (for which we’ve created posts as well) in the sidebar on this post.
On that post I’m going to define a custom field(global_association_tag) as ‘MarkPainterguy’.
Ok post, define custom global_association_tag as MarkPainterguy
Now we need a quick function to grab custom field values anywhere on the post’s page. Here that is:
// Grabs custom field data and displays/true or doesn't display/false function get_custom_field($key, $echo = FALSE) { global $post; $custom_field = get_post_meta($post->ID, $key, true); if ($echo == FALSE) return $custom_field; echo $custom_field; }
So in your sidebar theme file, to output the custom key for global_association_tag, call the function:
<?php get_custom_field('global_association_tag', true); ?> //outputs: MarkPainterguy as set in custom field
Now just for your info you can set this to just grab the data but not output it by changing true to false (or leave out the argument entirely).
Now you want to set the custom field value to a variable like:
<?php $globalAssociationTag = get_custom_field('global_association_tag'); ?>
Now that you have the custom field set as a variable you can use it in a query like this:
<?php //query all post by association tag(s) $the_query = new WP_Query('showposts=99&orderby=desc&tag='.globalAssociationTag); //If there are any posts with that tag... <?php if ($the_query->have_posts()) { // Then do this while there are post... while ($the_query->have_posts()) : $the_query->the_post(); ?> // Some loop code... <h2>Paintings from this Artist</h2> <h3><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3> <div class="excerptText"> <?php my_content_limit('125'); ?> </div> <?php // end while statement and reset the loop... <?php endwhile; wp_reset_query(); // If there are no posts... <?php } else { ?> <!-- Do what you want here... either display nothing or like a heading then a message "there are no paintings for this mofo on our site yet..." --> <?php } ?>
Now of course, for all the paintings your have for Mark Painterguy, add a tag that matches your global association tag. In this case, “MarkPainterguy”.
The query will pick up all posts with his paintings automatically and display them, or if there are none, do whatever you want.
Ok, one more bit. I used a function my_content_limit for the excerpt -it just has one argument which is the number of characters. I set it to 125 in the example.
Here’s the code for the function:
<?php # My Custom Content Excerpts function my_content_limit($max_char, $more_link_text = '', $stripteaser = 0, $more_file = '') { $content = get_the_content($more_link_text, $stripteaser, $more_file); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = strip_tags($content); if (strlen($_GET['p']) > 0) { echo ""; echo $content; echo " [...]"; } else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) { $content = substr($content, 0, $espacio); $content = $content; echo ""; echo $content; echo " [...]"; } else { echo ""; echo $content; } } ?>
If I’ve understood what you need correctly, you should be set with what I’ve given you. Or at least be able to work off it to make it work for you.
Hope this helps…
Cheers,
BryanForum: Hacks
In reply to: Partial solution to showing single post for a termHey Richard,
Nice… Bookmarked this. This will come in very handy for a project I’m working on right now.
Thanks,
BryanForum: Hacks
In reply to: Display (this) Based on Multiple Cat IDs from User Input (widget options)Xephan,
Nice! That did it… For anyone’s future reference, here’s the code:
$multiCategories= $gaw_placebymcat; // move into usable array $multiCategoriesArray=explode(',',$multiCategories);
Then the condition:
//if this field has an input... if ($gaw_placebymcat != '') { //if the current cat matches one of the user input cat id's... if (in_category( $multiCategoriesArray) ) { // execute this... include ('the-widget-code.php'); } }
Btw, thanks for the tips about for capitalization. Do you have a resource handy as sort of a guide to “clean coding”… Would love to have that.
Thanks again bro,
Bryan
Forum: Hacks
In reply to: wp_dropdown_cat and a html formHello,
Ok wait.. You don’t need put that inside a variable. If all you want your plugin to do is display that form, then just call your function. So…
Create a plugin file as normal, in which you would place your code:
function output_my_form(){ ?> <form class="form" id="form" method="POST"> <!-- some form code here --> <input type="submit" value="send" name="sendit" />'; }
Then anywhere in your theme files call the function:
<?php output_my_form(); ?>
I know that code will at least output the form, but as far as entering stuff into the database, that’s a whole other thing. I believe I’ve addressed your main issue here though.
Let me know…
Cheers,
BryanForum: Hacks
In reply to: Help with nested loops please!Here’s an example from one of my sites, PromotedProfits that may be useful. I don’t think this is exactly what you’re looking for and it seems Mark has helped you, but you could use it in the future.
On the homepage, in the sidebar here https://promotedprofits.com you see “featured marketers” and then another nested loop to show the most recent product review for that person (associated by tag).
So the structure is:
Featured Marketers
———————
Person’s name (permalink)
Excerpt
Latest Person’s Name Review (heading)
Product name (permalink)Here’s the code:
https://wordpress.pastebin.com/MZh3pbqG
Hope you get some use out of this…
Cheers,
BryanForum: Hacks
In reply to: GPL Allows me to modify a Plugin and Redistribute?You just have to keep the GPL license, which means anyone can modify and distribute your version as well. Otherwise GPL is essentially worthless. ??
Forum: Plugins
In reply to: Display (this) Based on Multiple Cat IDs from User Input (widget options)Hello,
After another 5 hours of searching I’ve still not found a solution here. My head is spinning, testing different things. I just need to know if I’m on the right track and maybe a little nudge.
Can anyone help me out?
Thanks,
Bryan