How can I add advertisement script inside yii framework loop? - javascript

I am trying to add an horizontal ad in between the content. An example article of my website is: http://articlefirm.com/biography/penny-taylor-age-net-worth-biography-twitter.html. I would like the ad to come somewhere inside the content.
The website is on YII framework. Here's the content code:
<?php echo $page->detail; ?>
Please let me know how could I add script inside the above given code.

you can change your main.php layout and add the code for show the ads as you like this way
if you need pass some php vars to the main.php layout
a simple way is add property to your controller
class YourController extends CController {
public $myParam;
then assign in your action the values you need for params
eg:
$this->myParam ='my_adv';
and then in your layout you can simple
<?php echo $this->myParam; ?>
otherwise if you don't need pass params form controller/action
you can simply change you views/layouts/main.php
adding the conde you need
<?php
echo 'here i cand add the adv i need before the view content';
?>
<?php echo $content; ?>

Related

Change html code in php when I have many same php files

I have question if is it even possible.
I have contact.php home.php and porfolio.php .
In every single site I have exacly same header (include "header.php") and only what I need is change one h1. I mean on every site have different title of h1. Is there any possible way, to change on every site html code differently ?
Like every site have same header.php but every time different h1..
Or should I make like "one half of code.php" .. CHANGEABLE CONTENT .. "second half of code.php.
Or should I do it in javascript ? like onload function and if site is contact.php then change h1.innerHTML on "".. ?
<body>
<?php include "./components/header.php"; ?>
</body>
I'm pretty sure someone on stackoverflow have answered a similar question but you can do something like
<body>
<?php
$h1Content = "put your desired h1 content here";
include "./components/header.php";
?>
</body>
Then in your header.php, do
<h1><?php echo $h1Content ?></h1>
You can also use an isset to check or set a default value
<h1><?php echo isset($h1Content)? $h1Content : 'Default Value' ?></h1>
you can achieve this easily. All you have to do is to assign header value to an variable and then use that variable in your header file.
//header.php file
<h1><?php echo $mainHeader; ?></h1>
and then before you inject the header you have to init that value on each site
<?php $mainHeader = 'Hello world'; ?>
<body>
<?php include "./components/header.php"; ?>
</body>

Adding widget to WordPress frontpage

I created a website in WordPress (Website: Link) using this theme.
I would like to know, how can I add a [timeline-express] widget after the image slider?
(I tried to modify idyllic-functions.php, using:
...
</div> <!-- end .main-slider -->';
echo $idyllic_category_sliders_display;
echo add_filter( 'widget_text', 'timeline-express');
...
,but the site crashes.)
Open this file: idyllic/inc/front-page/front-page-features.php and add this following line on line 34:
<?php echo do_shortcode('[timeline-express]'); ?>
Just above this line:
<div class="our-feature-box <?php echo esc_attr($feature_box_class); ?>">
So, your updated code will be also follows:
<?php echo do_shortcode('[timeline-express]'); ?>
<div class="our-feature-box <?php echo esc_attr($feature_box_class); ?>">
Note that, it's always a good practice to create a child theme, copy file/template to the child theme directory, and then modify your codes. Otherwise, you will lose your modified codes once the theme is updated.
PS: please try to follow what #tacoshy mentioned in his comment while asking questions in stackoverflow.

How to reuse same mixed code snippets by both PHP and JS? Best practice?

I'm just starting to learn JavaScript and PHP and am having troubles with this seemingly simple problem - how do I code reusable HTML snippets so they can be used both for JS and PHP?
Here's a case example - I have a simple .php page like this:
<body> <?php
foreach( $members_array as $member ) {
$id = $member->id;
$name = $member->name;
$img = $member->get_img();
include( 'single-member.php' );
}
foreach( $other_members_array as $member ) {
$id = $member->id;
$name = $member->name; ?>
<button type="button" onclick="addExtraMember" data-user-id="<?= $id? >">ADD <?= $name ?></button> <?php
}
</body>
Where for each member in the array a html code is dynamically generated with the variables. The 'single-member.php' is this:
<div id="<?= $id ?>">
<img src="<?= $img ?>">
<p><?= $name ?></p>
</div>
Then when the page finishes loading all the members are listed. The user of the page can click on one of the $other_members_array buttons that calls a JavaScript function. This JavaScript function should add the same code as 'single-member.php' after the last 'single-member.php' element to keep with visual consistency and in case I need to change the structure and styling of the snippet it's only in one file. I was googling this all afternoon today and here are my basic solutions:
rename the file to .html then load() and replace the attributes and text fields in JS
via .php page include one extra 'single-member.php' with empty values, a unique id and without displaying it so JS could grab it from the HTML DOM for re-use (in case the $members_array is empty)
don't load the members via PHP, add them all with JS when the page finishes loading using a reworked 'single-member.html' snippet without the PHP variables. So when a button is pressed JS function can use the 'single-member.html' again
I have a feeling this is a common problem - reusing elements and snippets between JS and PHP so I was wondering what the best practice is?
Also am I missing some more elegant library or solution?

Get source code of element in PHP

I have a container which has dynamic content in it. The content can be edited by users with an inline editor called Froala Editor.
<div id="froala-editor">
DYNAMIC HTML CONTENT
</div>
I want to output the source code generated by the froala editor into a php variable.
I have tried using froala editor's function for it, but it does not get any result.
$('div#froala-editor').froalaEditor('html.get');
I also tried to write my own function:
<?php
ob_start();
?>
<script>
document.write($('div#froala-editord').html());
</script>
<?php
$output = ob_get_contents();
ob_end_clean();
$html_output = htmlentities($output);
echo "<pre>";
echo $html_output;
echo "</pre>";
?>
But this snippet gives the result:
<script>
document.write($('div#froala-editor').html());
</script>
What I want is to get the source code of the #froala-editor div and store it in a php variable.
I also tried to use file_get_contents() but the file that has this div also has dynamic content in it.
Also tried the Simple HTML DOM Parser but it gives back an error using file_get_contents()
When the user finished editing the content with the editor, I want to submit a form with a hidden element that has the value of the edited content's source code.

Passing $data variable to iframe from controller in CodeIgniter

I want to display a page in iframe. This page contains email contents since I am building an inbuilt email system. But the CSS of the email contents are overriding my CSS styles. Now this page gets some data from $data variable which I Pass through controller.
To avoid getting my CSS style issues I am thinking of displaying that page in an iframe. (If anybody has any other solutions, welcome).
inboxdetailspage.php --> View which displays email contents
mailactions.php --> controller which passes $data to inboxdetailspage.php
This is the function that does it.
function viewInboxDetails(){
$mailId = $this->uri->segment('4');
$data['emailInfo'] = $this->fetchParticularEmailInfo($mailId);
$data['titleText'] = 'Email Information';
$this->load->view('admin/inboxdetailspage',$data);
}
I am absolutely blank on how to achieve this feature
Passing data to the IFRAME from the same controller is not possible.
IFRAMEs' are just basically another URL display on a particular page. Hence all you can do is can pass the data via URL and thats it!
How this can be achieved this is create another (say) link for displaying the mail content by taking the ID from the URL and display that URL in iFrame. For example,
Controller:
public function all_mails()
{
$data['mails'] = $this->xyz_model->get_mails();
$this->load->view('all_mails.php', $data);
}
public function mail_content($mail_id)
{
$data['mail'] = $this->xyz_model->get_mail_content($mail_id);
$this->load->view('mail_content.php', $data);
}
View:
all_mails.php
<?php foreach($mails as $mail) { ?>
<table>
<tr>
<td><?php echo $mail->from; ?></td>
<td><?php echo $mail->subject; ?></td>
<!-- Your email content -->
<td>
<iframe src="/xyz/mail_content/<?php echo $mail->id; ?>"></iframe>
</td>
</tr>
</table>
<?php } ?>
mail_content.php
<!-- Your CSS here -->
<link href="/static/home/css/bootstrap.min.css" rel="stylesheet">
<div>
<?php echo $mail->content; ?>
</div>
First pass $data to your view and from there call another controller which can render your whole iframe from it with its own view.
Create an iframe in the view linking to another function in controller(a new page). In this page display only email contents according to the email.

Categories

Resources