Custom Menu Links are not displaying in category page. When i checked the source, it shows me like this.
<div class="sidebar-widget">
<h1 class="widget-title">Popular Categories</h1>
<div class="menu-cus_menu-container">
<ul id="menu-cus_menu" class="menu"></ul>
</div>
</div>
The same function i called for my home page. But it is working fine. The following code is in sidebar.php
<?php
if ( is_active_sidebar( 'sidebar-hompage-widget-area' ) && is_home() ) {
dynamic_sidebar( 'sidebar-hompage-widget-area' );
}
if ( is_active_sidebar( 'sidebar-category-widget-area' ) && is_category() ) {
dynamic_sidebar( 'sidebar-category-widget-area' );
}
if ( is_active_sidebar( 'sidebar-left-widget-area' ) ) {
dynamic_sidebar( 'sidebar-left-widget-area' );
}
?>
Please help me to find out right solution or suggest me to find my mistake.
As far as i think you have a Category page not a category.php or archive.php file. is_category() function only works within category.php or archive.php file. Instead of using is_category try use is_page('category').
For more information on is_category() see http://codex.wordpress.org/Function_Reference/is_category.
Related
How to show login link for non-logged in users instead Buddypress Activity Loop?
Is there an easy way to do this in theme functions.php file?
I know how to add notice before loop with: action_activity_loop_start but how to hide the whole loop?
Option 1
You can use something like this:
add_filter( 'bp_get_template_part', static function( $templates, $slug, $name ) {
if ( $slug === 'activity/index' && ! is_user_logged_in() ) {
$templates = [];
}
return $templates;
}, 10, 3 );
This snippet will completely hide the default activity loop, with all filters, forms, etc, rendering an empty page instead of all BuddyPress Activity.
This may not be a desirable way.
Option 2
In the $templates variable you can also define your own path to a custom template (like activity/logged-out.php, so it will look like this:
$templates = [ 'activity/logged-out.php' ];
You will need to create a wp-content/themes/theme-name/buddypress/activity/logged-out.php file with something like this:
<?php do_action( 'bp_before_directory_activity' ); ?>
<div id="buddypress">
<?php do_action( 'bp_before_directory_activity_content' ); ?>
<div id="template-notices" role="alert" aria-atomic="true">
<?php do_action( 'template_notices' ); ?>
</div>
<?php do_action( 'bp_before_directory_activity_list' ); ?>
<div class="activity" aria-live="polite" aria-atomic="true" aria-relevant="all">
CUSTOM TEXT FOR LOGGED OUT USERS.
</div><!-- .activity -->
</div>
You can check activity/index.php file to decide what you need and what you don't, but I think this is a good idea to remove the majority of content and hooks.
Option 3
If you use the BuddyPress Legacy Template Pack (check in BuddyPress settings) you can copy /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/activity/index.php file into your theme: wp-content/themes/theme-name/buddypress/activity/index.php and do the modification where needed. Check the line around 235 which has this: <?php bp_get_template_part( 'activity/activity-loop' ); ?>.
For BuddyPress Nouveau Template Pack everything is basically the same, but you will need to deal with wp-content/plugins/buddypress/bp-templates/bp-nouveau/buddypress/activity/index.php file. You will need to wrap its div#activity-stream into is_user_logged_in() check before display the whole div and its content, something like this:
<?php if ( is_user_logged_in() ) : ?>
<div id="activity-stream" class="activity" data-bp-list="activity">
<div id="bp-ajax-loader"><?php bp_nouveau_user_feedback( 'directory-activity-loading' ); ?></div>
</div><!-- .activity -->
<?php endif; ?>
This way you will basically override the default BuddyPress template file with your own.
Please remember about the ajax functionality of the page (filtering etc).
I'm working on a blog using the theme Coral Dark. This theme has support for post thumbnails, and I want to remove them from the individual posts and leave them everywhere else (home, archives, categories, etc). The thumbnails are created with a pluggable function, so in theory I should just have to override it. If I add this to the functions.php of my child theme:
function coral_dark_post_thumbnail() {}
The thumbnails effectively disappear. However, if I use a conditional to run the function in posts only:
if ( is_single() ) {
function coral_dark_post_thumbnail() {}
}
It does nothing. The thumbnails still appear everywhere. I can even replace is_single with anything else because WordPress simply ignores it. And if I add a negation to the conditional like this:
if ( ! is_single() ) {
function coral_dark_post_thumbnail() {}
}
The thumbnails disappear but everywhere. Again, I can replace is_single with whatever because the result is the same. I don't understand what's happening.
This is the original function:
if ( ! function_exists( 'coral_dark_post_thumbnail' ) ) :
/**
* Displays an optional post thumbnail.
*
* Wraps the post thumbnail in an anchor element on index views, or a div
* element when on single views.
*
* Create your own coral_dark_post_thumbnail() function to override in a child theme.
*
*/
function coral_dark_post_thumbnail() {
if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
return;
}
if ( is_singular() ) :
?>
<div class="post-thumbnail">
<?php the_post_thumbnail('large'); ?>
</div><!-- .post-thumbnail -->
<?php else : ?>
<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
<?php the_post_thumbnail( 'post-thumbnail', array( 'class' => 'alignleft smallpostthumb', 'alt' => the_title_attribute( 'echo=0' ), 'sizes' => '(max-width: 480px) 100vw, 210px' ) ); ?>
</a>
<?php endif; // End is_singular()
}
endif;
Many thanks in advance. :)
Seems your problem is with the condition. You cannot use condition to wrap your function li
if ( is_single() ) {
function coral_dark_post_thumbnail() {}
}
Instead use:
function coral_dark_post_thumbnail() {
if ( is_single() ) {
//TODO: Something
}
}
Doing the above should work.
I was working on site pages here which comes in wedding category which comes in a custom taxonomy named listing.In my wedding category listing i dont want to display the price sticker but it shoud display in all other listing posts eg this page
I have tried
if ( in_category( 'wedding' )) {
?><style>.pricestricker{display:none!important;}</style><?php
}?>
also
if ( is_category( 'wedding' )) {
?><style>.pricestricker{display:none!important;}</style><?php
}?>
also
if ( has_term('listing', 'wedding' )) {
?><style>.pricestricker{display:none!important;}</style><?php
}?>
none of these worked.Please help.Thank You
Please try this once where the div "pricestricker" is present:
<div class="pricestricker" <?php if ( in_category( 'wedding' )) { echo 'style="display:none;"' }?>><span itemprop="price" class="wlt_shortcode_price">$0</span></div>
Here you should only write the php code inside the div "pricestricker" and remain will be default code.
or you can do:
<?php if ( !in_category( 'wedding' )) { ?>
<div class="pricestricker"><span itemprop="price" class="wlt_shortcode_price">$0</span></div> // This will be your default code
<?php } ?>
I need a little help on Wordpress searching. The thing I want to know is how to search Wordpress pages only.
You might want to check out this page on the wordpress forums.
You have to add a hidden form field in your search form and add a hook to update the query that wordpress generates.
Edit: Here's the code from the forum post mentioned above.
In the search form:
<input type="hidden" name="post_type" value="page" />
In functions.php:
function mySearchFilter($query) {
$post_type = $_GET['type'];
if (!$post_type) {
$post_type = 'any';
}
if ($query->is_search) {
$query->set('post_type', $post_type);
};
return $query;
};
add_filter('pre_get_posts','mySearchFilter');
In your search.php, find The Loop and insert this code just after it. You can recognize the Loop because it usually starts with:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
Code to be inserted:
if (is_search() && ($post->post_type=='post')) continue;
So, your code should be like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<?php if (is_search() && ($post->post_type=='post')) continue; ?>
Let me know if it worked.
I'm trying to have different pictures on every one of my pages built on wordpress.
So I have the following in my index.php file, archive.php file, page.php file, etc:
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $toppic; ?>" alt="page1" id="mainPageImg" />
Now, in my page.php file, I have the following:
<?php
// TOP PICTURE DEFINITIONS
if ( is_home() ) {
$toppic == 'page1.png';
}
if ( is_page('articles') ) {
$toppic == 'page2.png';
}
?>
How come this does not work? I tried it with one equal (=) sign...
EDIT: If I define $toppic at the top, for example, in the index.php file as follows:
<?php $toppic = 'page1.png'; ?>
Then it works. So therefore, it must be something that has to do with the conditional if is_page/is_home statements. Any ideas?
Thanks!
Amit
Okay, I found the answer.
This is what needs to be done. For the articles (blog) page, at the top section you need to place the following:
<?php // TOP PICTURE DEFINITION FOR ARTICLES PAGE
if ( is_home() ) {
$toppic = 'page1.png';
}
?>
Then, in your page.php file, you can control the picture at the top for all other pages (except 404, where you'd need to put a is_404() in your 404.php. So this is what it looks like:
<?php
// TOP PICTURE DEFINITIONS
if ( is_page('english') ) {
$toppic = 'page1.png';
}
if ( is_page('aboutus') ) {
$toppic = 'page1.png';
}
if ( is_page('newspaper') ) {
$toppic = 'page1.png';
}
else {
$toppic = 'page1.png';
}
?>
And finally, in order to implement this, use the following HTML/php syntax:
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $toppic ?>" alt="page1" id="mainPageImg" />
That's all. Phew. Finally got it to work :) Had to do it for a client, too!
The slug for your Articles page has to be defined as articles. This is set in the edit page interface, see these directions.