I have a left and right advertising plugin, but want to show it only to main page (index page)
I have tryed to put a if conditions in plugin but doesn`t work. How to do it correctly?
This is floatads.js file code: http://pastebin.com/qeUHPn08
This is float_left_right_ads.php file code: http://pastebin.com/xm6GxF4d
Thanks for all info and help!
The front page is the main page if you chose it so in the dashboard setting. Inside
if ( is_front_page() ) {
// display your advertisment plugin
}
Related
I want to limit the usage of a plug-in to the child-theme (called "intranet") only.
The file is located in mytheme/intranet/index.php, and is used as a template by a page named "Intranet" created in WP admin.
The URL is www.mysite.com/intranet
I have tried both targeting post-id ("100") and page-slug ("intranet") like this:
if (is_page( 100 )) {
//run pluggin
}
if (is_page( 'intranet' )) {
//run pluggin
}
This works however when targeting a page using template mytheme/intranet/custom-page-template.php in the child-theme (both id and slug).
I also tried targeting the uri:
$uri = $_SERVER['REQUEST_URI'];
if ( strpos($uri, 'child-theme/index.php') ) {
//run pluggin
}
Any ideas why it isn't working?
Try putting a wp_reset_query function call after your loop on the homepage template.
If you're using a custom query on the home page and not used wp_reset_query, then the conditional check will always point to the last post fetched by that custom query hence failing to check if homepage.
OR
Try this
<?php if (get_the_ID()==100): ?>
<!-- Google Analytics Content Experiment code -->
<?php endif; ?>
I have created html pages and trying to convert into wordpress theme,how to link html one page to other page in wordpress menu bar
sample code :
Features
this code is not working,it 's showing page not found.how to make this link in wordpress using php code.
Firstly Create Page "Features" from wp-admin.
Create template for this page.
http://codex.wordpress.org/Stepping_into_Templates
To set this page in menu Go in "Menu" section in WordPress.
http://codex.wordpress.org/Appearance_Menus_Screen
To view this menu in fronted use wp_nav_menu()
Take example template from your theme.
This is file in theme ending with -page.
Change template name in head of a file.
Then remember about the_loop all should be inside a loop to work correctly with many pages.
Put html there, also in header.php attach css to this html.
Page structure is like, header in the up, then page and then footer.
Remember to preserve good html structure - divs beginning and ending.
Then you create a page with content ( which is presented in the_loop ) , which has its own url address.
You can set url naming of pages in settings -> permalinks, you may need to write to .htaccess file.
Then you have direct url to page. You can use it in code like this:
echo bloginfo('url'). 'nameofpage';
All to do is create a template and assign it to page ( on page edit page template option ).
You can use pages or posts for this, i prefer pages.
Create new pages or posts and get their ID.
For linking its:
Get link with this:
get_permalink( $yourPostOrPageID ); // only get; not echo
Otherwise
Wordpress homepage link:
get_bloginfo('home');
Category or custom taxonomy term link:
get_term_link( $term, $taxonomy );
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.
in wordpress the single page is controlled by single.php theme file. I want to put another link on the single page like "Preview". I want this link to be handled by preview.php. preview.php will be stored in theme directory! how to handle this?
usually I do these using init action hook! if the variable exists in the query string, I perform the action! but how to register a custom script to handle a custom link!
the single page link is like ?p=x and the link to preview will be ?p=x&action=preview
thanks in advance
You could do it old school style. At the very top of your single.php, put:
<?php
if( isset( $_GET['preview'] ) ) {
require( "preview.php" );
die(); # a horrible death
}
?>
I wrote my own custom page template for my Wordpress page, now I want to change sidebar.php to insert a small menu whenever that page template is loaded.
// sidebar.php
if ( isset($event_name) ) {
// do something
}
But apparently sidebar.php doesn't recognize variable $event_name.
How do I come about solving this?
While I'm not familiar with the way WordPress implements templates, have you tried declaring the variable global in the sidebar page?
See: Function Reference/is page template « WordPress Codex to be able to detect page template in use.