Support » Fixing WordPress » Interesting reversal of options

  • Resolved satyaki

    (@satyaki)


    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.]

Viewing 15 replies - 1 through 15 (of 18 total)
  • 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.

    After a wait of how many hours bumping is legal?

    or

    is my question eternally dumped?

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Is your theme using the body_class() function?

    Can we have a link to your site?

    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.

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    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.)

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    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' );
    		  }
    	  }
    
      }
    }

    Hi,

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

    Thanks and warm regards
    Satyaki

    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

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    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.

    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' );
    		  }
    	  }
    
      }
    }

    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.

    🙂

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    You’re welcome. I’m glad you got it resolved 🙂

    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.

    Hi Keesiemeijer,

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

    Warm regards
    Satyaki

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    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

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Interesting reversal of options’ is closed to new replies.