I know this going to be very easy question for people with good PHP knowledge.
I have a WordPress website self hosted. I designed it for mobile devices and I would like to install Millennial Media advertisements in it. Millennial Media does not really provide detailed instructions and web resources strangely are not available!
I have knowledge in HTML,CSS and JavaScript but very poor in PHP :( .
any way I can do some changes PHP to achieve what I want, but I can't write them from zero and integrate them by my self.
Ok long story short
This the code provided by Millennial Media:
<?php
/*--------------------------------------------------------------*/
/* Millennial Media PHP Ad Coding, v.7.4.20 */
/* Copyright Millennial Media, Inc. 2006 */
/* */
/* The following code requires PHP >= 4.3.0 and */
/* allow_url_fopen 1 set in php.ini file. */
/* */
/* NOTE: */
/* It is recommended that you lower the default_socket_timeout */
/* value in the php.ini file to 5 seconds. */
/* This will prevent network connectivity from affecting */
/* page loading. */
/*--------------------------------------------------------------*/
/*------- Publisher Specific Section -------*/
$mm_placementid = 123456;
$mm_adserver = "ads.mp.mydas.mobi";
/* The default response will be echo'd on the page */
/* if no Ad is returned, so any valid WML/XHTML string */
/* is acceptable. */
$mm_default_response = "";
/*------------------------------------------*/
/*----------- BEGIN AD INITIALIZATION ----------*/
/*----- PLEASE DO NOT EDIT BELOW THIS LINE -----*/
$mm_id = "NONE";
$mm_ua = "NONE";
#$mm_ip = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_USER_AGENT'] )){
$mm_ua = $_SERVER['HTTP_USER_AGENT'];
}
if (isset($_SERVER['HTTP_X_UP_SUBNO'])) {
$mm_id = $_SERVER['HTTP_X_UP_SUBNO'];
} elseif (isset($_SERVER['HTTP_XID'])) {
$mm_id = $_SERVER['HTTP_XID'];
} elseif (isset($_SERVER['HTTP_CLIENTID'])) {
$mm_id = $_SERVER['HTTP_CLIENTID'];
} else {
$mm_id = $_SERVER['REMOTE_ADDR'];
}
$mm_url = "http://$mm_adserver/getAd.php5?apid=$mm_placementid&auid="
. urlencode($mm_id) . "&uip=" . urlencode($mm_ip) . "&ua="
. urlencode($mm_ua);
/*------------ END AD INITIALIZATION -----------*/
?>
<?php
/* Place this code block where you want the ad to appear */
/*------- Reusable Ad Call -------*/
#$mm_response = file_get_contents($mm_url);
echo $mm_response != FALSE ? $mm_response : $mm_default_response;
/*--------- End Ad Call ----------*/
?>
I want the Advertisement to appear in the footer area ( I will edit the footer.php in twenty eleven theme )
but I want to know where shall I put these pieces of codes in wordpress files or shall I create a new ones and what to name them?
would some please help me with this issue and provide me with the file's names that required to be edited and how would they look like in the end ?
Thanks
Anywhere in your page, where you want the ad to appear, let's say inside a <div>, use:
<div>
<?php include('thatfiletheysentyou.php'); ?>
</div>
This will make output of that file appear where include is.
EDIT: Complete rewrite:
This is content of footer.php. I just installed wordpress for you, took 3 minutes. I edited footer.php including <?php include('ads.php'); ?> (see below), which appeared in footer, as expected
<?php
/**
* The template for displaying the footer.
*
* Contains the closing of the id=main div and all content after
*
* #package WordPress
* #subpackage Twenty_Eleven
* #since Twenty Eleven 1.0
*/
?>
</div><!-- #main -->
<footer id="colophon" role="contentinfo">
<?php
/* A sidebar in the footer? Yep. You can can customize
* your footer with three columns of widgets.
*/
if ( ! is_404() )
get_sidebar( 'footer' );
?>
<div id="site-generator">
<div>
<?php include('ads.php'); ?>
</div>
<?php do_action( 'twentyeleven_credits' ); ?>
<?php printf( __( 'Proudly powered by %s', 'twentyeleven' ), 'WordPress' ); ?>
</div>
</footer><!-- #colophon -->
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
Now if you got a file from the ad company, change ads.php above to this file name. If you got a code pasted in (i don't know, an e-mail, website) - create a file ads.php and paste whatever you got from them. Place that file in twentyeleven subfolder. My file looks like this:
<?php
echo 'HEHEHE!';
//instead of this just paste your code here
?>
and on the page it is like so:
1 http://www.spzozwolsztyn.internetdsl.pl/wpress.jpg
If you got tired of them remove include line from footer.php.
Related
I've been trying to insert a WP contact form 7 in a custom 'blank' page template.
Actually what I'm trying to do is insert the WP CF7 functionality in a very basic, clean page (just a nice background, able to adjust font, images, ...) but I don't want the page the look like this blogpost from the WP theme..
I've tried to upload a white page template with FTP,
but when I try to embed to WPCF7 code in the new page with the blank template, nothing happens...
Anybody who can help me out?
Thanks a lot!
White page template
<?php /* Template Name: Blank Page
*
* A blank custom page template.
*
* The "Template Name:" bit above allows this to be selectable
* from a dropdown menu on the edit page screen.
*
*/
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
Write Your code Like this:
<?php
/* Template Name: Blank Page
*
* A blank custom page template.
*
* The "Template Name:" bit above allows this to be selectable
* from a dropdown menu on the edit page screen.
*
*/
get_header();
$id= get_the_ID();
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
get_footer();
I'd like to add a title element to a specific page (not all pages). I am using Yoast but I could not find this page on Yoast plugin. So I think I'd have to add it on PHP file head section. But my head section is like this below, how can I add it?
<?php
/**
* The template for displaying all single jobs.
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* #package WorkSt
*/
get_header(); ?>
Then below this is HTML, e.g. container and so on.
You can to this by wp_head hook of wordpress
add_action('wp_head', 'add_custom_meta');
function add_custom_meta(){
global $post;
if( 'your-page-slug' === $post->post_name ){
echo '<meta content="your content">'; // add mete here
}
}
I've got a weird issue, possibly because I've customized some PHP on my Wordpress site.
I've got a template called homepage.php that displays all the posts from today's date (taken directly from the Wordpress Codex, filed under WP_Query).
About 7 or 8PM every day, all the posts disappear from that page. Why? And how do I fix it?
I thought at a certain point that it might be a post expiration issue, but I never set any expiration - I don't even think that's an included feature in Wordpress, is it?
Many thanks.
Full code included below just in case there's some clue here.
<?php
/**
* Template Name: Home Page
* The template for displaying all of today's posts on home page.
*
* This is the template that displays only today's posts.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* #package WordPress
* #subpackage Twenty_Fifteen
* #since Twenty Fifteen 1.0
*/
get_header(); ?>
<?php
$today = getdate();
$query = new WP_Query( 'year=' . $today['year'] . '&monthnum=' . $today['mon'] . '&day=' . $today['mday'] );
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
if ($query->have_posts() )
{
echo'<ul>';
while ( $query->have_posts() ){
$query->the_post();
echo '<li>' . get_template_part('content', get_post_format() ) . '</li>';
}
echo '</ul>';
/* Restore Post Data */
wp_reset_postdata();
//else : // no posts found.
}
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
What is best practice for making a function call on a wordpress page?
For instance if you want to call my_special_function(); on the home page, where is the proper place to put the function call (ie home-page.php, /template-parts/content-page.php etc.).
<?php if( function_exists( my_special_function ) ) {
my_special_function();
} ?>
FYI Im using Underscores theme.
I've seen a few comments regarding shortcode. Would something like the below WP page template with the shortcode inserted be a best practice over just calling the function on that page?
So if I wanted the function to be called in the page template below I would just insert the shortcode wherever I want it on that page template or just is just calling the function is sufficient or best practice
<?php
/**
* Template Name: Home Page
*
* The template for displaying the home page.
*
* #link https://codex.wordpress.org/Template_Hierarchy
*
* #package Rollins_Ridge
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
// insert Shortcode
<?php echo do_shortcode('[special_function_shortcode]') ;?>
// or just call the function
my_special_function();
// or something else im not aware of
code here;
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
Don't edit themes core files.
the proper way is using functions.php file in child theme directory.
you can add your function in this file and create shortocde using wordpress hook
like
my_special_function(){
//Your content goes here.
echo "This is proper way";
}
add_shortcode('special_function_shortcode','my_special_function');
and use following shortocde anywhere on site.
in wordpress page use [special_function_shortcode]
and in php use
<?php echo do_shortcode('[special_function_shortcode]') ;?>
I know this question is already asked a lot, but every time I read an answer on those questions it looks like I've implemented it like I should've. My problem is as follows:
I have added the following statement to my index.php to load a different header (saved in header-frontpage.php) for my static home page (called page-home.php).
if(is_front_page())
{
get_header('frontpage');
}
else
{
get_header();
}
I have also set page-home as my static front page in the wordpress settings->read.
Shouldn't this result in my homepage loading the header-frontpage.php? Now it just retreives my header.php for my frontpage as well. A live preview can be found at www.koencuijpers.com (wrong loading of header.php) and www.koencuijpers.com/spot-map (right loading of header.php).
My complete code for my index.php is:
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
*
* #link https://codex.wordpress.org/Template_Hierarchy
*
* #package Spot_Utrecht
*/
if(is_front_page())
{
get_header('frontpage');
}
else
{
get_header();
}
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
/* Start the Loop */
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();
?>
If you've set your homepage as a static page, then WordPress will be following its template hierarchy to decide what template to use:
https://developer.wordpress.org/themes/basics/template-hierarchy/#front-page-display
This means WordPress will not be using index.php as the template for your front page, so whatever changes you make there will have no effect.
Therefore you need to include your if statement in the appropriate template (probably front-page.php, depending on your theme setup).