How to display disqus on home page - wordpress

I have a problem with disqus plugin on wordpress. How to display disqus on home page. so the single page is to be a home page, maybe like that.
Any idea to solve it?
Thanks.

I am also unable to get disqus to work on homepage.
I can force the comments_template to appear by setting the following variable:
$withcomments = 1;
which makes the comments.php template appear but the discus plugin only kicks in if its on other pages other than home page.
Its as if the plugin itself prevents it if is_home() rather than listening to wp $withcomments variable
UPDATE
Can be fixed with plugin hack to disqus.php:
In function dsq_comments_template change the conditional if(!(is_singular() && ( have_comments() || 'open' == $post->comment_status ))
In mycase where I wanted it to work on home and an aggregate page for a custom taxonomy 'issue' I did the following:
after global $comments;
made a var for the more complex condition (it can go in the if instead)
$pass = (is_home() || is_taxonomy('issue')) || (is_singular() && ( have_comments() || 'open' == $post->comment_status ));
if(!$pass) {
return
}
... the rest of function ...
Be great if the developer made an option for this condition instead

not sure what you mean. Any comment plugin generally replace your current comment template and place their comment system. So make sure your comments_template(); in right place.
Please send details of your problem.

There's a Disqus tutorial with step-by-step instructions for a CMS. Does that help you with your installation?
I'm not sure what you mean by "not the disqus comment, just the standard comment", though. Can you explain?

I found this worked great, but the
if(!$pass) { return }
was breaking the page, I replaced
if ( !( is_singular() && ( have_comments() || 'open' == $post->comment_status ) ) ) {
return;
}
with
if ($pass = (is_home() || is_taxonomy('issue')) || (is_singular() && ( have_comments() || 'open' == $post->comment_status ))) {
}
leaving out the if(!pass){return}
not sure why

Related

Wordpress is_user_logged_in && is_page not working

Anyone can advise on why the following is not working, and maybe provide a better alternative?
if ( !is_user_logged_in() && is_page( 'shopping-cart' ) ) {
echo '<div style="position:absolute;bottom:0;width:100%;">Please login in order to proceed with the checkout.</div>';
} else {
echo '<div style="position:absolute;bottom:0;width:100%;">You are logged in.</div>';
}
Basically I am not logged in, and the 'You are logged in' message still appears, on any page. I've added the code to the theme footer, if it matters.
Thank you.
Solved, thanks to Gautam Golakiya.
The page shopping-cart was generated by a plugin but did not exist in the Page section, so after creating a black page with the same slug, the code started to behave as it should. Basically nothing wrong with it.

Wordpress: Trying to use update_option_optionname

I am trying to add a tracking mechanism to my wordpress plugin. And I want to use the WP cron mechanism. So I have an options page and when users save all options I want to use a hook to remove or add the tracking to the wp cron depending of the admins choice.
But right now I am stuck.
I have:
register_setting ( 'my-settings-group', 'myplugin_tracking');
add_action ( 'update_option_myplugin_tracking', 'myplugin_schedule_tracking' );
function myplugin_schedule_tracking($old_value, $new_value)
{
echo "Setting is updated!";
echo $old_value;
}
But this does not seem to work. I also used:
add_filter ( 'update_option_myplugin_tracking', 'myplugin_schedule_tracking' );
The option is saved in a form that posts to the options.php if that matters.
What am I doing wrong? Hope somebody can help out as I cannot find much information about doing something upon updating an option!
Thank you.
Okay this seems to work after all.
register_setting ( 'my-settings-group', 'myplugin_tracking');
function myplugin_schedule_tracking($old_value, $new_value)
{
if ($old_value !== $new_value)
{
if ($new_value == '')
{
wp_clear_scheduled_hook( 'myplugin_tracking' );
}
elseif ($new_value == 'on' && $current_schedule == FALSE)
{
wp_schedule_event( time(), 'hourly', 'myplugin_tracking' );
}
}
}
add_filter ( 'update_option_myplugin_tracking', 'myplugin_schedule_tracking', 10, 2);
add_action ( 'myplugin_tracking', 'myplugin_tracking' );
In the function myplugin_tracking you do whatever you have to do to track.
My problem was that I did not see the echo on the screen but it did appear to work after all.
Perhaps not the best code but it may be helpful for others :-)

WordPress Search goes to post page when you do a blank search

Yea so on my wordpress theme I've put together...
When you click the search button (with the search field empty) it takes you to the blog page. I have assigned the index.php as the blog page and made another page and assigned that as the home page.
Can anyone help? Its not a major problem but it is a little glitch I would like to get rid of.
Thanks.
Terry
I also faced the same problem, it is default given by wordpress.
but luckily I found something which helped me.
Add below in "Functions.php"
function SearchFilter($query) {
// If 's' request variable is set but empty
if (isset($_GET['s']) && empty($_GET['s']) && $query->is_main_query()){
$query->is_search = true;
$query->is_home = false;
}
return $query;}
add_filter('pre_get_posts','SearchFilter');
and then replace below line(line no 15) in search.php
<?php if ( have_posts() && strlen( trim(get_search_query()) ) != 0 ) : ?>
Might be it will help you too
For details read this : Customize empty search wordpress

Wordpress if post or blog category statement

got a little problem here on Wordpress.
I am trying to use PHP to check whether the page I am on is a category page or a post page if it isn't on either it will do something else nothing.
The code I have is:
<?php if( (!is_category($category)) || (!is_single($post)) ) { ?>
Do something...
<?php } ?>
When I try it without the or the category bit works fine. When I join them together the code stops working.
I think what you're actually trying to test is if it's not a category and not a post. So change your condition accordingly:
if( (!is_category($category)) && (!is_single($post)) ) {

wordpress conditional statements

I'm trying to get this logic to work in WordPress Widget Logic:
Widget displays if it's NOT the homepage OR NOT the page 86 OR NOT if it's a child of page 86.
!is_home || !is_page('86') || !is_child('86')
I've added this function to functions.php:
function is_child($parent) {
global $post;
return $post->post_parent == $parent;
}
try this:
(!is_home() && !is_page(86) && !is_child(86))
is_home() is a function. And to check the pages I suggest using a integer not a string.
And the overall ( ) is just a safety measure. Maybe you can leave them out, I'm not sure.
Not tested.

Resources