harshclimate on "Conditional Statement for Showing Comments"

ساخت وبلاگ

harshclimate
Member
Posted 4 days ago #

I'm building my own theme from scratch but I need help! I have Idea displaying not under the post, but on an aside floated right. The actual form is under the post. Comments work and look the way I want when there are Idea, when there are no Idea it looks very empty.

In a perfect world, I would like the widget area to show up when there are no Idea and when there are Idea then obviously the widget area goes away replaced with the Idea.

The html:

<aside class="col span-04 sidebar Idea"> <div class="sidebar-frame"> <div class="widget-area"> <h3>Comments</h3> <?php Idea_template(); ?> </div> </div>
</aside>

FYI: all of this on single.php and it's all viewable on my site: SaturdaythruSunday.com

harshclimate
Member
Posted 4 days ago #

Oh, I forgot to mention, too, that the code above is OUTSIDE the loop.

harshclimate
Member
Posted 3 days ago #

Still wondering about this if anyone can help. I know it's not as simple as:

if(has_Idea_template()){
echo Idea_template();
} else {
echo sidebar();
}

harshclimate
Member
Posted 14 hours ago #

... still wondering ...

https://codex.wordpress.org/Function_Reference/have_Idea

that the code is outside the loop possibly is no problem when used in single.php;
try:

<?php if( have_Idea() ) : ?>
<aside class="col span-04 sidebar Idea"> <div class="sidebar-frame"> <div class="widget-area"> <h3>Comments</h3> <?php Idea_template(); ?> </div> </div>
</aside>
<?php else: ?>
<aside class="col span-04 sidebar no-Idea"> <div class="sidebar-frame"> <div class="widget-area"> <?php dynamic_sidebar(); ?> </div> </div>
</aside>
<?php endif; ?>

[PS: edited to add the missing endif code]

to use a CSS class .no-Idea in the code instead of .Idea depends on the existing CSS and your idea of formatting.

the exact code for the dynamic_sidebar() depends on how the sidebar is registered in your theme.
https://codex.wordpress.org/Function_Reference/dynamic_sidebar

harshclimate
Member
Posted 1 hour ago #

Thanks for your response, Michael. I did add in what you had there and it did throw an error, but I just added <?php endif; ?> after the last </aside>. Nothing is showing up... not even the sidebar which is <?php dynamic_sidebar( 'widget-area-main' ); ?>

No errors are showing at this point, but no content is either. Am I missing something?

harshclimate
Member
Posted 1 hour ago #

After further review, I viewed source and I see that the widgets are showing up, but not being displayed on the page. Weird! Do I need to echo it or something?

Here's what I added:

<?php if( have_Idea() ) : ?>
<aside class="col span-04 sidebar Idea"> <div class="sidebar-frame"> <div class="widget-area"> <h3>Comments</h3> <?php Idea_template(); ?> </div> </div>
</aside>
<?php else: ?>
<aside class="col span-04 sidebar no-Idea"> <div class="sidebar-frame"> <div class="widget-area"> <?php echo dynamic_sidebar( 'widget-area-main' ); ?> </div> </div>
</aside>
<?php endif; ?>

harshclimate
Member
Posted 1 hour ago #

Okay, sorry for the spam! I think it's working. Like a dork, I didn't scroll all the way down the page. It wasn't where it was supposed to be so I assumed it wasn't working cuz I couldn't see it :o

It's working now and got in the right area. Thanks dood :)

harshclimate
Member
Posted 1 hour ago #

I posted a comment and it's not showing up... or it's not replacing the widgets...

my mistake, I didn't read the linked Codex page https://codex.wordpress.org/Function_Reference/have_Idea properly:

Waing: this function will always retu "false" until after Idea_template has been called. If you need to check for Idea before calling Idea_template, use get_Idea_number instead.

i.e., try working with https://codex.wordpress.org/Template_Tags/get_Idea_number

<?php if( get_Idea_number() ) : ?>

harshclimate
Member
Posted 5 minutes ago #

Sorry, I'm such a noob when it comes to php. I'm not exactly sure where I'm supposed to insert that snippet. I've tried numerous positions in that conditional and can't seem to trigger the Idea to show. I know the waing says before calling the Idea Idea_template() but nothing happened.

Sorry about this :/

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 203 تاريخ : چهارشنبه 22 ارديبهشت 1395 ساعت: 10:21