wordpress blog page geting custom field of first post

i am facing a bad problem. it will be well appreciated if any one can help me regarding my problem.

i am using custom fields on posts and pages, just like removing Page navigation, Footer, Sidebar, ETC. when i use custom field on my recently added post (first post on displaying on Blog page) for example i remove navigation from that recently added post it also remove the navigation from Blog page where all the post are listing.

Read More

i am removing all the element from Jquery .remove() and i add all this code in footer

how to handle this i do not want any change on blog page if i am making any change in recently added post from custom fields.

<?php
   global $post;
   if(get_post_meta($post->ID, '_remove_topnavigation', true)=='yes'): ?>

   jQuery('#branding #navigation').remove();

<?php else : ?>

 //Do nothing

<?php  endif; ?>  

Related posts

Leave a Reply

2 comments

  1. You should post the code of the page , or at least a link, because your problem is not in the use of the custom fields but in the selectors you are using .

    instead of using #branding #navigation , which are maybe (probably) shared by your other navigation (although they are IDs, but bad theme coders are not rare in this world ) .

    So the solution would be either to isolate & identify better the selectors, or add another selector (class) to the recently added post.

    If you had included the page source code , it would have been much easier ..

  2. You’re trying to mix server-side and client-side code incorrectly. What your server-side PHP code needs to do is put some “marker” (probably a class attribute) on anything that your JavaScript code (via JQuery) needs to remove. Then your JavaScript code needs to look for that marker and then remove it.

    So the body of your if statement needs to set a class attribute (let’s call it “nobrandnav“) on whatever HTML block (probably a div) is being output. Your JavaScript code needs to start off like:

    jquery(".nobrandnav").
      find(whatever navigation is needed to find your branding).
      remove();