i have this code :
<?php include("Hedar.php"); ?>
<?php
$q=mysql_query("select * from news2 where id = $news2_id ");
list($news2_ides,$news_id,$name,$text,$stext,$ktext,$dtext,$date,$vews,$path)=mysql_fetch_array($q);
?>
<img src="upload1/<?php echo $path ?>"/>
<h2 class="_title"><?php echo $name ?></h2>
<?php echo $text ?>
<?php include("Footers.php"); ?>
------------
so as you can see i have a site in PHP code
so i want to insert 2 adsense code into $text
i tried to separat this $text to many but i fail with it
so anyone can help me to separate this ( <?php echo $text ?> )
thanks a lot
Regards
If am right you want to display adsense code with the $text variable
so you do:
<?php
$text.=$adsense
echo $text;
?>
If you are storing your adsense code in $adsense variable
Related
Hello everyone and thank you in advance that I will answer. I have this problem, I want to see the second page where I find a link that takes me home page blog if in other categories.
I developed this little code:
<div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
<?php $link_address = "http://testjoomla0315.altervista.org/index.php?option=com_k2&view=itemlist&layout=category&Itemid=53" ?>
<?php $homeblog = "Blog" ?>
<?php $doc = JFactory::getDocument(); ?>
<?php $page_title = $doc->getTitle(); ?>
<?php echo $page_title; ?>
<?php if ($page_title != $homeblog) ?>
<?php echo "<a href='".$link_address."'>Home Blog</a>"; ?>
<?php endif; ?>
<?php echo $this->escape($this->params->get('page_title')); ?>
Unfortunately although not error the result is the same, or as if what I wrote was invisible. In homepage obviously sees the home page link (and that is the rule I)
Your code is missing a colon at the end of if statement.
Change
if ($page_title != $homeblog)
To
if ($page_title != $homeblog):
Also dont use <?php and ?> every line. You can have the code like this
<div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
<?php
$link_address = "http://testjoomla0315.altervista.org/index.php?option=com_k2&view=itemlist&layout=category&Itemid=53";
$homeblog = "Blog";
$doc = JFactory::getDocument();
$page_title = $doc->getTitle();
echo $page_title;
if ($page_title != $homeblog):
echo "<a href='".$link_address."'>Home Blog</a>";
endif;
echo $this->escape($this->params->get('page_title'));
?>
I am trying to add the default category name on my site to a WordPress widget. Is there a way to pull this string (not the ID) automatically? I only have one category so i thought it would be easy, but none of the following are working:
<?php bloginfo('category'); ?>
<?php get_category(); ?>
<?php get_the_category(); ?>
<?php get_category([0]); ?>
<?php get_the_category([0]); ?>
<?php get_category([0]->cat_name); ?>
<?php get_the_category([0]->cat_name); ?>
<?php echo get_category(); ?>
<?php echo get_the_category(); ?>
<?php echo get_category([0]); ?>
<?php echo get_the_category([0]); ?>
<?php echo get_category([0]->cat_name); ?>
<?php echo get_the_category([0]->cat_name); ?>
Any help is appreciated...
UPDATE: 08/01/13 - Amal pushed me onto the right path. I ended up using the following and it worked perfectly...
<?php echo get_cat_name(get_option('default_category'));?>
Try this:
$category = get_category(get_option('default_category'));
I am trying to display RSS feed in my magento website and I'm having difficulties showing the image for the feed. Studying the feed, I see that the image is inside a content:encoded tag so I can't access it directly by using something like $item->image. Here's my current code:
<?php $channel = new Zend_Feed_Rss('newsfeedurl'); ?>
<?php foreach ($channel as $item): ?>
<?php if($i<2) { ?>
<img src="<?php echo $item->image; ?>" title="<?php echo $item->title; ?>" height="63" width="95" />
<?php echo "image:".$item->content; ?>
<?php } else {} ?>
<?php $i++; ?>
<?php endforeach; ?>
$?>
I tried also tried using $item->content but this returns the entire content of the newsfeed. So my question is, how can I access the image's source from content:encoded in order to display it on my feed?
UPDATE: After some more research, I tried using preg_match like so: preg_match('/<*img[^>]*src = ["\']?([^"\'])/i', $item->content, $matches); echo $matches[0]; I'm getting the correct image path but I've placed this inside a loop so each I should have at least 2 images but I'm only getting 1. why is this?
SOLVED: I've managed to solve my problem by changing $matches[0] to $matches[1]. I guess I was using 0 thinking it was the index of an array matches.
In order to get the image source from the content:encoded tag, I used regular expression (preg_match). Here's how my current code looks:
<?php $channel = new Zend_Feed_Rss('newsfeedurl'); ?>
<?php foreach ($channel as $item): ?>
<?php preg_match('/<*img[^>]*src *= *["\']?([^"\']*)/i', $item->content, $matches); ?>
<?php if($i<2) { ?>
<img src="<?php echo $matches[1]; ?>" title="<?php echo $item->title; ?>" height="63" width="95" /></a></div>
<?php } else {} ?>
<?php $i++; ?>
<?php endforeach; ?>
Hope this helps someone else.
For some reason I can't get my if-statement to echo out the HTML.
<?php
$my_description = meta('description');
if (!empty($my_description)): echo '<p class="description">'.$my_description.'</p>';
echo '<br>'; ?>
<?php endif; ?>
It only outputs the text, nothing else.
meta('description') is from a plugin in Wordpress that should output the text I placed in the backend. The above code ONLY outputs the following: Lorem Ipsum...
Update: I would like it to output:
<p class="description">Lorem Ipsum...</p>
After a discussion in chat, we discovered that the meta() function was not returning the value we expect. The correct function is get_post_meta
<?php
$my_description = get_post_meta(get_the_ID(), 'description', 1);
if (!empty($my_description)):
?>
<p class="description"><?php echo $my_description; ?></p>
<br>
<?php endif; ?>
Ugh... sooo ugly, just do it like this:
<?php
echo !empty($my_description) ? '<p class="description">'.$my_description.'</p>' : '<br />';
?>
Use the ternary operator, don't use that messy if formatting...
I'm working on adjusting my site title in Wordpress. I want my site title to admit the "Home >>" text from the title only on the homepage. Here is the code that i'm working with:
<title><?php if ( is_home() ) { ?> <?php } ?> <?php echo ucwords(wp_title('',false)); ?> » <?php echo ucwords(get_bloginfo('name')); ?> </title>
As i'm new to php, I'm trying decypher the coding. Would an if-else statement serve better?
<title><?php if ( is_home() )
echo "Blah blah blah";
else
echo "<?php echo ucwords(wp_title('',false)); ?>
» <?php echo
ucwords(get_bloginfo('name')); ?>";
?></title>
{ ?> <?php } ?>
<?php echo ucwords(wp_title('',false)); ?> » <?php echo ucwords(get_bloginfo('name')); ?>
</title>
I would greatly appreciate your opinion. My website is http://www.merrimentdesign.com
<title>
<?php if ( is_home() ) { ?> Home title, you don't need to echo something <?php } ?>
<?php echo ucwords(wp_title('',false)); ?> »
<?php echo ucwords(get_bloginfo('name')); ?>
</title>
Edit:
<title>
<?php
if ( is_home() ) { //I'm in the homepage
?>
Home title, you don't need to echo something
<?php
}else{ //every page but homepage
echo ucwords(wp_title('',false)) . '»' . ucwords(get_bloginfo('name'));
}
?>
</title>
An inline comparison would serve you well
<title>
<?php
echo (ishome()? "isHome evaluated to true": "isHome evaluated to false");
?>
</title>
Additionally nested PHP tags will not work and will simply throw errors.
IE
<?PHP
//everything in here is already php, if you add this:
echo "echo <?php doSomething(); ?>";
?>
Will not work because the ?> tag within your "echo" statement will be treated by PHP as the end of the PHP code block, not a string literal.
Instead of
echo "<?php echo ucwords(wp_title('',false));
just do
echo ucwords(wp_title('',false));
You can't echo PHP tags and have them be executed as PHP code.
That's what I do in my blog. But it won't work like it is - change it to:
<title><?php if ( is_home() )
echo "Blah blah blah";
else
echo ucwords(wp_title('',false)); ?>
»
<?php echo ucwords(get_bloginfo('name')); ?></title>