How to handle a custom url with Wordpress? - wordpress

i want to handle a custom url with WordPress theme files, for example http://www.example.com/wordpress/login
the question is that how i handle this /login with WordPress theme files like page.php , index.php or a custom template file for this reason, if exists!.

This plugin might be useful to you.
https://wordpress.org/plugins/login-logout/
It appears you could create a page called 'Login' which Wordpress would automatically create as http://www.website.com/login/
This plugin appears to be a widget, but I like that it has the ability to manage where a user is re-directed after successful login/logout.
You could register a new widget in functions.php, then call the widget with a conditional to the 'Login' page that way it could be in the main content area rather than look like a widget.
Example:
<?php } if ( is_page(9) ) { ?>
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('login-widget') ) : ?>
<?php endif; ?>
<?php } else { } ?>
My example would assume page 9 = your login Page and 'login-widget' would be the name of the widget you assigned in functions.php

Related

Frontend Buddypress Notifications - Show for Current User Only

I've added a custom slide-out box to show a user's Buddypress notifications on any page.
https://imgur.com/ellepqp
I'm essentially echoing the template part from the Buddypress plugin Youzify (formerly known as Youzer). Youzify is just an extension to redesign Buddypress so I believe this problem is not necessarily related to that but rather native Buddypress.
I am able to get the Notifications for the current user when I'm on any standard Wordpress page. However, if I'm on a user's profile, it shows THEIR Notifications instead! I know that by default, Admins can actually see all Notifications if they simply add /notifications to any profile slug, but this is happening for standard Users too.
This is the current code:
<?php global $bp;
if( bp_has_notifications($bp->loggedin_user->id) ) : ?>
<?php bp_get_template_part( 'members/single/notifications/notifications-loop' ); ?>
<div class="read-all-notifs"> View All Notifications</div>
<?php else : ?>
<?php bp_get_template_part( 'members/single/notifications/feedback-no-notifications' ); ?>
<?php endif; ?>
I assume it's something to do with the template part and some function that forces the bp_displayed_user ID when on a Buddypress page, so how can I override that to make sure the Notifications in my popup are always for the current user on ANY page? Anyone have any ideas? Thanks.
I figured this out with help from a developer. This is the correct formatting for the initial part:
<?php if ( is_user_logged_in() && bp_has_notifications( array('user_id' => bp_loggedin_user_id(), 'per_page' => 10, 'search_terms' => false ) ) ) : ?>
The search terms part was added because on any search results page it was showing the 'No Notifications' loop for everyone.

How to reuse the same widgets in different wordpress pages

I have to the following page which has a widget called press as you can see in the screenshot
I had created another page (manually and by cloning pulgin) and I can't reuse the same widget in the new page.
Any ideas how can I do that?
you can add sidebar in particular page template
Ex. sidebar slug name : "left-sidebar"
<?php if ( is_active_sidebar( 'left-sidebar' ) ) : ?>
<?php dynamic_sidebar( 'left-sidebar' ); ?>
<?php endif; ?>
Or
you can use below plugin
https://wordpress.org/plugins/display-widgets/
Page template section screenshot
For Ex. About Us Template

Different header in different pages in wordpress

I am going to develop a WordPress theme for my own site. It has three types of menu.
first one is only for the home page, the second one is for any normal page (like about us, contact etc.) and the third one is for article page (when a news will be clicked then where one will be gone).
how can I do this?
thanks.
There are multiple ways you can go about doing this. For the article I would create a PHP file named page-article.php and within the file follow what developer tells you:
<?php
/**
* Template Name: Article
*
*/
and then create a custom header for the article in a header-article.php file:
header('article') ?>
To target the home you could use is_page() and pass it home but I would suggest using is_home() instead but you could always pass both like:
if ( is_page('home') || is_home() ) :
// further code
endif;
Do note this would depend on your settings as you do not mention if you will have a custom page set by the setting under Settings -> Reading so if you set front page you should target it with is_front_page():
if ( is_page('home') || is_home() || is_front_page() ) :
// further code
endif;
You could always code all of this in one header.php file but I would suggest creating an additional header file and calling it header-article.php
You can do it using is_page() function.
See full documentation here
if( is_page( array( 'about-us', 'contact') ){
//display your page menu
}
if( is_page( 'home' ){
//display your home page menu
}
if( is_page( 'article' ){
//display your article page menu
}else{
//display default menu
}
If you need different header in different page then you have to create a page template then you can add different header file in different page template-
Normally we use get_header() to include header.php
Now create a copy of header.php file and named it header-alternative.php
Then create a page template named "Alternative header"
<?php get_header('alternative');
/*
*Template Name: Alternative Header
*/
?>
<section class="error-page-inner">
<h1 class="error-code"><?php esc_html_e( '404', 'labstore' ); ?></h1>
</section>
<?php get_footer(); ?>
Then header-alternative.php is called for this page template.

wp_title() not working properly with blog in non-root folder

I followed this guide to have my blog appear under mydomain.com/blog:
http://codex.wordpress.org/Making_Your_Blog_Appear_in_a_Non-Root_Folder
In short, I'm using a custom page template to create a static page "Blog", which then goes and renders the posts:
<?php
/*
Template Name: Blog
*/
// Which page of the blog are we on?
$paged = get_query_var('paged');
query_posts('cat=-0&paged='.$paged);
// make posts print only the first part with a link to rest of the post.
global $more;
$more = 0;
//load index to show blog
load_template(TEMPLATEPATH . '/index.php');
?>
In my theme, I render the <title> tag using the following syntax:
<title><?php bloginfo('name'); ?> | <?php is_front_page() ? bloginfo('description') : wp_title(''); ?></title>
This is described here in the codex:
http://codex.wordpress.org/Function_Reference/wp_title#Covering_Homepage
The problem is that now on mydomain.com/blog, there is no title rendered by wp_title('');
If I stop using the blog.php template, then the title appears correctly. Obviously the blog posts do not anymore though. How to have the wp_title() display the correct title in this situation?
You should be following the updated guide for Wordpress 2.1+:
http://codex.wordpress.org/Creating_a_Static_Front_Page

Password protecting not working for custom post type single-template.php? - Wordpress

I have created a custom post-type 'Clients' where admin user can create new clients, add pictures and details to post, then password protect the page so only a particular client can access the content.
For displaying content of this post-type on the front end, I'm using a single-clients.php template. It displays the content perfectly, but the password protect function does not display the form and hide the content, even if I'm in a different browser, cache cleared/logged out of Wordpress (viewing it as a regular end-user would).
What might I be doing wrong here?
<?php get_header(); ?>
<div class="container-client">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
Display all fields and content for post-type
<?php endif; ?>
<?php endwhile; else: ?>
<div class="alert-box error">Sorry, this page no longer exists :( — Back to home</div>
<?php endif; ?>
</div>
<?php get_footer(); ?>
This is roughly how my single-clients.php page is setup. Is there any way to manually display the password function so that when end-user visits page, the content is hidden and password form is displayed?
I had exactly this problem and after some trying and reading the codex I came up with this solution:
<?php
add_filter('single_template', function($single_template) {
global $post;
if ($post -> post_type == 'your-custom-post-type') {
if (!post_password_required()) {
$single_template = 'path-to-your/single-your-custom-post-type.php';
}
}
return $single_template;
});
?>
This way the page is only rendered in the custom sinlge view after entering a password, if it is password protected.

Resources