Using an include inside an echo - php

I am trying to insert this search form into my wordpress header. I found where php calls for the user-uploaded logo, and would like to insert the form immediately after.
Search form include:
<?php include ('wp-content/themes/thematic/searchform.php'); ?>
Functions.php echo:
function childtheme_override_blogtitle(){
global $up_options;
echo '<div id="blog-title"><span><img src="' . $up_options->logo . '" alt="" /></span></div>';
}
add_action('thematic_header','childtheme_override_blogtitle',3);
function childtheme_override_blogdescription(){
I tried inserting the form as a separate div, but this keeps the form from centering with the rest of the main content. So I am trying insert the form where php creates the div. You can see my current progress here: texturly.com

There's a function for including the theme's searchform..
http://codex.wordpress.org/Function_Reference/get_search_form
Just call it inside your function or appropriate file.
<?php get_search_form(); ?>
There's an example filter on the above codex page to, should you want to override searchform markup from within your functions file.
EDIT: Regarding placement inside the function, i'd write it a little something like this.
function childtheme_override_blogtitle(){
global $up_options;
?>
<div id="blog-title">
<span><img src="<?php echo $up_options->logo; ?>" alt="" /></span>
<?php get_search_form(); ?>
</div>
<?php
}
Of course move that search form where you want it, i just reformatted how the HTML is generated so you'll have an easier time adjusting it.
Hope that helps.

Related

How can I add a image click function to gallery.php temp code?

Ok so here is the link to the template code for gallery.
https://github.com/JoomShaper/Helix-Joomla/blob/master/helixPlugin/shortcodes/gallery.php
However when I insert images on my database (not in Php), the image shows up but I am unable to click that image and be directed to the images page, which I have hyperlinked on my database (Joomla). I will have multiple images where I will need to add this click function to.
I have been trying to figure this out forever. I am new to Php and coding, so forgive my ignorant use of word choices from the above paragraphs.
(I've noticed in the past when speaking to coders it is frustrating for them to code the jargon from a someone who doesn't know the language ha!) Thanks!
Sorry, I know this is not an answer probably, but I cannot comment yet. I have been looking at your code for a little while, and I noticed some things I wanted to ask you about. First:
<?php foreach ($galleryArray as $key=>$item) { ?>
<li style="width:<?php echo round(100/$columns); ?>%" class="<?php echo str_replace(',', ' ', $item['tag']) ?>">
<a class="img-polaroid" data-toggle="modal" href="<?php echo ($modal=='yes')? '#modal-' . $key . '':'#' ?>">
<?php
echo '<img alt=" " src="' . $item['src'] . '" />';
?>
<?php if($item['content'] !='') { ?>
<div>
<div>
<?php echo do_shortcode($item['content']); ?>
</div>
</div>
<?php } ?>
</a>
</li>
You begin your a and li inside the foreach loop, but you finish them outside of it. Considering that the a is your link, and your link is not working, I thought this could be part of your issue.
Also, I noticed that when you link to the modal, you use the same variables from the loop, but the variables were defined inside the loop and would not carry over on clicking the link that was generated. It seems to me that you would need to define a property value with the variable you need from each one, so that you can use JS to do something along the lines of "onClick" grab "this.property.value" so that you could have that information in the modal.
I only thought this was of note because the modal you are opening with the link is named by one of these variables. Unless you are creating a separate modal for each one inside the foreach loop, the name you are linking to does not exist. Sorry if this is confusing.

How to force a wordpress template to parse code instead of plain-text

I have recently installed a new template(more specifically SquirrelTheme - a free template) in my wordpress blog. It happens that I would like to have two buttons on my front page. Let's say button X and button Y. For creating these buttons I use a plugin called "MaxButtons" which allows you to easily create and manage a button and it's functions. After creating the said button, it gives you a shortcode that you can insert in your posts and pages - lets say [maxbutton id="1"] - to display it.
Unfortunately, after editing the template to my liking(removing divs I didn't intend to display), I can't seem to display these two buttons as the template parses plain-text, unlike the pages/posts apparently.
In case you are wondering how I am inserting the shortcode for the buttons, the template can be easily modified through the dashboard, in which I inserted the following in the field that dictates what is displayed on the specific part of my homepage:
[maxbutton id="1"] [maxbutton id="2"]
Like I said before, instead of showing the buttons as intended, I just see exactly what I type in the box.
I believe this is caused by how the template parses the text, as it uses its own function(? - php _e('...')) to echo the text:
<div class="full_content">
<center>
<?php if (squirrel_get_option('squirrel_slidehead') != '') { ?>
<h1><?php echo stripslashes(squirrel_get_option('squirrel_slidehead')); ?></h1>
<?php } else { ?>
<h1><?php _e('We are scope, a design firm in England', 'squirrel'); ?></h1>
<?php } ?>
<?php if (squirrel_get_option('squirrel_slidedesc') != '') { ?>
<h2><?php echo stripslashes(squirrel_get_option('squirrel_slidedesc')); ?></h2>
<?php } else { ?>
<p><?php _e('Newfoundland dogs are good to save children from drowning, but you must have a pond of water handy and a child.', 'squirrel') ?></p>
<p><?php _e('From drowning, but you must have a pond of water handy and a child.', 'squirrel'); ?></p>
<?php } ?>
</center>
</div>
My question is, how can I get it to display the buttons or any other code.
Thanks in advance.
You can call the function do_shortcode() to do the proper shortcode processing on some text.
Example:
echo do_shortcode('This is a button: [maxbutton id="1"]');

Load different div at home template in wordpress

I am working on a custom wordpress homepage.
I want that it is loading in a different div in the header.
The header now loads the #content div for every page. But i want to let it load #contenthome div if the homepage loads.
I'm using this php-code:
<?php if (is_page_template('template-home.php')) { ?>
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
I'm fairly new to php. so i hope you guys can help me :)
Thanks a lot.
Or this:
if(is_home())
{
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
Personally, I prefer writing things in shorthand when it comes to cases like these. Consider also using this to shorten your code:
<div id="<?php echo is_home() ? 'contenthome' : 'content'; ?>">
ADDITIONAL NOTES: If your <body> tag has the Wordpress body_class() added to it, you can pretty much target individual pages with CSS, even when they're using the same template. The homepage, like any other page, will have a unique body class applied that will then allow you to target that particular page.
So if your issue is simply a matter of being able to target any given page regardless of template with CSS, you won't necessarily NEED to apply any unique divs to your page. For example:
<style type="text/css">
#content{display:block;}
.home #content{display:none;}
</style>
This will hide the content div only on the homepage. It's probably not what you want it to do, but you can see how the page itself is being targeted to override the default behavior.
UPDATE: As per your latest question, if you need another particular page to use that conditional, use is_page() like so:
LONG CODE:
if(is_home() || is_page('posts_page_title'))
{
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
SHORTHAND:
<div id="<?php echo is_home() || is_page('posts_page_title') ? 'contenthome' : 'content'; ?>">
If you prefer, you may also use is_page('posts_page_ID') or is_page('posts_page_slug'). Play around with it and see what works best for you. More information here: http://codex.wordpress.org/Function_Reference/is_page
With reference to this post Try this one....
$pagename = get_query_var('pagename');
if ($pagename = 'template-home.php') {
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
it seems like you already created a file in your theme just for the homepage and you called it template-home.php
from this point you have two options:
1) you can just define a constant (or variable) and decide what div to use only when it is defined; if you will use a variable remember that in header.php you are in fact inside a function (get_header) and you will need to use global to have access to it
2) if you foresee any other differences between the structure of the header between the main page and the rest of your wordpress you could use another file for the header. to do this, in your template-home.php file give a parameter to the get_header function, like get_header('home')
if you do this header-home.php will be loaded instead of header.php

Display certain HTML in an Automatically generated PHP page?

How can I display a certain HTML code in a php generated page.
For example, php will automatically display the name and category of an item, yet I want to add custom pictures to this generated page. Is there any way to do this without creating a separate HTML page to include into the generated page?
I'm hoping for something like a database entry where to add the html part to display. Is it possible?
ps. Sorry if I didn't express my idea in a completely understandable way.
Store the image URLs just like you are storing the names and categories. Then you would just do something like:
<span id="name"><?= $name ?></span>
<span id="category"><?= $category ?></span>
<img src="<?= $image ?>" />
Maybe you need to clarify - why do you need different HTML for each page, if the only thing changing are the images?
Keep in mind here I use <?= $foo ?> which is generally considered bad practice, and is just shorthand for <?php echo $foo; ?>.
Just wrap the PHP in your HTML:
<h1>My Test</h1>
<?= $myCategory; ?> - <?= $myItem; ?>
<img src ="mySource" alt="myImg" width="15" height="15" />
This also works for your HTML in your Database:
<p><?= $myDatabaseHTMLContent ?></p>
Cheers,
Max
<?php
//Your php code
?>
<img src="" />
<?php
//Your php code
?>
You can put html in a php file, like the example above.

How would I properly insert this PHP into an <a> tag's title?

I know this code isn't correct, but I would like to inject the HTML and PHP into the title of the below tag.
<p class="related_articles" title="<?php echo the_field(related_articles_1_title); ?>"Related Articles</p>
I am using a jQuery tooltip plugin (http://flowplayer.org/tools/tooltip/index.html) that grabs content from the title tag and displays it as the tooltip content. I have Advanced Custom Fields setup (WordPress plugin) that allows me to publish custom field content. In effect, the content I post in these custom fields will end up in the tooltip.
My goal is to produce a tooltip when the user hovers over "Related Articles", that displays a link that is clickable. Again, the above jQuery tooltip plugin grabs the content from the title, which is why this is causing difficulty
Ok, as we understand what you are trying to do. Lets get some things clear.
<p class="related_articles" title="<?php echo the_field(related_articles_1_title); ?>"Related Articles</p>
Is SO wrong on so many levels. First of all things, its not valid in any way. Second of all, you are not ending your <a>. You are also missing one echo and target="", inside title="" was not escaped: target=\"\".
So in a nutshell to straight up answer your question, this maybe will work (maybe, because its seriously uncommon and nonstandard)
<p class="related_articles" title="<?php echo the_field(related_articles_1_title); ?>">Related Articles</p>
Also, as one of the users already mentioned. If your server server enables short open tags, then you could make the <?php echo $foo; ?> shorter: <?= $foo ?>. So in your codes case it would look like:
<p class="related_articles" title="<?= the_field(related_articles_1_title) ?>">Related Articles</p>
However, as probably mentioned already. This is not recommended method and may produce all sort of issues. I recommend to research for a better solution.
Use the short form if your server supports it:
<?=the_field(related_articles_1_link)?>
or else, you should echo it:
<?php echo the_field(related_articles_1_link); ?>
<p class="related_articles" title="<?php echo htmlspecialchars(''. the_field(related_articles_1_title) .''); ?>">Related Articles</p>
While this should work, I am not sure if your mentioned jQuery plugin is able to interpret the given html in a title attribute as HTML (you need to test it). Most likely this will be interpreted as text and all tags will be visible to the end user, but this is not what you want.
I found an example of how to implement this in a different manner: http://flowplayer.org/tools/demos/tooltip/any-html.html
Is it possible that this is what you want?
<p class="related_articles">
Related Articles:
<a href="<?php echo the_field(related_articles_1_link); ?>" target="_blank">
<?php echo the_field(related_articles_1_title); ?>
</a>
</p>
Now that you've clarified that your question was regarding the jQuery Tooltip plugin, you should do the following:
<p class="related_articles">Related Articles</p>
<a class="tooltip" href="<?php the_field(related_articles_1_link); ?>" target="_blank">
<?php echo the_field(related_articles_1_title); ?>
</a>
Javascript:
$('.related_articles').tooltip();
The reason this works:
The tooltip plugin looks at the element right after the one which .tooltip() was applied to. If that next element has a class name of tooltip, it'll use that as the contents of the tooltip (instead of the title attribute).
Given that you are placing html content inside an HTML property it should be escaped. As mentioned by #Karolis do this:
<p class="related_articles" title="<?php echo htmlentities(''.the_field(related_articles_1_title).''); ?>">Related Articles</p>
This should generate a tooltip with the link in it. If you see stuff like "& lt;a href="... & gt;" on the tooltip then the plugin is not unescaping html values. You could unescape the values but unfortunately javascript has no function. For this you can check out php.js
which provides php's functions in js but that seems kinda overkill. You could instead replace the troublesome characters like this:
<?php
// Generate complete tootltip content
$tootltipContent = ''.the_field(related_articles_link_1).'';
// Search for these
$search = array('<','>','"');
// And replace them with these
$replacements = array('##','##','\"');
$tooltipContent = str_replace($search,$replacements,$tooltipContent);
?>
<p class="related_articles" title="<?php echo $tooltipContent; ?>">Related Stuff</p>
Then look for the line in the plugin where the title is extracted from the element. (tip: on the plugin source code do a search for 'title'. There should be one place where the value is being extracted) It may look something like this tooltipContent = $(someVar).attr('title'); Now run the inverse replacement in js:
tooltipContent = tooltipContent.replace('##','<').replace('##','>').replace('\"','"');

Categories