WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Interesting reversal of options (19 posts)

  1. satyaki
    Member
    Posted 2 years ago #

    Hi,

    I have a style.css file for my previous and next button.

    It has a nice option of not showing the buttons in case viewed from mobile.

    The code is as below................

    /* CSS3 Media Query - Hide from smaller displays/ viewports
    ------------------------------------------------------------ */

    @media screen and (max-width: 1024px) {
    .wpspn-area,
    #wpspn-nextpost,
    #wpspn-prevpost {
    display: none;
    }
    }

    Now I wish this switches to show up for only one category and not all.
    How can I do that?

    I think it will be something similar to the above coding but not know exactly what.
    I am a newbie and doesn't know much about coding.

    Your help will be highly appreciated, experts.

    [No bumping. If it's that urgent, consider hiring someone.]

  2. satyaki
    Member
    Posted 2 years ago #

    Hello,

    I was wondering if I could insert a line like this in the single.php file of my theme

    -------------------------

    <?php if ( in_category('3') ) { wdpv_vote(); } ?>

    -------------------------

    However, I am confused about what to write instead of "{ wdpv_vote();}"

    I am not using the 'vote' plugin but yours instead.

    Please help me out.

  3. satyaki
    Member
    Posted 2 years ago #

    After a wait of how many hours bumping is legal?

    or

    is my question eternally dumped?

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    Is your theme using the body_class() function?

    Can we have a link to your site?

  5. satyaki
    Member
    Posted 2 years ago #

    Hi Keesiemeijer,

    Thanks for replying.
    I am a newcomer to this forum, please forgive me if I deviated from the norms of the forum.

    Sorry, I forgot to mention.
    The website in discussion over here is..........
    available only on localhost and not yet uploaded.
    I intend to use the 'Kippis' theme.

    It have various categories for posts and I wish to activate the 'WP Single Post Navigation Within Category' prev/next buttons for posts having the category 'photo' only.

    Thanks for your time again.

  6. keesiemeijer
    moderator
    Posted 2 years ago #

    I think the Kippis theme is using the body_class. Try putting this in your theme's stylesheet style.css [untested]:

    .wpspn-area,
    #wpspn-nextpost,
    #wpspn-prevpost {
    display: none;
    }
    
    .category-3 .wpspn-area,
    .category-3 #wpspn-nextpost,
    .category-3 #wpspn-prevpost {
    display: block;
    }

    This hopefully shows the previous and next button only on category 3 (ID.)

  7. keesiemeijer
    moderator
    Posted 2 years ago #

    Ok, that's not going to work. remove those lines from your style.css and add this to your theme's functions.php:

    add_action( 'wp', 'specific_single_prev_next_links' );
    
    function specific_single_prev_next_links(){
    	if ( is_single() ){
    
    	  global $post;
    
    	  if(isset($post->ID) && $post->ID) {
    		  if(!has_term(3, 'category', $post->ID)) {
    			  remove_action( 'wp_head', 'single_prev_next_links' );
    		  }
    	  }
    
      }
    }
  8. satyaki
    Member
    Posted 2 years ago #

    Hi,

    Thanks for the solution.
    I am implementing it now and will update in next 15 minutes.

    Thanks and warm regards
    Satyaki

  9. satyaki
    Member
    Posted 2 years ago #

    Hi,

    I have implemented the code in the functions.php file.
    Now the prev/next buttons are effectively removed from all posts.

    However, it is also not appearing for category ID=17 (that is my requirement) :)

    Hence, I had changed the code from 3 to 17 in the following line............

    " if(!has_term(3, 'category', $post->ID)) {"

    It must be some mistake from my side, do I have to put the category ID as 17 to some other place as well?

    I need the buttons to appear for posts under category ID = 17

  10. keesiemeijer
    moderator
    Posted 2 years ago #

    I'm sorry but without being able to look at the website it's very difficult to know how to solve this issue. It works on my testsite.

  11. satyaki
    Member
    Posted 2 years ago #

    The codes are working perfectly well for blocking the buttons in appearing from any posts.

    However, for category ID = 17, the buttons are not appearing as well.

    I have tweaked your codes to work for category ID =17.

    I am not very good with technical stuff and this is the second time I am seeing the .php files.

    Will you please check whether what I have done is correct?
    I think I am doing some mistake from my side.

    This is the modified coding that I have used
    for showing buttons only in category 17...............

    add_action( 'wp', 'specific_single_prev_next_links' );
    
    function specific_single_prev_next_links(){
    	if ( is_single() ){
    
    	  global $post;
    
    	  if(isset($post->ID) && $post->ID) {
    		  if(!has_term(17, 'category', $post->ID)) {
    			  remove_action( 'wp_head', 'single_prev_next_links' );
    		  }
    	  }
    
      }
    }
  12. satyaki
    Member
    Posted 2 years ago #

    Hi Keesiemeijer,

    As I told you, the mistake was from my side only.
    Somehow, I had forgotten to erase the commands in the style.css file.
    That is why in all the posts the buttons were blocked.
    Silly me!!! :)

    Your suggestion is working like a charm.
    Thanks for helping out a technically challenged person like me.

    On a lighter note, Tintin has always been my favorite character too.
    Have a great day.

    :)

  13. keesiemeijer
    moderator
    Posted 2 years ago #

    You're welcome. I'm glad you got it resolved :-)

  14. satyaki
    Member
    Posted 2 years ago #

    Thanks Keesiemeijer,

    One more thought on this.....
    can I use another 2 more categories for showing the buttons using this?
    How can I do that if I wish to add category ID = 18 & 19 in future.

  15. satyaki
    Member
    Posted 2 years ago #

    Hi Keesiemeijer,

    Please give my request a thought.
    In the meanwhile have a wonderful weekend.

    Warm regards
    Satyaki

  16. keesiemeijer
    moderator
    Posted 2 years ago #

    you can use an array of ids like this:

    if(!has_term(array(17,18,19), 'category', $post->ID)) {
    			  remove_action( 'wp_head', 'single_prev_next_links' );
    		  }

    http://codex.wordpress.org/Function_Reference/has_term

  17. satyaki
    Member
    Posted 2 years ago #

    Hi Keesiemeijer,

    Thanks for the solution and support.
    Thanks for taking out the time for me on Sunday.
    I do really appreciate your help.

    Your solution has completely taken care of my problem.
    Thanks once again for the sound technical help.

    Regards
    Satyaki

  18. satyaki
    Member
    Posted 2 years ago #

    Sorry, I forgot to flag the thread as resolved.

    Thanks to Keesiemeijer, the issue is resolved,

    an hence I am flagging the thread as resolved.

  19. satyaki
    Member
    Posted 2 years ago #

    Resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic