how to go to other pages of my wordpress plugin - php

I have a function that once is done should open a page called "nexpage.php" at the end of function I have used the following but none of them work.
include works but when I use this,it includes the new page in current page which I do not want, and need to close the current page and open the next page.
function myfunc(){
.........
include "nextpage.php";
echo "<a href='nextpage.php'>NewPage</a>"; <<does not find it
include_once "nextpage.php"; << open it in the page so javascript does not work and login wont disappear
header('Location: nextpage.php'); <<it refresh the page but does not open the nextpage
}

Personally I would put the full link on the page so that there is no confusion on where you want it to go. I would specify the full path instead of the short path of the PHP file.
You can either use these for a Plugin:
echo 'New Page';
or
echo 'New Page';
or if Theme
echo 'New Page';
There are other options as well. When creating setting pages for a plugin you can also create an array of submenu's by using add_menu_page() & add_submenu_page() and listing each page with a subpage-slug that you can point to a function or a page based on the name.
Reference:
http://codex.wordpress.org/Function_Reference/add_menu_page
http://codex.wordpress.org/Function_Reference/add_submenu_page

Related

PHP code to create hyperlinks to the homepage?

I have a php site template and i want to create hyperlinks to the homepage on the internal pages. I tried this code which works in wordpress but doesn't work on my template: anchor text
What alternative code i can use to replace <?php echo home_url(); ?>, so it will work on my php template?
edit:
This worked Homepage! but i have another problem. In my php template the most recent pages are displayed on the homepage in a same way as a wordpress site. For the inner pages I am using this code page title to create hyperlinks for the page title similiar to the blog posts in wordpress. The problem is that the pages on the homepage are linking to the homepage not to the page url. For exmple, page with title Blue Widget has this page url domain.com/blue-widget, but when the page is displayed on the home page the page title is linking to domain.com.
How can i make the page title that are displayed on the homepage to link to they corresponding page url and not to the homepage. The same way blog posts that are dispalayed on the homepage of wordpress site are linking to they blog post pages.
Homepage link is just (when you have one domain):
Homepage!
Create a constant, somewhere in a central place like a config file. Then use it throughout the script.
define ('SITELINK', 'http://www.stackoverflow.com');
And in your template:
Go to home!
Or you can wrap it into a function:
<?php
function home_url(){
return SITELINK;
}
?>
Go to home!
Go to about page!
For referring only homepage:
In php
echo 'anchor text';
In Html
anchor text
Use "/" to redirect to home page from any other page.
The problem with $_SERVER['SERVER_NAME']; is it can be unreliable on some instances such as subdomains, etc...
Here is WordPress' Reference Manual: http://codex.wordpress.org/Function_Reference/network_home_url
In WordPress you can use:
$url = network_home_url();
echo $url;
So for you example it would be:
anchor text
Hope that helped.
<?php
function home_url(){
?>Go Home<?php
}
home_url();
try to use $_SERVER['SERVER_NAME']; to get the home URL
Home

How can i check if there is any content in them main page of joomla?

i am using joomla 3 for a web site, i don't use any content in the main page but the system output is on because i need to output contents on other pages of the site. the problem is i have a space in the middle of the page where normally the content comes. i know where this comes from but i have to disable it if there is no content on that selected page. i tried to check the
$this['template']->render('content')
which is actually used to render the specific content. but i was not able to use it in a conditional if. so i need to check if the loaded page has a content output. has anybody a idea how i could do that?
PS: i dont want do this with css.
You may check if you are showing the main page and render conditionally:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
$this['template']->render('content');
}
?>
For multilingual site check this link for detecting if you are on the default page:
http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page
Just curious... why don't use the <jdoc:type="component/>?

Wordpress calling an HTML file from PHP

I am trying to modify a theme on wordpress. The theme shows a slider on the front page, which reads from the featured.php file.
I have gone into the featured.php and removed all the PHP code. I can inject my custom HTML into the featured.php and the pages display properly, however I want the page to display from a wordpress page.
So i tried to:
<?php
$html = file_get_contents('http://www.mydomain.com/homepage-featured');
?>
The above link corresponds to a page i created in wordpress. So i want to be able to inject my HTML into that page and then when you load my homepage, the PHP tells the browser to display the contents of this URL.
The above code doesn't work.
Thanks for the help.
file_get_contents() - as its name suggests - reads a file in but does not print it. You need to echo your $html variable. A better way is to use require() or include() but if I were you I would put my custom file on the same server so that way you don't have to use the file from a remote location thus sparing network traffic.
I think you have better to use the include function.
The file_get_contents you are using would generate an HTTP request, so it would make your script slower. I think it would be a good idea to put the HTML file on the same server if possible.
Have you tried
<?php
require('http://www.mydomain.com/homepage-featured');
?>
If my understanding is correct, you are trying to use a template (featured.php) for a different page other than the front page.
To do so, just change the Page Template of the page(the separate page which is # www.url.com/myhomepage). You can change this # Dashboard > Pages (Click Edit link in the required page) > Edit Page > Page Attributes meta box (available in the rightside below Publish) > Template. Change the template of this page to "Featured".
(I assume that your code in file feature.php has Template Name: Featured at the top)

Page title show "page not found" on wordpress

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.

Drupal Adding custom Omniture code, PHP variable not being set

Ok I have some custom Omniture code I need to add to a Drupal site. All is good as I have added the Javascript code to the themes template page. The code shows up on all the pages as expected but I have a couple of PHP variables that I need to print in the Javascript that are coming up blank.
<?php
$omniture_event = "test this works as expected";
$omniture =<<<OMNITURE
<script language="JavaScript"><!--
s.events="{$omniture_event}"
s.landing="{$omniture_landing}"
OMNITURE;
echo $omniture;
?>
but $omniture_landing is set on the landing page only and it looks like the template page is being loaded first then the content of the page is being added. I can print the value to the screen and I see the Javascript in the footer as expected with the other PHP variable set, but when I try to set the variable on the landing page it comes up blank in the javascript.
You can edit your page.tpl.php template file. If the 'Landing page' is your front page, then you can do something a little easier and more consistent (if you end up changing the title).
if($is_front) {
$omniture_landing = 'Yeah we have landed!!!';
}
Or by node id:
if($node->nid == '1') {
$omniture_landing = 'Yeah we have landed!!!';
}
Replacing 1 with whatever the node Id is of course
Also, check to see if you have a page-front.tpl.php If so, that file, page-front.tpl.php is the template that runs on the landing page instead of page.tpl.php and you can add your code to page-front.tpl.php or remove it if you don't need a separate template for the landing page.
I ended up adding this to the template page (page.tpl.php) before the Omniture code
if($node->title == 'Landing Page Title') {
$omniture_landing = 'Yeah we have landed!!!';
} else {
$omniture_landing = '';
}

Categories