how to display wordpress title with conditional if else? - php

I added a title section in WordPress theme option for site title. I want that if that field is empty then it will display wp_title regular title with front page condition or the field is fill up then the title will display what written in the field. I tried this
<title>
<?php if (is_home()) {
$website_title = ot_get_option('website_title');
if (isset($website_title) && $website_title != "") {
echo $website_title;
} else {
is_front_page() ? bloginfo('description') : wp_title(''); bloginfo('name');
}
} else {
is_front_page() ? bloginfo('description') : wp_title(''); bloginfo('name');
}
?>
</title>
But this code works great in localhost of my computer and when i upload this code in website online it works as regular wp_title, no change happen from theme option. But from localhost theme option change is correctly.
If someone any idea please.

Related

How to show author name only on a post - Wordpress

This code should probably be a LOT smaller, but I can't seem to figure it out.
This is what I want:
[when the visitor is on a post]
Written by: the magnificent author of this piece
[When the visitor is on anything else then a post]
...... (nothing here)
Simply put:
This is the titel!!
Written by the magnificent author (I only want this to show on a post, not on > a page or any other page)
The text in the article is then shown here as normal. Regardless if
the author is shown or not.
This is the code I've got so far...
<?php
if (is_single() || is_page()) {
while (have_posts()):
the_post();
# page + post
wikiwp_get_thumbnail($post);
# post only
if (is_single()) {
?>
<?php
_e('<p>Written by:', 'wikiwp');
echo ' ';
the_author_posts_link();
?>
<?php
} else if (is_page()) {
Stuff that is shown when they are on a page
?>
<?php
}
endwhile;
} else {
The stuff that is shown when they are on anything else
?>
<?php
}
?>
The text of the article......
I'm pretty sure the code above doesn't make any sense.... But my limited PHP experience isn't really helping lol.

How to detect if is subpage in wordpress?

I want to make a check if im on a subpage. On the homepage it is :
<?php if(is_front_page()): ?> <?php endif; ?>
But how to do it when it is another page?
This is literally right from the docs:
There is no function to check if a page is a sub-page. We can get around the problem:
if ( is_page() && $post->post_parent > 0 ) {
echo "This is a child page";
}

magento - how to style only the pressed/active menu item related to the current page we are in?

i want to highlight only the pressed menu item in magento, can it be done?
i have tried to achieve this in many ways but none of them succeeded (i can list some of them here if it helps)
thank you
1 tried php get url and compare it to the text written inside the a tag
2 tried built-in methodes/id specific to magento
i have made some progress -i added this code to my template file -2columns-left.phtml
<?php
$routeName = Mage::app()->getRequest()->getRouteName();
echo $routeName;
$body_class = $this->getLayout()->getBlock('root')->getBodyClass();
echo $body_class;
if(strpos(strtolower($body_class),strtolower($routeName)) !== false){
$nav_active = "class = 'nav_active'";
}
?>
now i have added $nav_active to the body tag in the same file ,have tried this but it didnt work
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?><?php if(strpos(strtolower($body_class),strtolower($routeName)) !== false):?> echo $nav_active ;?>>
you can try with my alternative solution
it is working at my end
just do it like this
<?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'your_category_name') != false ) :?> active<?php endif;?>
hope this will sure help you.

implement multiple slider instances through wordpress plugin

i have customised the smooth div scroll jquery plugin (http://smoothdivscroll.com/) and implemented it in wordpress as a wordpress plugin along with an options page you can view the slider here http://dev.linuxfreakz.com/?page_id=2 , i have created an options page in wordpress admin which has 4 options to select the slider title , background and arrows color and category of posts . the slides are wordpress posts and the images inside them are their featured images . the slider can be currently used with a shortcode , this is all fine and working .
the problem is that now i am supposed to add multiple sliders that can have different options selected and can be used on a single page through the options page and i am confused as how to get this done . can some wordpress guru please point me in the right direction i am really running out of time here , i don't need the whole code just an idea as how i could actually get this done and i am pretty good at php and wordpress myself usually .
any help would be appreciated , thank you .
here is the code that pulls the posts and generates the slider that i am currently using
function sds_display_slider() {
global $post;
$sds_category2 = (get_option('sds_category') != false) ? get_option('sds_category') : 1;
$sds_title2 = (get_option('sds_title') != '') ? get_option('sds_title') : 'Smooth Slider';
$sds_bgcolor2 = (get_option('sds_bgcolor') != '') ? get_option('sds_bgcolor') : '#dedede';
$sds_navcolor2 = (get_option('sds_navcolor') != '') ? get_option('sds_navcolor') : '#9e1b32' ;
$plugins_url = plugins_url();
echo '<div id="carousel" style="background-color:'.$sds_bgcolor2.'!important;">
<style>
div.scrollingHotSpotLeft {background-color:'.$sds_navcolor2.';}
div.scrollingHotSpotRight{background-color:'.$sds_navcolor2.';}
</style>
<h2>'.$sds_title2.'</h2>
<div id="makeMeScrollable">';
query_posts('post_type=post&posts_per_page=-1&cat='.$sds_category2.'&order=ASC');
if ( have_posts() ) :while ( have_posts() ) : the_post();
$img_attached_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium');
$img_attached = $img_attached_url[0];
$post_heading = get_the_title($post->ID);
$post_text = substr(get_the_excerpt(),0,180)."...";
$link = get_permalink($post->ID);
echo '<div class="contentBox">
<a href="'.$link.'">
<img src="'.$img_attached.'"></a><br>
<h2>'.$post_heading.'</h2>
<p>'.$post_text.'</p>
</div>';
endwhile;
endif;wp_reset_query();
echo '</div>
</div>';
}
Try http://wordpress.org/plugins/meta-box/ and put your options page inside.

How to get the URL of the current page with the title and post it to Digg?

We have a Joomla site and have purchased a template from Gavick.
I need to change the code which is part of a template we have purchased.
If I hardcode the parameters associated to the Digg button as follows then I am taken to Digg's website submission link form and can add the details.
The current code in the template is as follows:
<?php if($this->template->params->get("icon2", 1) == 1) : ?>
<a href="<?php echo $this->template->params->get("icon2_link", ''); ?>"
class="social_icon" id="social_icon2" target="_blank">Digg</a><?php endif; ?>
What I need to do is get the URL of the current page along with the title and post this to Digg.
Never used Joomla but...
<?php if($this->template->params->get("icon2", 1) == 1) : ?>
<a href="http://digg.com/submit?Url=<?php echo $_SERVER["REQUEST_URI"]?>&title=<?=mainframe->getPageTitle()?>&no_mobile=1"
class="social_icon" id="social_icon2" target="_blank">Digg</a><?php endif; ?>
I don't know variable for title.

Categories