I am creating a custom members area for my client's employees. Basically, what I've done so far is I created a new role=consultants and I gave that role a read only access.
Then I uploaded the Peter's Login Redirect Plugin so that the consultants (employees) land in a page called CONSULTANTS PORTAL. From there, they will be able to access their individual page which it will load as long as the name of the page matches the username given to them. That way they can only see their own page.
To see this process, you can visit this link in the wordpress.org forums EASY CLIENT PORTAL
So I've managed a lot of it, except...I am supposed to duplicate the page.php and then add the script that will make the individual page show up. But, the Genesis Framework is pretty complicated. The page.php has an empty skeleton and the actual meat of the page is in a li/structure root folder (That's what I think anyway) .
As it is right now, I have the following in my default template page consultants-portal.php
<?php
/**
* Template Name: Consultants Portal
*/
global $current_user;
get_currentuserinfo();
$page = get_page_by_title($current_user->user_login);
_e($page->post_content);
genesis();
?>
This code gets me this. You can see the content (my page) loading before the page loads. Which tells me there is something else I need to add to this so that the content loads in the actual white area of the page.
The instructions in the link I mentioned says to add the dynamic script right above the is_page or have_posts, but I as I said, Genesis doesn't have this in page.php. instead it is all broken in pieces and spread through the root.
Sorry if I made this too long to read, I wanted you to have all the info I have.
has anyone done this before?
Try out the following code:
<?php
/**
* Template Name: Consultants Portal
*/
// remove Genesis default loop
remove_action( ‘genesis_loop’, ‘genesis_do_loop’ );
// add a custom loop
add_action( ‘genesis_loop’, ‘my_custom_loop’ );
function my_custom_loop () {
// add your queries or custom structure here
global $current_user;
get_currentuserinfo();
$page = get_page_by_title($current_user->user_login);
_e($page->post_content);
}
genesis(); ?>
Instead of writing the code directly, write it inside the loop function as above.
Related
I have this in my index.php file. It adds the home banner image in WordPress. I know that it is mostly generated in WordPress customizer, but I need to add an anchor tag in this section. I can't find it anywhere in the file structure.
<?php do_action('cleanblog_index_top'); ?>
I'm not able to find where cleanblog_index_top leads to. Any help would be great. Thank you!
I stumbled on this old one while looking up the docs for do_action(). The answers are brutal so I decided to provide a better answer in case anyone else stumbles here.
If a WordPress theme has something like do_action( 'example_action_hook_tag' ) somewhere in one of the template files (such as index.php, page.php or whatever) the purpose is to provide theme or plugin authors with a way to write their own custom function that they can then "hook" onto the action with the function add_action().
WordPress would then call this function any time and anywhere do_action( 'example_action_hook_tag' ) is called.
The creators of commercial themes will often litter their template files with hooks declared with do_action() to make it easier for their customers to customize their themes via functions.php or by writing a site-specific plugin.
It looks to me that this is the likely scenario that is impacting the OP. This also explains why the OP was unsuccessful in finding where this "leads to".
It would only "lead somewhere" if the OP wrote a function in the theme/child-theme functions.php or in a plugin and added the line do_action( 'cleanblog_index_top', 'name_of_ops_function' ) to hook their function onto the cleanblog_index_top. WordPress would then call their function when do_action( 'cleanblog_index_top' ) was called in index.php.
From the name of the OP's hook, cleanblog_index_top, it sounds like the theme author intended to provide a way for others to inject output at the top of the index page template.
Suppose the OP wanted <h1>Hello World</h1> to appear there.
In functions.php of a theme/child-theme the OP could add a function that echo's this out:
function op_customization() {
echo '<h1>Hello World</h1>';
}
And hook their function onto cleanblog_index_top:
add_action( 'cleanblog_index_top', 'op_customization' );
Cheers!
You should never edit the index.php file directly, for the same reason you should never edit core Wordpress files directly - the next time WP pushes an update, your changes will be overwritten (and that assumes you don't break anything). Never edit plugin files directly, same reason.
You need to look in your theme, you should only make changes to the functions.php and style.css files in your theme - unless you create a child theme and that is a topic you should Google.
this is how I'm going with wordpress forum
it is such that even if you do not log into the site you can see what you can create, etc.
Create forum / post to the site just being tucked away so it is only possible to view it if you are login on the page.
Comment content must also be away but just get some text that you can not write content until he has sustained itself on the page.
I purchased this forum
http://themeforest.net/item/forumengine-flat-responsive-wordpress-forum-theme/5999646
WordPress comes with all the functionality needed for this its as simple as wrapping the content you want within an if statement for example
<?php if ( is_user_logged_in() ) {
echo "Member Content";
}else{
echo "Sorry Guest";
?>
id suggest something like above if you are working with template files you could always wrap the while loop with the above
After updating (or maybe not) but some time before, when I'm going to category list page mysite.com/?cat=10 I'm getting not category.php template - it opens single.php Why?
I was trying to make category-10.php (just for test) but still coming to single.php.
Where I should look about my problem?
The problem was with my ajax plugin his code is :
<?php
/**
* Plugin Name: Ajax content loader
* Description: Load content througt ajax.
* Version: 0.1
*
*/
/**
* Initialization. Add our script if needed on this page.
*/
function ajax_content_init() {
global $wp_query;
// Add code to index pages.
if( !is_singular() ) {
// Queue JS
wp_enqueue_script(
'load-posts',
plugin_dir_url( __FILE__ ) . 'js/load-posts.js',
array('jquery'),
'1.0',
true
);
$wp_query->is_single = true;
}
}
add_action('template_redirect', 'ajax_content_init');
?>
Any ideas what is wrong here?
It is for mobile version, how to activate him only for mobile? not for desktop?
Download the WordPress Debug Bar Plugin. It will add a button to your wp-admin bar that says "Debug". When pressed, this button will show you the debug panel. Find the tab in this debug panel that says "WP Query", and it should show you query vars and the template file that are being used.
This should help you figure out what query vars are being registered, and which template file is really loaded.
You should read wordpress codex for template_redirect before trying to experiment things.
This action hook executes just before WordPress determines which
template page to load.
What are you actually trying is:
if( !is_singular() ) {
If page is not a singular, means is not a template page.php or single.php it should execute the code.
So when you were at category.php it executed the code and sets the global $wp_query layer objects property single to true. So whatever template you were viewing at that time it will set that page as single.
Hope it helps.
My question: Is there any way of showing the visitor's IP address in the title of a page on Wordpress? What I've done so far is this: My IP Lookup.
Is there any plugin or a tweak that I can do to?
Here's the file: Header.php
Please help!!
I'm the author of the theme and its framework. I'm just going to modify the code that Matthew gave you a bit. For future updates to the theme and framework, it's better if you can avoid actually editing header.php in your Child theme, but instead utilize the framework's hook system:
http://www.wpjumpstart.com/tutorial/primary-framework-action-hooks/
themeblvd_title is one of the framework's actions. It has a default function already hooked onto it that displays the title the way you see it now. What you want to do is fairly easy because you're not actually modifying that default function, but instead just adding onto the action.
If the concept of action hooks in general is completely foreign to you, definitely check out this article -- www.wpjumpstart.com/tutorial/actions/ -- Understanding these basic WordPress development concepts is really going to expand what you're going to be able to do moving forward with your customizations.
So to accomplish what Mathew said, you'd do the following from the functions.php of your Child theme:
function my_title_addon() {
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addition
do_shortcode('[shortcode]');
}
}
add_action( 'themeblvd_title', 'my_title_addon' );
There's also one big thing to note here, as well. I noticed on your site, you're using Alyeska 2.0. You should update to the latest version Alyeska 2.1 posted last week on ThemeForest, which incorporates v2.1 of the framework. Inside is a new sample child theme that incorporates a slightly modified structure, as outlined in this video -- vimeo.com/41331677
If you do not use this new child theme structure, the above code I posted will add your IP shortcode to the start of themeblvd_title, which isn't what you want. If you elect to keep your current theme version and Child theme structure, the above add_action needs to have a priority higher than the default 10 like this:
function my_title_addon() {
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addition
do_shortcode('[shortcode]');
}
}
add_action( 'themeblvd_title', 'my_title_addon', 11 ); // Higher priority so it comes after default title function
Here is how you can use a filter hook to modify the title.
Add this in a theme functions.php file or one of your own plugins:
add_filter( 'wp_title', 'add_ip_to_title', 10, 3 );
function add_ip_to_title($title, $sep = '', $location = '') {
return $title . $sep . "visitor IP info here";
}
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
Edit your header.php file in your theme. That is where the tag is generated. It should be wp-content/themes/alyeska-child/header.php or if it isn't there wp-content/themes/alyeska/header.php.
If you post the code that is generating your title (or your header.php file if you can't tell), we can tell you where to add it specifically.
If the IP info is generated via a shortcode, you can use do_shortcode('[shortcode]) in your PHP to run the shortcode directly with PHP.
If you wanted to do this on just one page, you would have to detect the correct page and conditionalize the change to the title. You need to know a page identifyer for the page you want, but you would use something like:
<title>
<?php
themeblvd_title();
if (is_page(10)) { //Check if we are on the correct page
echo '|'; //Just a spacer between the default title and your addtion
do_shortcode('[shortcode]');
}
?>
</title>
More information on is_page: http://codex.wordpress.org/Function_Reference/is_page
To add to some of the other answers, to get their IP address, it could vary a little bit depending upon your server environment. Just make a file called test.php and put it in a web accessible place:
<?php
echo phpinfo();
?>
Then, look for a place where you can retrieve the user's IP address. If your PHP is running in a reverse proxy, unfortunately, the normal place will just have localhost's IP. But there are a lot of other environmental variables you can grab the IP from. Here are the places to check:
"Apache Environment" or "HTTP Headers Information" or under the "PHP Variables" section.
Then, if you see the real IP address (compare the address shown on the info page with what you might get from whatismyip.com) then you can access that value in the function described above by drew010 using one of PHP's predefined variables.
i made a couple of php pages and integrated them into wordpress.
The first page is fine, but the second one show "page not found" on the title when it is loaded.
You can find the first page here:
http://www.stefanovirgulti.it/spese.php
then click on "Aggiungi Negozio" to go to second page.
code of first page:
(suppressed wordpress template code)
//if ( is_user_logged_in() ){
if ( true ){
$index=linkBuilder("Aggiungi Negozio",$_SERVER['PHP_SELF']."?p=1");
$appPath="./moneym/";
//$page=$_GET["p"];
switch ($_GET["p"])
{
case 1:
$page="negozi.php";
break;
default:
echo "this is the first page<br>";
echo $index;
break;
}
if ($page != "") include $appPath.$page;
}
else {
echo "This is a private page.<br>";
}
function linkBuilder($name,$path){
return sprintf("%s ",$path,$name);
}
(suppressed wordpress template code)
The code of the second page contains only an echo.
How do i fix this?
PS: the second page works, but if you check the title page, it says "page not found" and i can't change that, this is my problem.
How did you create these pages? Without looking at your header.php file I'll assume your using some sort of default code to get the page title. To create new pages in wordpress you need to create them in the backend admin panel. if your just loading in files, the wordpress enviroment will see this as a page that doesn't exist.
Solved!
I found the "page custom template" functionality. I just made a template with all my code, then used it as template for a wp static page.
I have done the custom template starting from page.php of my current template, took off the code that handles the content, and replace it with my php/sql stuff.
I have made a new page inside wp and used this custom template.
In this way i have a page that does what i want, but act as a real wp page, i can even add it to menus and apply whatever plugin to it. I left the title funcionality so i can change the title of my cutom page from wp admin.
THe reason for this is that one of your included phps includes a check for wordpress environment and displays that title when the condition is satisfied.
The solution is to use php to output "" tags before the included file is loaded.