Add echo to my wordpress sidebar for non-connected users - php

i have Nice Login Widget which does not have any link to the registration page for non-members (simple visitors). I would like to visualize the Inscription link on the sidebar, just under the login widget but NOT anymore when someone is logged in !
The idea is that i will visualize the link with echo and by its css i could position it absolute.
I do not know anything about php, i tried to add some codes in my sidebar.php file but it does not work :
The sidebar.php is a classic twentyeleven theme :
<?php
if ( 'content' != $current_layout ) :
?>
<div id="secondary" class="widget-area" role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php
if ( is_user_logged_in() ) {
echo '';
else
echo '<a class="inscrip-link" href="http://www.igorlaszlo.com/test/register/">Inscription</a>';
?>
<aside id="archives" class="widget">
<h3 class="widget-title"><?php _e( 'Archives', 'vihegay' ); ?></h3>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h3 class="widget-title"><?php _e( 'Meta', 'vihegay' ); ?></h3>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!-- #secondary .widget-area -->
<?php endif; ?>
My added codes in above codes are :
<?php
if ( is_user_logged_in() ) {
echo '';
else
echo '<a class="inscrip-link" href="http://www.igorlaszlo.com/test/register/">Inscription</a>';
?>
Then i would add the css to the link class inscrip-link :
.inscrip-link {
position:absolute;
top:300px;
left: 30%;
z-index:1;
}
Can someone tell me how to do this ? (I accept better solution as well !:))

Your code seems to be missing a few curly brackets.
<?php
if ( !is_user_logged_in() )
{
echo '<a class="inscrip-link" href="http://www.igorlaszlo.com/test/register/">Inscription</a>';
}
?>
I have changed your code a bit. The register link will only show when a user is not logged in.

Finally i found a better solution for my case to be able to add my link with relative position to the sidebar... if someone has the same problem :
I added a text widget with my inscription link (#text-7) under my login widget.
In sidebar.php I added a widget with the same id (#text-7) which gives a classe to the body when users are logged-in (see php codes below).
In the style.css i give style to the #text-7 widget and i display:none when the body class is "logged-in" (see codes below).
PHP
<aside <?php echo (is_user_logged_in() ? 'class="widget widget_text logged-in"' : ''); ?> id="text-7" class="widget">
<h3 class="widget-title"></h3>
<div class="center">Inscription</div>
</aside>
CSS
#text-7 {position:relative;margin: -50px auto 30px;z-index:1;}
.logged-in #text-7 {display: none;}
Together with my personal class, i also added all other classes to the widget what a widget should have (widget and widget_text) because if not, it did not work for me... maybe it is just a "handmade" code but it work fine !

Related

Remove sidebar and replay from wordpress post page

I am looking for help to remove "junk" widgets from my wordpress website. Website theme is Zerif Lite and on every page so far there was no sidebar,however when I make a new post there is alot of junk (sidebar,who posted it,when,how entry was tagged and replay option).
I tried removing it from appearance->widgets and it didnt work and theme customization for widgets is locked for lite version.
So for start I 1st want to remove sidebar that include search,archives and meta.Only thing that worked so far was blanking out sidebar.php that include:
<div id="secondary" class="widget-area" role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h2 class="widget-title"><?php _e( 'Archives', 'zerif-lite' ); ?></h2>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h2 class="widget-title"><?php _e( 'Meta', 'zerif-lite' ); ?></h2>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; ?>
</div><!-- #secondary -->
However when I did that sidebar was removed,but space it took was blank,meaning post itself was only using 2/3 of page.
To get you to see for your self here are links to site (its in serbian,ignore that):
website and:
new post, this you can only see with this link,its where problem is
So if anyone can help me remove all that and make page clean I would be very greatfull. Thanks
The problem is css
Here is the solution (only if you dont use sidebar anywhere in your site)
Change the width of your content container, maybe right now is set to 70%(remaining 30% is for sidebar) to 100%.
If you plane to use sidebar, then you need set a conditional class in your functions.php:
function custom_body_classes( $classes ) {
// Adds a class of nosidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'nosidebar';
}
return $classes;
}
add_filter( 'body_class', 'custom_body_classes' );
Then only customize the css with the new class. Ex:
.content .nosidebar {
width:100%
}
Cheers

Suppress Meta Log In, Log out from pages when the theme has no reference to it

I am using a theme (ward) that has no reference to the Meta / Site Admin / Log Out but I am still seeing it at the bottom of every page/post. I have looked all php files from the theme and I cannot see any mention to that.
How do I get rid of this? Is there any hook to get rid of this?
edit
This is my Meta on the appearance widgets:
But as you can see I have nothing on the first sidebar or home page
There is, in sidebar.php:
<?php
/**
* The first/left sidebar widgetized area.
*
* If no active widgets in sidebar, alert with default login
* widget will appear.
*
* #since 1.0.0
*/
?>
<div id="secondary" <?php bavotasan_sidebar_class(); ?> role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar' ) ) : ?>
<?php if ( current_user_can( 'edit_theme_options' ) ) { ?>
<div class="alert alert-warning"><?php printf( __( 'Add your own widgets by going to the %sWidgets admin page%s.', 'ward' ), '', '' ); ?></div>
<?php } ?>
<aside id="meta" class="widget">
<h3 class="widget-title"><?php _e( 'Meta', 'ward' ); ?></h3>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; ?>
</div><!-- #secondary.widget-area -->
It's the wp_loginout() that's causing it.

different widgets for different pages and posts

my blog page in Wordpress is using a specific widget but I wanted to use different widget for a post in the blog.
I used an example (https://gist.github.com/anonymous/1308851) to write my code in sidebar.php.
<?php
if ( 'content' != $current_layout ) :
?>
<?php
//for rest of posts
if (is_active_sidebar('blog_widget_area') ) : ?>
<div id="secondary" class="blog_widget_area bordered" role="complementary">
<?php dynamic_sidebar( 'blog_widget_area' ); ?>
</div><!-- #secondary .widget-area -->
<?php endif;
//for specific post "Loyalty Program Trends in the Restaurant Industry"
if (is_active_sidebar('loyalty_programs_widget_area') && is_single('4063') ) : ?>
<div id="secondary" class="blog_widget_area bordered" role="complementary">
<?php dynamic_sidebar( 'loyalty_programs_widget_area' ); ?>
</div>
<?php endif;
?>
<?php endif; ?>
However, I couldn't get the second widget to display in that specific post....
Possible solutions:
Before trying below solution make sure some data/widget already loading on sideabar
loyalty_programs_widget_area.
solution 1
// use array inside is_single function
<?php if (is_active_sidebar('loyalty_programs_widget_area') &&
is_single( array('4063','4063-page-name-here') ) ) : ?>
<?php endif; ?>
solution 2
// put separate if check inside sidebar
<?php if (is_active_sidebar('loyalty_programs_widget_area') ) : ?>
if( is_single('4063') ) { } or
if( is_single(array('4063','pagename')) ) { }
<?php endif; ?>
Other possible solutions:
Try:
-deactivating ALL plugins temporarily to narrow down and possibly fix the problem . If the problem goes away, activate them individually to find the culprit?
-switching to the default theme (Twenty Ten) for a moment by renaming your current theme's folder in wp-content/themes. The idea is to force WordPress to fall back to the default theme to rule out any theme-specific issue?
For further details read official documentation regarding " sidebar "
Note:
is_single() offer different other ways to check post id or name(when permalink isenabled)
- is_single(array(17,'beef-stew','Irish Stew'));
- is_single('17'); or is_single(17);
Try this code below:
<?php // only show on 31 post not any other. ?>
<?php if ( is_single('31') ) { ?>
<?php // if blog_widget_area2 is active then show otherwise don't :) ?>
<?php if ( is_active_sidebar( 'blog_widget_area2' ) ) : ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area2"); ?>
</div>
<?php endif; ?>
<?php }else{ // otherwise load this sidebar ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area"); ?>
</div>
<?php } ?>
With the help of codewizz (Thanks codewizz!), we got it to work. The things we need to change is to move the code over from sidebar.php to single.php. However, the way it's coded, it displays both the first widget and the second widget on the post's sidebar.
So he suggested that I use http://wordpress.org/plugins/display-widgets/. And now it works.
Additionally, if one want to start from scratch, you should use that code
<?php // only show on 31 post not any other. ?>
<?php if ( is_single('31') ) { ?>
<?php // if blog_widget_area2 is active then show otherwise don't :) ?>
<?php if ( is_active_sidebar( 'blog_widget_area2' ) ) : ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area2"); ?>
</div>
<?php endif; ?>
<?php }else{ // otherwise load this sidebar ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area"); ?>
</div>
<?php } ?>

3-column grid breaking after certain point

I have a WP blog with a theme based on F5 (Reverie). Currently using a child theme for handling the custom styles, etc.
In addition, I'm using Infinite Scroll (part of JetPack plugin) to manage pagination on home and archived pages.
The issue
It looks fine on the initial loading of the first set of posts (set to 6). When I click the button to trigger infinite scroll, six more load (still looks fine). Load another and the 3-column grid starts to break (lose the float). At first I thought it might be the images using for the post. I even tried deactivating some plugins I thought could be an issue; no luck.
I have also tried adjusting the css (height, min-max) of the posts to see if helps. No go.
home.php
<div class="row" id="content-home">
<div class="small-12 columns" id="content" role="main">
<h5 style="margin-left:15px;">Latest Posts</h5>
<?php query_posts('offset=1'); ?>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; // end have_posts() check ?>
</div>
</div>
content.php
<article id="post-<?php the_ID(); ?>" <?php post_class('index-card small-12 large-4 columns'); ?>>
<header>
<?php if ( has_post_thumbnail() ) {the_post_thumbnail('large'); } ?>
</header>
<div class="entry-content">
<h2><?php the_title(); ?></h2>
<?php bvblog_small_meta(); ?>
</div>
.row .small-12.columns#content article {
display: inline-block;
float: left !important;
min-height: 540px;
}

Underscores Wordpress Theme - Adding second sidebar

Stared a Wordpress site using Underscores theme (_s)
I have got one sidebar working but want to make a second one to be on the same page. (containing different widgets)
I have added the new sidebar to the functions.php and it appears in the Wordpress login screen and i can drop widgets into it. However, I can't get it to show on the actual webpage. (the first sidebar is working fine)
Anyone know how to do this or know a tutorial...
Thanks
You'll need to edit the "sidebar.php" file in your theme folder. It should normally be:
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar-1 widget area ?>
</div><!-- #secondary -->
You will need to add another if statement that looks out for the other sidebar. Be sure to reference it by whatever you used in the functions.php file.
If you want it to appear below the current sidebar, just be sure to add it before closing the 'div' so it will still be in the same column. I used 'sidebar-lower':
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar-1 widget area ?>
<?php if ( ! dynamic_sidebar( 'sidebar-lower' ) ) : ?>
<?php endif; // end sidebar-lower widget area ?>
</div><!-- #secondary -->

Categories