my name is Chris and this is my first help question.
I am having some issues trying to figure out how to embed a Minecraft Server Dynamic Map into my PHP.
The map is 209.105.236.244:8123
The code in which I am trying to embed it is
<div class="span6">
<?php if( protectThis("1, 2") ) : ?>
<h1 class="page-header"><?php _e('You have the ability to view this map'); ?></h1>
<p><?php _e('You will only be able to see this content if you have a <span class="label label-info">special</span> user level. ')?></p>
<?php else : ?>
<div class="alert alert-warning"><?php _e(' ***Dynamic Map Here***'); ?></div>
<?php endif; ?>
</div>
I am just not able to figure out how to make the map display here instead of them just going to the url. :3
If anyone can provide me with a solution or even a jumping off point on how to go about this, that would be simply amazing! Please and thank you :)
I'm assuming you intend to call javascript based on the page source at 209.105.236.244:8123
You could forgo the echo <?php _e(' ***Dynamic Map Here***'); ?> and include your map related scripts here just as you did with your other html tags. It should still fall within your "else" condition so that these scripts are only called if your requirements are met.
In this case, any time protectThis("1, 2") is not true, the map should be displayed.
<?php if( protectThis("1, 2") ) : ?>
<h1 class="page-header"><?php _e('You have the ability to view this map'); ?></h1>
<p><?php _e('You will only be able to see this content if you have a <span class="label label-info">special</span> user level. ')?></p>
<?php else : ?>
<div class="alert alert-warning">
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="js/script.json.js"></script>
</div>
<?php endif; ?>
Related
I have a banner I would like to only show on archive pages on my website. I can't figure out the php code to do so. Here is what I have so far (obviously I've removed a lot of the code to make this look cleaner and easier):
<header id="masthead" class="site-header navbar-static-top fixed-top <?php echo wp_bootstrap_starter_bg_class(); ?>" role="banner">
</header>
<?php if(is_archive()) ?>
<div class="free-shipping-banner">
<p>
FREE SHIPPING on all print orders within North America.
</p>
</div>
<?php endif; ?>
You can see it is my free-shipping-banner that I want only displayed on archive pages. I'm not getting any errors with this code, but it's still showing up on all other pages of my website. Does anyone know what I am doing wrong?
Here is your correct code. Please add brackets for if statement.
<header id="masthead" class="site-header navbar-static-top fixed-top <?php echo wp_bootstrap_starter_bg_class(); ?>" role="banner">
</header>
<?php if(is_archive()) { ?>
<div class="free-shipping-banner">
<p>
FREE SHIPPING on all print orders within North America.
</p>
</div>
<?php } ?>
The mistake in your code is that the if statement will only look for the next line. But when you place brackets; you tell the server where it ends. You used endif but you also forgot a colon at the end of if statement. The above code will work.
I have a loop in my view that outputs all the content gathered from the database:
<?php foreach($content as $contentRow): ?>
<?php
echo $contentRow->value;
?>
<?php endforeach; ?>
This works fine for HTML strings like:
<h2><strong>Example Text</strong></h2>
however I have some image content that I would like to display and I have tried the following database entries to no avail:
<img src="<?php echo site_url('pathToImage/Image.png'); ?>" alt="Cover">"
<img src="site_url('pathToImage/Image.png')" alt="Cover\">"
I feel like I am missing a step on how to use PHP values in this way.
How do I access the URL of the image and use that to show the image?
Full Code Edit
<?php
$CI =& get_instance();
?>
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="col-md-2"></div>
<div class="col-md-20">
<!--<form class="form-center" method="post" action="<?php echo site_url(''); ?>" role="form">-->
<!-- <h2 class="">Title</h2>
<h2 class=""SubTitle/h2>-->
<?php echo $this->session->userdata('someValue'); ?>
<!--//<table class="" id="">-->
<?php foreach($content as $contentRow): ?>
<tr>
<td><?php
echo $contentRow->value;
?></td>
</tr>
<?php endforeach; ?>
<!--</table>-->
<!--</form>-->
</div>
<div class="col-md-2"></div>
</div>
</div>
</div><!-- /.container -->
and the values are being read out in $contentRow->value;
I have to verify this, but to me it looks like you are echo'ing a string with a PHP function. The function site_url() is not executed, but simply displayed. You can execute it by running the eval() function. But I have to add this function can be very dangerous and its use is not recommended.
Update:
To sum up some comments: The use of eval() is discouraged! You should reconsider / rethink your design. Maybe the use of tags which are replaced by HTML are a solution (Thanks to Manfred Radlwimmer). Always keep in mind to never trust the data you display, always filter and check!
I'm not going to accept this answer as #Philipp Palmtag's answer helped me out alot more and this is more supplementary information.
Because I'm reading data from the database it seems a sensible place to leave some information about what content is stored. In the same table that the content is stored I have added a "content type" field.
In my view I can then read this content type and render appropriately for the content that is stored. If it is just text I can leave it as HTML markup, images all I need to do is specify the file path and then I can scale this as I see fit.
I have updated my view to something akin to this and the if/else statement can be added to in the future if required:
<?php foreach($content as $contentRow): ?>
<?php if ($contentRow->type != "image"): ?>
<?php echo $contentRow->value; ?>
<?php else: ?>
<?php echo "<img src=\"".site_url($contentRow->value)."\">"; ?>
<?php endif; ?>
<?php endforeach; ?>
I made a custom template for the team I'm working on. I used this code for the template (along with the parts that get the header and footer ofc)
<div class="main-container">
<?php
the_post();
$thumbnail = has_post_thumbnail();
?>
<section class="section-header overlay preserve3d">
<div class="background-image-holder parallax-background">
<?php the_post_thumbnail('full', array('class' => 'background-image')); ?>
</div>
</section>
<section>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="article-body">
<?php
if(!( $thumbnail ))
the_title('<h1>','</h1>');
the_content();
wp_link_pages();
?>
</div><!--end of article snippet-->
</div>
</div>
</div>
</section>
But if there's no featured image, a gray box will appear. I'd rather just have the whole section be hidden if there is no featured image, because it will look much better.
I'm a php rookie so I have no idea how to do this. What I think I need to do: Have an if/else statement check for the featured image. If there is no image, add a class to said section and define 'display none' in my css file for that class.
So this is the code I tried to pair with that, but it did not work:
<?php
// Must be inside a loop.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
$("section:first").addClass("noshow");
}
?>
Is this code incorrect? Where do I need to place this in my document for it to work?
While PHP is executed on the server, jquery is executed on the user end. You could always echo that jquery statement and that way it would be sent to the user.
You could follow the path Martin E. said on his comment (which in my opinion is a much cleaner version) or you could pursue the way you were working on by adding jquery on your header if you haven't and trying something like this:
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
echo '<script>$("section:first").addClass("noshow");</script>';
}
?>
I'm trying to load a php file into a div#main when a link is clicked. The html content loads but the actual php code included in the file does not. Here's what I've got:
Link to trigger everything:
<a id="nav" href="http://domain.com/inc/file.php">
jQuery:
jQuery(document).ready(function($) {
$("#nav").on('click', function (e) {
e.preventDefault();
$("#main").empty();
$.ajax({
url: $("#nav").attr('href')
}).done(function(data) {
$('#main').html(data); // display data
});
});
});
Code from file.php (mostly WordPress functions):
<div id="hostels" class="section cf">
<?php get_a_post(31); ?>
<article id="swiss" <?php post_class('swiss bg col span-1-3'); ?> role="article">
<h3>
<a href="<?php the_permalink(); ?>">
<span class="logo-pl-small"><?php include(TEMPLATEPATH . '/library/svg/logo.svg'); ?></span>
<span class="">Swiss Cottage – London UK</span>
</a>
</h3>
<?php if ( has_post_thumbnail()) { the_post_thumbnail(); } ?>
<div class="entry-content">
<?php the_excerpt(); ?>
<?php edit_post_link( __( 'Edit', 'bonestheme' ) ); ?>
<?php if ( get_post_meta($post->ID, 'vidlink', true) ) {
echo apply_filters('the_content', get_post_meta($post->ID, 'vidlink', true));
} ?>
</div>
</article>
</div>
OUTPUT:
<div id="main">
<div id="hostels" class="section cf">
</div>
</div>
The file begins to load but as soon as <?php get_a_post(31); ?> is reached, the file does not continue to load.
I could be wrong, but I thought that by using $.ajax the php code would execute on the server and code it outputs would load into my #main div.
So I've got this somewhat working.
I found this tutorial for Ajax Powered Loops with jQuery and WordPress from which I discovered that (as I had guessed) the files I created need to understand WordPress functions. For this I need to include:
require_once('../../../../wp-load.php');
In my case that's the relevant path from file.php.
There's still some issues such as shortcodes generated from plugins not working fully, but that's beyond the scope of my original question.
There's a lot of useful info relating to ajax and Wordpress in the tutorial above though, if anyone is having similar issues I'd recommend having a read.
Instead of
$.ajax({
url: $("#nav").attr('href')
}).done(function(data) {
$('#main').html(data); // display data
});
why not the more simple
$("#main").load('http://domain.com/inc/file.php');
??
I'm currently in the process of making a portfolio website for myself, using a modified version the 'Gridly' wordpress theme. Here's the current website.
Right now I'm trying to implement the 'infinite scroll' plugin, but I can't seem to get it to work.
I'm not sure if anyone here is familiar with this specific plugin, but just in case, the selectors that I'm using are:
Content Selector: #post-area
Navigation Selector: .view-older
Next Selector: .view-older a:first
Item Selector: .post
I can't really tell what code would be relevant to post here, but here is what the index.php contains:
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<div id="post-area">
<?php while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) { ?>
<div class="gridly-image"><?php the_post_thumbnail( 'summary-image' ); ?></div>
<div class="gridly-category"><p><?php the_category(', ') ?></p></div>
<?php } ?>
<div class="gridly-copy"><h2><?php the_title(); ?></h2>
<p class="gridly-date"><?php the_time(get_option('date_format')); ?> </p>
<?php the_excerpt(); ?>
<p class="gridly-link"></p>
</div>
</div>
<?php endwhile; ?>
</div>
<?php else : ?>
<?php endif; ?>
<?php next_posts_link('<p class="view-older">View Older Entries</p>') ?>
<?php get_footer(); ?>
I've also set the behavior to Masonry/Isotope, and made sure the plugin is activated.
If anyone could help me solve this problem I'd hugely appreciate it. I'm (clearly) not a web developer, so please bear with me if any of this sounds silly.
I did it! For the benefit of anyone who might encounter the same problem, this was how I solved it:
Firstly, for some reason this theme included a 'view older posts' function, but it didn't include a 'view newer posts' one. I solved this by copying
<?php next_posts_link('<p class="view-older">View Older Entries</p>') ?>
and both creaing a div around the link, and adding another line of code, so that it states
<div ="navigation>
<?php next_posts_link('<p class="view-older">View Older Entries</p>') ?>
<?php previous_posts_link('<p class="view-newer">View Newer Entries</p>') ?>
</div>
Next, I changed the infinite scroll selectors to
Content Selector: #post-area
Navigation Selector: #navigation
Next Selector: #navigation a:first
Item Selector: #post-area .post
Hopefully that will help if anyone else encounters a similar issue. :)
Not really an answer, I'm afraid, but it's too long for a comment. Your link ends up a bit screwy in the HTML, with an a wrapped around a p (which, though technically 'legal' with your doctype, isn't a good idea).
View Older Entries</p>
Not sure how a:first is meant to be targeted, or what it refers to.