Forum Replies Created
-
AuthorPosts
-
November 15, 2013 at 8:15 pm in reply to: Custom Post Types in Category Archive Loop and Standard Blog #73331
Lord_Devi
ParticipantOk! I actually figured this one out just now!
Pretty cool actually. I have to say I am rather excited about picking up on this Custom Post Type stuff, and I love how easy Genesis is making this whole learning process for me.
So I went through the following two pages, rather forcing myself to not just read, but to try and make sense of the data there! Which isn't exactly that easy for someone just picking up PHP.
http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
and
http://codex.wordpress.org/Class_Reference/WP_Query
Just noticing a pattern with how
if ( is_tag() && $query->is_main_query()
was structured, and comparing that with the examples found under the pre_get_posts link I posted above, using the Proprties found on the WP_Query page above, I tried to just hack the properties in and lo and behold my custom post type was appearing on both my Category Archive Loop, and my Home Loop.I ended up using the two following pieces of code initially to get my custom post types posting to my other archive loops:
For adding CTP 'review-epilator' to Category Loop:
function review_epilator_to_category_loop( $query ) { // we don't want this running on the admin side if ( is_admin() ) return; // include our stream type on tag pages if ( is_category() && $query->is_main_query() ) { $query->query_vars['post_type'] = array( 'post', 'review-epilator' ); return; } } add_action ( 'pre_get_posts', 'review_epilator_to_category_loop' );
For adding CTP 'review-epilator' to Home Loop:
function review_epilator_to_home_loop( $query ) { // we don't want this running on the admin side if ( is_admin() ) return; // include our stream type on tag pages if ( is_home() && $query->is_main_query() ) { $query->query_vars['post_type'] = array( 'post', 'review-epilator' ); return; } } add_action ( 'pre_get_posts', 'review_epilator_to_home_loop' );
So the three I've pasted so far DID indeed add the functionality I was looking for. However I try to minimize code where I can so I tried to group the 3 separate functions I pasted above into the following single function:
function review_epilator_to_archive_loops( $query ) { // we don't want this running on the admin side if ( is_admin() ) return; // include our stream type on tag pages if ( is_tag() && $query->is_main_query() ) { $query->query_vars['post_type'] = array( 'post', 'review-epilator' ); return; } // include our stream type on category pages if ( is_category() && $query->is_main_query() ) { $query->query_vars['post_type'] = array( 'post', 'review-epilator' ); return; } // include our stream type on home page if ( is_home() && $query->is_main_query() ) { $query->query_vars['post_type'] = array( 'post', 'review-epilator' ); return; } } add_action ( 'pre_get_posts', 'review_epilator_to_archive_loops' );
And it also works great! So I got everything I needed, and a nice small little function that will make it very easy for me to add new CTPs to my archive pages with later! SO EXCITING!
So my only remaining question before I mark this thread as solved (I'll wait a while before I close it), is does anyone have any input about my compiled function above?
Are there any reasons I should not group these three functions into just the one above?
Is there any better or more efficient way of writing this function?
Lord_Devi
ParticipantHaha... Yeah.. Well BASH scripting is a bit of old obsession. I'm a bit of a control freak. =) (Or power user if you prefer. 😉
Used to spend days working on little scripts just to help automatically encode video files, organizing images.. all sorts of silly little tasks. I've learnt something about that though... There is ALWAYS a way to improve a script =)
Anyway, just taking a quick look at your svn => wp plugin installer, looks pretty clean to me! You certainly code in an easy to understand manner, I love that.
The only comment I may have is that you allow the user to enter in custom paths and options to the script, but then do not verify them afterwards.
Does the directory they enter for the SVN path actually exist? That kinda thing.
Oh and one more item I guess is that removing the trailing slash from a user entered variable is actually pretty simple as well.
Just changing:
SVNPATH="${input:-$default_svnpath}"
to
SVNPATH="${input%/:-$default_svnpath}"
Should do it. (See Here and Here.)
Anyway yeah, I would enjoy reading those books of yours when they come out. Is there a place I can subscribe or anything to receive any updates in that regard?
And thanks again for the help! Good to know about the function cloning system. This is still way easier than what I am used to. (Used to use Joomla 😛 )
Updating the custom clone later on isn't so bad really. At least it's an easy to maintain and manage system. Especially when combined with Dynamik Website Builder. I love that particular marriage SO much!! Finally makes me feel in control of my websites.
Anyway, I don't suppose you might know of any good sites or documentation sources on learning Genesis fundamentals better? A little extra reading material perhaps...
I've looked around and I find a decent amount of snippets, everyone has a list of hooks.. But I am surprised at how difficult it is for me to find good documentation on Genesis. The closest I've found so far is by "Nick The Geek". A series titled "Genesis Explained" (Found here.)
But honestly, and no offense to nick at all for trying so hard, but I find his material very difficult to understand. =/
Thanks again GaryJ! =)
Lord_Devi
ParticipantAha ok! Yeah I thought that was what needed to be done!
I was actually just trying really hard to parse lib/structure/comments.php when I got a ping that this thread was updated. =) I admit I was having a difficult time finding exactly what part needed the replacing.
But I've been trying to go through Nick The Geek's Genesis Explained series to get a better grasp of these things, and it DID seem to me that what I needed to do was copy a function directly, an action anyway.. and then add it to my own custom function list (renaming it), and then manually changing what was there.
Trying to find my way around all this code is confusing though, I suspect it may take a bit to get right. At least I have years of Linux BASH scripting under my belt to help with the programmatic side of things!
Anyway, thank you very much for clearing up for me the
genesis_comment_form_args()
and such as well. I understand that way better now.A question though. Did you know to use the
html5_comment_callback
action just out of experience... or do you have a resource one can use to help find these actions..? -- I'm happy I was on the right track. It means I'm actually picking this up! But I am dismayed a bit at just how difficult of a time I am having finding the components I need to modify. (At least I know about the structure of lib/structure now!).And one last question if I may:
Taking an ENTIRE function, the whole action like this, and then making my own version of it.. and then creating a custom function using the entire (sometimes hefty) block of original code as the starting point
If I need to create modifications like this, that is: Taking an ENTIRE function (sometimes hefty in size), create my own custom function using the ENTIRE original function as a template, and the applying my own (perhaps 1 line at times) tweak to the entire function... am I doing it the best way?
It seems to me, if Genesis comes out with major updates or anything, I may end up having to redo this function. Or other things I can't think of. I mean, it just seems like an awfully lot of code I'm copying for just one minor change.
Thanks again for walking me through some of these little points I was missing from the available documentation again! It's helping me a ton, that's for sure!
I hope you don't mind some of the extra questions I've asked either. I've just learned from experience that it's a good idea to try and avoid NOT learning best-practice approaches the first time around. There may be many ways to skin a cat, but a lot of the time, only a few ways are correct.
P.S.: Thanks to you Garyl, my comment form's extra fields are working and exactly where I want them. My rating stars are right where I need them.. Everything is well. And I now have a much better idea about not only how to work with genesis filters and actions, and I also know enough to reliably get stuff done with all the fun API's out there I've been forced to gloss over in the past from lack of knowledge.
Thanks a ton Garyl!
August 27, 2013 at 4:31 am in reply to: Anyone have experience with Dynamik Website Builder for Genesis? #59023Lord_Devi
ParticipantI absolutely love Dynamik Website Builder myself.
I essentially have all the power of Genesis using it, but Dynamik makes a lot of things much easier for me. I'm not a fan of directly editing code if I don't have to - but I AM obsessed with keeping things clean.
With dynamik, I can take any Genesis filter snippet or any other function, and just paste it into Dynamik's back end. I change fonts site wide, add CSS to very specific places very easily. A front end css builder to make things even simpler.
A bunch of good videos on what conditionals are, and how they differ from labels - or how to use either. Yeah it just makes life way simple for me. It's the first framework / templating system I have tried for ANY cms that makes me happy.
Lord_Devi
ParticipantOk one more post here...
I have been going through comment-template.php, the WordPress codex, Genesis snippets, and I have one other related problem I am unable to solve. I was hoping that by fixing the above problem I would learn enough to fix the second issue, but it is not coming to me.
The review plugin also displays each comment's associated rating if it has one. Currently I have this assigned with a hook bound to "genesis_after_comment", but the rating is then appearing BENEATH the "reply" button, and I need it above the reply button.
I don't know if I need to use a "replace_action" function or something here or not...
But here is a picture of what the comment looks like now, and you can see how the star ratings are beneath the "Reply" link.
How can I have this appear above the Reply button?
This is the current code I am using to summon the stored rankings:
myrp_api_comments_ratings_table( $comment_id = null, $post_id = null, $return = false )
And the image of the problematic result:
Lord_Devi
ParticipantYes! That was totally it!
I logged out and it was right there where it ought to be. Phew!
Thank you so much for your help Garyl.
I was able to extract from your help some better information about how to go about creating functions. How to find the information inside the code I need to use them effectively, and some good naming conventions. It'll take some practice of course, but it was very informative!
Using what you showed me, I expanded on it a bit to utilize this function available inside of Dynamik Website Builder for Genesis (I love that child theme SO much) to have the function also check for a custom conditional.
I nested it so that first the function checks for the existence of the plugin, like you showed; then it moves on to check if the post has had the label 'review' applied to it or not, and if so, THEN to display the comment form.
And it seems to be working great!
Here is the final product:
/*------------------------------------*/ /* MyReviewPlugin Comment Review Form */ /*------------------------------------*/ add_filter( 'comment_form_default_fields', 'prefix_add_review_fields' ); function prefix_add_review_fields( array $fields ) { // Verify the plugin is installed. if ( ! function_exists( 'myrp_api_ratings_form_table' ) ) { return $fields; } // Add review form only if the label "Review" has been applied to the page. elseif (dynamik_has_label('review')) { $fields[] = myrp_api_ratings_form_table( null, true ); return $fields; } return $fields; }
I admit a little confusion in a way though. This method seems to work fine, but it is different from what I was seeing around on my.studiopress.com. I was looking at their collection of snippets to modify comments, trying to figure out how to work with this.. and I noticed they were using a filter "genesis_comment_form_args" a lot to modify the form.
You can see examples of this over at: my.studiopress.com.
An example is someone using the following code to modify the "Speak Your Mind" text:
add_filter( 'genesis_comment_form_args', 'sp_comment_form_args' ); function sp_comment_form_args($args) { $args['title_reply'] = 'Leave a Comment'; return $args; }
I don't suppose you (or someone else) could explain to me the difference here between using "genesis_comment_form_args" and "comment_form_default_fields". Or even if one could use either methods..
It SEEMED to me, like genesis_comment_form_args is a way to do perform similar (if not identical) tasks. And I thought if Genesis has an API to be doing such things, I should probably be using it.
In my stumbling ignorance, I tried to adapt the genesis_comment_form_args to do the same thing Garyl's code does, but was unsuccessful. =/
Lord_Devi
ParticipantOh ok! Good pointers for your naming conventions. I also like the addition of the function test, to make sure it's there. I would have totally forgotten to do that.
I admit again, php is new to me, and I didn't know that about not needing to assign variables to arguments. I just pulled that line of code out of the MyReviewPlugin API directly.
I'm understanding better I think now, what you are doing how this works. I just think I may be having some added difficulty being added by this particular plugin or the fact the fields are a table.
I tried your code snippet again (as is this time), and was greeted with no extra field table at all 🙁 Outside or in.
so I tried a few different versions of what you suggested, trying to make my best educated guesses on what it could be that I could.
Namely I only altered the:
$fields[] = myrp_api_ratings_form_table( null, true );
Line. I tried the following variations, and in any instance where "true" was used, the table just did not display at all.
In all other instances, where "false" was used, the table appeared, but outside the actual form #respond <div> still. =/
$fields[] = myrp_api_ratings_form_table( null, true ); $fields[] = myrp_api_ratings_form_table( get_the_ID(), true ); $fields[] = myrp_api_ratings_form_table( $post_id = null, $return = false ); $fields[] = myrp_api_ratings_form_table( null, false ); $fields[] = myrp_api_ratings_form_table( get_the_ID(), false );
I also thought it might be prudent to try and see if I could remove the table and stuff as a possible complication factor. So I thought I would try to use your method to just output some generic text. So I could see if I could get some text to appear inside the comment form using it. But I must be doing something wrong, because I could not get this to display all anywhere! :
add_filter( 'comment_form_default_fields', 'prefix_add_review_fields' ); function prefix_add_review_fields( array $fields ) { $fields[] = '<p class="comment-form-review-fields">TESTTESTTEST</p>'; return $fields; }
You've been very helpful so far still Garyl! Thank you very much for taking the time to respond. =)
Lord_Devi
ParticipantOk ok.. I'm looking at that comment-template.php file you showed me. I see what you are talking about. If you would be willing, or anyone else, a little mini walk through in what you are doing while you construct that statement would go a long way with me!
With my understanding of what you are doing I adapted the following snippet you provided me with into this:
add_filter( 'comment_form_default_fields', 'comment_form_review_fields' ); function comment_form_review_fields( array $fields ) { $fields[] = '<p class="comment-form-review-fields">' . myrp_api_ratings_form_table( $post_id = null, $return = false ) . '</p>'; return $fields; }
1. If I am creating a functions or variables I like to go from the general to the specific, so I renamed the function to "comment_form_review_fields".
2. Editing the class for the review fields to be specific to the custom fields seemed appropriate.
3. The API code I need to generate the fields is "myrp_api_ratings_form_table( $post_id = null, $return = false )" so I put that where you indicated.It did indeed show up! And mostly worked. However, this inserts the fields in a very similar fashion to what I would get by trying to assign it to the "genesis_comment_form" hook. That is, the fields still appear outside of the #respond <div> 🙁 I need it to appear inside "#respond div #commentform form" element.
I'm attaching a screenshot of the relevant section of the site being examined with Firebug to help provide some more helpful information.
I've already included the snippet of code I am using to try and get this stuff appearing where it needs to be.
Thanks for the help and insight you have already provided me with by the way!
The highlighted line in the image are the fields I need inserted into the #respond <div> beneath it.
-
AuthorPosts