I have this plugin installed "Category Images" which basically helps me add an image for a category. it works fine.
but when i view my post, say for example a post from category "movies". can i use the background image of the category(movies) has the background image for single post of category(movies)?
this helps me get the link of the category image.(plugin)
<?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?>
i tried this code
<style type="text/css">
body.single{
background-image:url(<?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?>);
}
</style>
thank you
If you want to address the body element, the following could work:
<?php if ( is_single() && function_exists('z_taxonomy_image_url') ): ?>
<style type="text/css">
body {
background-image:url(<?php echo z_taxonomy_image_url(); ?>);
}
</style>
<?php endif; ?>
http://codex.wordpress.org/Function_Reference/is_single
...you also might need to pass the image function a category ID, if you're not on a archive page:
<?php $category = get_the_category(); ?>
background-image:url(<?php echo z_taxonomy_image_url(category[0]->term_id); ?>);
http://codex.wordpress.org/Function_Reference/get_the_category
Perhaps you meant:
body .single{
instead of
body.single{
Related
Is there a way to get a thumbnail from any website link? For example, if I take a link from imgur and post it on my website in the post itself, it shows the image. But when I go to the homepage of my website there is no featured image for that post. Just a great box. How could I generate a featured image of any link I posted from an external website?
I have used the video thumbnail plugin but it only works with certain websites.
try going into page.php of your theme, then search for the_post_thmbnail(). There add the image link
change this line:
<?php the_post_thumbnail(); ?>
to something like this:
<?php $name = get_post_meta($post->ID, 'ExternalUrl', true);
if( $name ) { ?>
<?php the_post_thumbnail(); ?>
<?php } else {
the_post_thumbnail();
} ?>
hope this helps :)
I have wordpress site and I'm using this script
onclick="<?php if(!isset($_COOKIE['visited'])){echo"window.open('http://link', '_blank')"; setcookie("visited", "1", time()+3600*24); header("Refresh:0");} ?>"
in body line. So it means I'm using
<body <?php body_class(); ?> onclick="<?php if(!isset($_COOKIE['visited'])){echo"window.open('http://link', '_blank')"; setcookie("visited", "1", time()+3600*24); header("Refresh:0");} ?>">
on header.php file of the theme.
But it opens the link in every click.
I want to open it only one time until I refresh the page or open new page.
How can I do it.
Please help.
Thanks in advance.
Greetings.
Like the setcookie function reference says:
cookies must be sent before any output from your script
First solution
You could add this at the very top oh header.php:
<?php
$onclick = '';
if(!isset($_COOKIE['visited'])) {
setcookie('visited', '1', time()+3600*24, COOKIEPATH, COOKIE_DOMAIN);
$onclick = 'onclick="window.open(\'http://link\', \'_blank\')"';
}
?>
Update: I've added the constants COOKIEPATH and COOKIE_DOMAIN like explained here.
And this for your body tag:
<body <?php body_class(); ?> <?php echo $onclick; ?>>
Better solution
The prior solution doesn't ensure the cookie is set before any output sent (there could be some characters in one of you template files before get_header() is called, or a plugin could add something).
Instead you should add an action to a Wordpress hook that is always called before any output (like init).
So try adding to your functions.php file:
add_action('init', 'set_visited_cookie');
function set_visited_cookie() {
if (!isset($_COOKIE['visited'])) {
setcookie('visited', '1', strtotime('+1 day'), COOKIEPATH, COOKIE_DOMAIN);
}
}
As for your body tag:
<body <?php body_class(); ?> <?php if(!isset($_COOKIE['visited'])): ?> onclick="window.open('http://link', '_blank')" <?php endif; ?>>
I have a wordpress site, that need to show pages using swipe, I choose to use Jquery Mobile, and I get it working fine. Now, we have 2 languages on site, using wpml plugin. And my Swipe Code works well, except when we use Change language button swipe fails.
Details on issue.
We have only 3 Text Only page in our website, in 2 language. And in Footer we have link to change language. Also client hate to have Ajax page loading, so what I did is I create three Div with data-role=page and put data-next, data-prev as #div-$postid. So the navigation works absolute fine. I put footer outside from data-role=page.
Now, when I click change button in footer, it load the english page [I saw it using Fiddler] and then take first data-role=page from server and replace /slide its content. However since it only pick the first data role, all other english page doesn't get in HTML [it just update DOM and doesn't navigate to english version]. so swipe fails as other english pages are not in dom.
Also, footer is not changing, so what I want is: can we simple force a Link to navigate instead of going swipe way? Jquery Mobile is enforcing swipe on all A tags, I do not want swipe to works anything outside data-role=page.
Hope I make sense.
Edit here is code: [not sure if this code will help at all]
<?php
get_header();
global $post;
$args = array('post_type' => 'mobile_slide','showposts' => '-1', "order" => "DESC");
$the_query = new WP_Query($args);
if($the_query->have_posts()){
while($the_query->have_posts()) { $the_query->the_post();
$prev =get_previous_post();
$next =get_next_post();
if($prev) {
$prev = "#page-" . $prev->ID; //get_permalink($prev->ID);
} else {
$prev='';
}
if($next) {
$next = "#page-".$next->ID; //get_permalink($next->ID);
} else {
$next='';
}
if (has_post_thumbnail( $post->ID ) ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'slider_image' ); ?>
<div id="page-<?php echo $post->ID; ?>" data-dom-cache="true" data-transition="slide" class="page" data-role="page" data-prev="<?php echo $prev; ?>" data-next="<?php echo $next; ?>" style="background-image:url('<?php echo $image[0]; ?>'); background-position:center center; background-color:#000; background-repeat:no-repeat; ">
<?php } else { ?>
<div id="page-<?php echo $post->ID; ?>" data-dom-cache="true" data-transition="slide" class="page" data-role="page" data-prev="<?php echo $prev; ?>" data-next="<?php echo $next; ?>">
<?php } ?>
<div class="post_box">
<h2><blockquote><?php the_title(); ?></blockquote></h2>
<div class="post_entry">
<?php the_content(); ?>
</div>
</div><!-- post_box -->
</div>
<?php }
} ?>
<?php get_footer(); ?>
This is all I have, except that get_footer use Ul li based list where on LI change based on language variable, to show different images for either language.
To stop Ajax from loading pages/links, add to link anchor data-rel="external" or data-ajax="false". This will load page normally without any transition.
Reference: jQuery Mobile - Links
For those who have similar problem, I fix it by using following:
1) I add a "noswipe" class to A Tag so I can refer it in Jquery
2) I add following code
$(function(){
$(".noswipe").click(function(){
window.location.href= $(this).attr("href");
return false;
});
});
The above code simply enforce to skip the Mobile's parsing and calling and works for my case.
In a wordpress site, i have defined a default NOT_FOUND_IMAGE in timthumb config file:
// "http://example.com/timthumb-config.php".
<?php
if(! defined('NOT_FOUND_IMAGE') ) define ('NOT_FOUND_IMAGE', 'http://example.com/img/default.jpg');
Is there any way to force resizing of this image depending on timthumb request parameters. For instance:
// 404 occurs
timthumb.php?src=http:%2F%2Fexample.com%2Fimg%2F404-image.jpg&h=180&w=120
// get resized (cropped) default image
timthumb.php?src=http:%2F%2Fexample.com%2Fimg%2Fdefault.jpg&h=180&w=120
Try this code:
if (!defined('NOT_FOUND_IMAGE'))
define ('NOT_FOUND_IMAGE','images/ingredient.jpg');
I don't rate timbthumb, and I think it has security issues. Install and use the ThumbGen plugin instead.
You can then use it really easily with a normal editable conditional php statement.. (Pseudo)
<?php if you have a thumbnail {
Output the img with thumbgen resized
} else {
Output the no image, you can even use thumbgen if you want
}
?>
Real world example:
<?php if ( has_post_thumbnail() )
{
$image_id = get_post_thumbnail_id();
$alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
$image_url = wp_get_attachment_image_src($image_id,'large');
$image_url = $image_url[0];
?>
<img src='<?php thumbGen($image_url,175,175, "crop=1"); ?>' />
<?php
}
else
{
?>
<img src="<?php bloginfo('template_url');?>/images/no-photo.png" alt="No Photo!">
<?php
}
?>
I'm trying to have different pictures on every one of my pages built on wordpress.
So I have the following in my index.php file, archive.php file, page.php file, etc:
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $toppic; ?>" alt="page1" id="mainPageImg" />
Now, in my page.php file, I have the following:
<?php
// TOP PICTURE DEFINITIONS
if ( is_home() ) {
$toppic == 'page1.png';
}
if ( is_page('articles') ) {
$toppic == 'page2.png';
}
?>
How come this does not work? I tried it with one equal (=) sign...
EDIT: If I define $toppic at the top, for example, in the index.php file as follows:
<?php $toppic = 'page1.png'; ?>
Then it works. So therefore, it must be something that has to do with the conditional if is_page/is_home statements. Any ideas?
Thanks!
Amit
Okay, I found the answer.
This is what needs to be done. For the articles (blog) page, at the top section you need to place the following:
<?php // TOP PICTURE DEFINITION FOR ARTICLES PAGE
if ( is_home() ) {
$toppic = 'page1.png';
}
?>
Then, in your page.php file, you can control the picture at the top for all other pages (except 404, where you'd need to put a is_404() in your 404.php. So this is what it looks like:
<?php
// TOP PICTURE DEFINITIONS
if ( is_page('english') ) {
$toppic = 'page1.png';
}
if ( is_page('aboutus') ) {
$toppic = 'page1.png';
}
if ( is_page('newspaper') ) {
$toppic = 'page1.png';
}
else {
$toppic = 'page1.png';
}
?>
And finally, in order to implement this, use the following HTML/php syntax:
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $toppic ?>" alt="page1" id="mainPageImg" />
That's all. Phew. Finally got it to work :) Had to do it for a client, too!
The slug for your Articles page has to be defined as articles. This is set in the edit page interface, see these directions.