StudioPress Community Forums

StudioPress Community Forums (http://www.studiopress.com/support/index.php)
-   General Discussion (http://www.studiopress.com/support/forumdisplay.php?f=7)
-   -   how to add an action to a specific page or post but no all pages or posts? (http://www.studiopress.com/support/showthread.php?t=123954)

vbrasil 11-10-2012 12:16 AM

how to add an action to a specific page or post but no all pages or posts?
 
I am creating a simple child theme for a site with a few pages.

On this child theme I am trying to implement the use of a plugin, skitter_slideshow. Its a slider plugin that is invoked when you add the following code to posts.php in wordpress:

<?php if ( function_exists('show_skitter') ) { show_skitter(); } ?>

On the Genesis Framework I have added the following code to my child theme's functions.php file:


if ( function_exists('show_skitter')) add_action( 'genesis_after_post_content', 'show_skitter');

This works and invokes the plugin slider. However, it does it for every post and page.

My objective is to just have it display on a particular page or post and not any of the other pages or posts in the site.

Any suggestions on how I can do that within the framework.

NicktheGeek 11-10-2012 08:10 AM

You can make your code conditional
http://nickc.co/conditional-content

vbrasil 11-11-2012 01:03 AM

Thanks for the response Nick. I read the post, it seemed very clear and made sense to me. I was just testing the logic, perhaps my PHP is not correct, but I didn't work for me in my application. Can you please take a look at the code and let me know if I am doing anything wrong.

if (is_page() && is_category('photo')) {

if ( function_exists('show_skitter')) add_action( 'genesis_after_post_content', 'show_skitter');

}

My site http://www.missionplacehomes.com is just made up of several pages. One page I put under the category photo but it didn't work. To troubleshoot I then tried to simplify it to:

if (is_page() ) {

if ( function_exists('show_skitter')) add_action( 'genesis_after_post_content', 'show_skitter');

}

And this had no effect either. I am obviously doing something wrong, but its not obvious to me what it is. Please let me know if you know. Thanks

NicktheGeek 11-11-2012 07:22 AM

this needs to be added differently. The is_page/is_category conditionals don't have anything to work with till after teh query is built.
PHP Code:

add_action'genesis_after_post_content''child_maybe_show_skitter');
function 
child_maybe_show_skitter() {
    if( 
is_page() && is_category('photo') )
        
show_skitter();



vbrasil 11-13-2012 01:12 AM

That worked perfectly, thanks Nick. I am currently reading your Genesis Framework Explained Series, very enlightening.

I am trying to do one more thing. I want to remove the author and date info after the post. I am trying to find the hook and function that it pertains to. My methodology is to look in the post.php file. And I thought I found it but I was wrong since my change did nothing.

what I added to my child functions.php file was:

remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

I then created a post.php file and added the same action above, and no change.

Basically I looked for the action I thought added in the function and just removed it, but that didn't work. Do I have the right idea here?

I am having a difficult time finding this, any tips on how to locate these actions for future reference.

NicktheGeek 11-13-2012 06:45 AM

looks right in theory, please start a new thread and we can help out. Thanks

You're welcome.

Since this is resolved I'm going to close this thread.


All times are GMT -5. The time now is 01:16 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.