Hi All,
I have an ongoing and rather perplexing issue. I have single post navigation (in one category) as a drop-down in my sidebar global navigation. I also have Advanced Custom Fields appearing in the sidebar when they are associated with a particular post or page. The problem is that both of these functions are showing up at random—particularly when you view the blog—in spite of my conditional tags to the contrary. The, issue, I believe, is that my tags are incorrect. But, they often show up differently using MAMP locally as they do on the "live" server. Please help. My code(s) are as follows:
For ACF
<div id="statement">
<?php the_field( 'project_statement' ); ?>
</div><!--end div#statement-->
And for the drop-down navigation
<?php if ( in_category('Collaborations')) { ?>
<ul class="child">
<?php next_post_link_plus( array('link' => 'Next', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?><br />
<?php previous_post_link_plus( array('link' => 'Previous', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?>
</ul>
<?php } ?>
The website in question can be found here:
http://mcnairevans.com
Michael Caputo answers:
You might want to make use of the is_single() function to limit the sidebars from displaying on single entry pages.
If there are more than one posts displaying on a listing page, there must be conditions being met somewhere on that page.
Adam comments:
Thanks for your prompt response Michael,
Unfortunately, I have tried is_single (in combination with both is_category and in_category) to no avail. Well, actually, it was not completely wrong, but the drop-down also appeared on other single page views. I only need it to appear when the user is browsing the Collaborations category.
Any (more ideas?)
thanks in advance!
Arnav Joy answers:
can you please explain what is the problem , and what should be the output
Arnav Joy comments:
try this
<?php if ( is_single() && in_category('collaborations' , get_the_ID())) { ?>
<ul class="child">
<?php next_post_link_plus( array('link' => 'Next', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?><br />
<?php previous_post_link_plus( array('link' => 'Previous', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?>
</ul>
<?php } ?>
Adam comments:
Unfortunately, no such luck.
While the prev/next drop-down no longer appears when navigating the blog (good) they also no longer drop down when I navigate to "collaborations" (which is not good).
I understand that my initial post could have been more detailed, so to clarify: The drop-down navigation should only appear when the user is browsing the collaborations category.
thanks for taking a stab at it :)
Arnav Joy comments:
try this by replacing category id with your
<?php $collaborations_cat_id = 11; // replace here with your id ?>
<?php if ( is_single() && in_category($collaborations_cat_id)) { ?>
<ul class="child">
<?php next_post_link_plus( array('link' => 'Next', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?><br />
<?php previous_post_link_plus( array('link' => 'Previous', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?>
</ul>
<?php } ?>
Adam comments:
Same results as before :(
Could it be the "&&"? Why not "||"? Just curious, as I am (obviously) not too familiar with all of this.
thanks,
Arnav Joy comments:
yes try with "||" in place of "&&"
Arnav Joy comments:
for ACF try this
<div id="statement">
<?php
if(get_field( 'project_statement' )
the_field( 'project_statement' );
?>
</div><!--end div#statement-->
Adam comments:
Using that code broke the site...
Arnav Joy comments:
there is ) missing ,
try this
<div id="statement">
<?php
if(get_field( 'project_statement' ))
the_field( 'project_statement' );
?>
</div><!--end div#statement-->
and if this did not work then try this
<div id="statement">
<?php
$project_statement = get_field( 'project_statement' );
if(!empty($project_statement))
the_field( 'project_statement' );
?>
</div><!--end div#statement-->
Adam comments:
Unfortunately, those produced the same results (statements appearing in sidebar while navigating blog). I believe, however, that I fixed the issue with this code:
<div id="statement">
<?php
if(get_field( 'project_statement' ) && !is_home())
the_field( 'project_statement' );
?>
I simply added the conditional statement to prevent it from appearing on the blog. I am still unclear why exactly it was happening in the first place, but I suppose this fix is good enough, no?
Anyway, thanks for all the suggestions.
Plugarized answers:
Try the following code below
Plugarized comments:
Try the following
<?php if ( is_single() || in_category('collaborations')) { ?>
<ul class="child">
<?php next_post_link_plus( array('link' => 'Next', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?><br />
<?php previous_post_link_plus( array('link' => 'Previous', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?>
</ul>
<?php } ?>
Plugarized comments:
If that doesnt work try the following.
<?php if ( in_category(Collaborations) ) { ?>
<ul class="child">
<?php next_post_link_plus( array('link' => 'Next', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?><br />
<?php previous_post_link_plus( array('link' => 'Previous', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?>
</ul>
<?php } else { ?>
<ul class="child">
</ul>
<?php } ?>
Adam comments:
Thanks for both recommends! I am still getting the same issue with the drop-down showing up on the blog rather than ONLY when "collaboration" is selected. I came up with the following solution (also posted in my conversations section):
<?php if ( is_category('Collaborations') || in_category ('collaborations') && is_single()) { ?>
<ul class="child">
<?php next_post_link_plus( array('link' => 'Next', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?><br />
<?php previous_post_link_plus( array('link' => 'Previous', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?>
</ul>
<?php } ?>
Not sure if this is the best solution as I was simply doing trial and error until something stuck. I suppose as long as it is working though...
Still unable to resolve the aforementioned issue with the custom fields though. Any suggestions?
Adam comments:
Thanks for both recommends! I am still getting the same issue with the drop-down showing up on the blog rather than ONLY when "collaboration" is selected. I came up with the following solution (also posted in my conversations section):
<?php if ( is_category('Collaborations') || in_category ('collaborations') && is_single()) { ?>
<ul class="child">
<?php next_post_link_plus( array('link' => 'Next', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?><br />
<?php previous_post_link_plus( array('link' => 'Previous', 'format' => '%link', 'loop' => true, 'in_same_cat' => true) ); ?>
</ul>
<?php } ?>
Not sure if this is the best solution as I was simply doing trial and error until something stuck. I suppose as long as it is working though...
Still unable to resolve the aforementioned issue with the custom fields though. Any suggestions?