Show jQuery/PHP Stock Ticker only to Home Page

Posted in: Newspaper
Post count: 75

Hi,
I would like to add this piece of code and show a custom ticker above the header ONLY to home page.
However, since there is no file dedicated to home page, when I add the code, it shows the ticker in all pages.
This is the part of code I want to add:

<?php

$str = file_get_contents('http://fc2b.inbroker.gr/AllInfo?company=INTARGET&userName=marketpostwebsite&IBSessionId=GFKLKS60-56DO-56OD-5897-JLKGKLD8954D&lang=GR&market=ATH&instrument=IDX&type=long&format=json');
//Now decode the JSON using json_decode():

$json = json_decode($str, true); // decode the JSON into an associative array
//You have an associative array containing all the information. To figure out how to access the values you need, you can do the following:
?>

<!-- Start ticker markup code-->
<!-- For more information about the markup code and how to customize it, see chapter "4.2.2. The markup code" of the guide. -->
<div class="modern-ticker mt-round">
<div class="mt-body">
<!--<div class="mt-label">NEWS:</div>-->
<div class="mt-news">

</div>
<div class="mt-controls">
<div class="mt-prev"></div>
<div class="mt-play"></div>
<div class="mt-next"></div>
</div>
</div>
</div>
<!-- End ticker markup code -->

<!-- Start ticker initialization code -->
<!-- For more information about the initialization code and the available settings, see chapter "4.2.3. The initialization code" of the guide. -->
<script type="text/javascript">
jQuery(document).ready(function() {

jQuery(".modern-ticker").modernTicker({
effect: "scroll",
scrollType: "continuous",
scrollStart: "inside",
scrollInterval: 20,
transitionTime: 500,
linksEnabled: true,
pauseOnHover: true,
autoplay: true
});

});
</script>
<!-- End ticker initialization code -->

Can you please help me with this issue?
Thank you in advance.

Post count: 20688

Hi,

You could wrap the whole code in a condition, to appear only on homepage
https://codex.wordpress.org/Function_Reference/is_front_page
That would be a solution in this case, to have the desired ticker appear only on the front page. You will probably have to edit the header template you use, to place it in the header.

Thanks

Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘Newspaper’ is closed to new topics and replies.