Showing Number of Comments without the Link - wordpress

When I use <?php comments_number('0', '1', '%'); ?> this code, that come with span HTML code. I need to show number of comments on a tag's title attribute. So how can I?
<div class="comment">
</div>
this is how is it looking

You can get the numeric value using get_comments_number():
<div class="comment">
</div>

Related

How to target specific line of text within text-widget in WordPress?

I have this html:
<aside id="secondary" class="widget-area col-md-4"
role="complementary">
<div id="text-3" class="widget widget_text">
<div class="textwidget"><p><strong>Sign In</strong>.
</p>
<p><strong>Create Account</strong></p>
<p><strong>Find your next employee on Adsler
</strong></p>
</div>
</div></aside><!-- #secondary -->
I want to target Find your next employee on Adsler
Tried.
.textwidget:nth-of-type (3) {font-size: 30px}
Nothing. Should I be doing something else?
Easiest way to achieve this is using javascript or jQuery
<script>
$( ".textwidget:contains('Find your next employee on Adsler')" ).css( {fontSize: "50px"} );
<script>
This script will find all the strings 'Find your next employee on Adsler' under specified class/id.
You can add the script directly in the js file or add this jquery code by downloading a plugin naming as "simple custom css & js"
Hope this will work.
Place a text widget in the sidebar on the page and place the following html in it.
<span style="font-size: large;">Foobar</span>

How to avoid the unwanted <p></p> tags while getting the post in Wordpress

I'm trying to get the data from a post using the following snippet:
<div class="marquee-container row marquee-row">
<?php
$post = get_post(415);
if(isset($post->post_status) && $post->post_status == 'publish') {
echo apply_filters('the_content', $post->post_content);
}
?>
</div>
But when I inspect the element, I found some unwanted <p></p> tags which are unnecessarily introducing gaps.
<div class="marquee-container row marquee-row">
<p> </p>
<div class="some-class">Content from the post</div>
<p></p>
</div>
How to avoid this unwanted tags ?
Note: This tags are not being inserted to table, being introduce while trying to get the post.
Thank you for your help.
can you please check that content from admin side in text tab(Where you add the contents for page or post)? If you have pressed Enter key then it will take that as <p></p> tag in content.
Remove blank spaces from editor if it is not necessary.

inner nested shortcodes not working - eg: columns not showing inside of row

I wanted to create specially styled columns, but make it easy for the client to still edit the content of the column.. so I created my own shortcodes to setup the row and columns inside. (This is a custom wordpress template I created for a specific client).
Here is the code in my function.php for the two shortcodes 'member-row' & 'member':
add_shortcode('member-row', function ($content = null) {
return '<div class="row">
<br />'.do_shortcode($content).'</div>';
});
add_shortcode('member', function ($atts, $content = null) {
extract(shortcode_atts(array(
'color' => 'white',
), $atts));
return '<div class="col-md-6 col-sm-6 col-xs-12 md-margin-bottom-40">
<div class="member-col funny-boxes funny-boxes-top-'.$color.'">'.do_shortcode($content).'</div>
</div>';
});
I've also added the .do_shortcode($content). on the inner-nested 'member' column shortcode - just in case the client wants to add other shortcodes inside of each column. (Note: The problem still occurs even if I change the 'member' shortcode to just use .$content.)
Here is the code I entered in the text side of the wordpress page editor
[member-row]
[member color="gold"]
<img class="aligncenter img-responsive" src="http://localhost/test/testWP/wp-content/uploads/2015/07/logo1.jpg" alt="logo" />
<strong>Company 1</strong>
Address
Telephone
www.example1.com
[/member][member color="yellow"]
<img class="aligncenter img-responsive" src="http://localhost/test/testWP/wp-content/uploads/2015/07/logo2.jpg" alt="logo" />
<strong>Company 2</strong>
Address
Telephone
www.example2.com
[/member]
[/member-row]
When I save, and click on 'view page', the section where this has been added doesn't display anything.
This is the html code that is produced:
<div class="row">
<br /></div>
So it is only executing the 'member-row' shortcode, and not the nested 'member' shortcode columns.
This is the correct html code I was expecting:
<div class="row">
<br />
<div class="col-md-6 col-sm-6 col-xs-12 md-margin-bottom-40">
<div class="member-col funny-boxes funny-boxes-top-gold">
<img class="aligncenter img-responsive" src="http://localhost/test/testWP/wp-content/uploads/2015/07/logo1.jpg" alt="logo" />
<strong>Company 1</strong>
Address
Telephone
www.example1.com
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-12 md-margin-bottom-40">
<div class="member-col funny-boxes funny-boxes-top-yellow">
<img class="aligncenter img-responsive" src="http://localhost/test/testWP/wp-content/uploads/2015/07/logo2.jpg" alt="logo" />
<strong>Company 2</strong>
Address
Telephone
www.example2.com
</div>
</div>
</div>
When I just remove the surrounding [member-row] and [/member-row] shortcodes from the editor window, then the 'member' column shortcode does show up properly on the webpage.. so it appears it is just being inside of the 'member-row' shortcode that causes the problem.
Note: I did try adding the add_filter('the_content', 'do_shortcode', 10); line to the bottom of my function.php file, but it didn't seem to make any difference, so I removed it.
Hopefully I have just made some typo error.. Any help will be greatly appreciated!
Thanks.
I figured out the problem.
I had to add $atts to the function for the member-row shortcode as follows:
add_shortcode('member-row', function ($atts, $content = null) {
return '<div class="row">
<br />'.do_shortcode($content).'</div>';
});
It now works as expected!!
I am not sure why I needed to add $atts, as this shortcode is not passing attributes or setting default ones, but it appears you need it if you are going to use enclosing shortcode with $content. (Maybe it is needed because $content is defined as the 'second' parameter???)
I just read in the WP Codex for shortcode api that
"Three parameters {$atts, $content, $tag} are passed to the shortcode
callback function. You can choose to use any number of them including
none of them."
So that seems to me that you could use the $content by itself... but as I just proved that $content can't be by itself - I am still unsure of the reason that my solution worked for me. (Just glad it did!)
If anyone knows the rule or reason for why the $atts is needed to make this work, I would appreciate the comment - to clarify this for myself, and anyone else that has the same problem.
Thanks!

Woocommerce's Cart page is being overwritten by my Page.php page in Wordpress

I'm having a little bit of a problem. My page.php seems to be overriding WooCommerce's cart page. The page is already created (generated by WooCommerce with the shortcode intact) named Cart.
I know that my page.php is overriding it, but I don't know how to stop that. Here is the code for my page.php page:
<?php
get_header();
if ( have_posts() ) {
//Work with us page
$workwithuspage = "work with us";
$pitch = "pitch an idea";
$cart = "cart";
if($workwithuspage == strtolower(get_the_title()))
{
//Page stuff here!
$image = wpse_get_images();
?>
</div>
<div class="hero">
<div class="container heroImage" style="background-image:url('<?php echo $image->guid;?>');">
<div class="col-md-7"></div>
<div class="col-md-5">
<div class="pageText">
Work with Us
</div>
<div class="subText">
<?php echo $image->post_content; ?>
</div>
</div>
</div>
</div>
<div class="bodyBg">
<div class="container">
<div class="col-md-6">
<div class="box-style">
<div class="box-header">
Got a comic idea and want it published?
</div>
<div class="box-text">
Tell us your desires, so we can slap it on a comic book and sell it for millions. Ya dig?
</div>
<div class="box-button-container">
<?php
$pitch = get_page_by_title('pitch an idea');
?>
<div class="button large">Pitch an Idea</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="box-style">
<div class="box-header">
Want to work on one of our great titles?
</div>
<div class="box-text">
Tell us your desires, so we can slap it on a comic book and sell it for millions. Ya dig?
</div>
<div class="box-button-container">
<div class="button large">Find Jobs</div>
</div>
</div>
</div>
</div>
</div>
<div id="ourstandards">
<div class="coloroverlay">
<div class="container">
<div class="col-md-6">
<div class="pageHeaderText">
Our Standards
</div>
<div class="bodyTxt">
<p>
At On Target Network, we strive to promote consistency,
communication and passion in all areas of work and we expect the same of our artists.
</p>
<p>
We understand the nature of creators and seek to raise ourselves to higher and higher standards. To do that, we vet and
review series pitches with a carefully selected panel of writers and artists.
</p>
<br /><br />
<p>
Got questions? We'll be happy to help.
</p>
<div id="sendUsQ" class="secondaryBtn">
Send us your questions
</div>
</div>
</div>
<div class="col-md-6"></div>
</div>
</div>
</div>
<div class="container">
<?php
}
else if($pitch == strtolower(get_the_title()))
{
?>
</div>
<div id="pitchImg" class="hero">
<div class="container">
<div class="col-md-7"></div>
<div class="col-md-5">
<div class="pageText">
Pitch an Idea
</div>
<div class="subText">
<?php echo $image->post_content; ?>
</div>
</div>
</div>
</div>
<div class="bodyBg">
<div class="container">
<div class="col-md-12">
<div class="pageHeaderText dark">
Start your pitch here
</div>
</div>
<div class="col-md-9">
<?php
if ( isset($si_contact_form) ) {
echo $si_contact_form->si_contact_form_short_code( array( 'form' => '1' ) );
}
?>
</div>
</div>
</div>
<?php
}
}
get_footer();
?>
I have conditional ifs for pages I wanted to customize, but I fear in doing that, it has overridden (somehow) the cart page.
WooCommerce adds the cart using shortcodes; shortcodes get displayed as part of the page content. WP uses the the_content() function to display the content for a particular page or post. You've removed the_content() from your page template, therefore the cart doesn't display.
Looking at your page template, you've removed the_content() and inlined all your content directly into the template rather than fetching it from the database. This is atypical of a WP site in general, but I understand that sometimes a site starts off static and you just want to get it 'into' WP.
You're also using a bunch conditionals to display different chunks of content, which runs against the idea of using templates. My suggestion would be to create separate page templates for your 'pitch' and 'work with us' pages, and make page.php just a default page template that has the_content(). This way you have a generic template you can use for any page, including the cart page.
Check the codex for more info on creating custom page templates, but in a nutshell, you add a comment to the top of the file:
<?php
/*
Template Name: My Custom Page
*/
Then save your file in your theme folder. Common practice is to name it along the line of page-pitch.php so you can easily identify it. Then in the admin area you can assign the template to any page you want simply by selecting it from the drop down menu.
Splitting your different content into separate templates has a couple of benefits; namely you no longer have to use conditionals for checking the page titles (which can vary from install to install) and makes it much easier for you to debug things.

Drupal 7 - Where can I find templates for render() function?

While I was creating my custom template for node, I found out that Drupal adds extra html.
so I changed page.tpl.php like below to test
<div style='height:300px'>
<?php print render($page['content']); ?>
</div>
and then changed node.tpl.php to
hello
the output is:
<div style='height:300px'>
<div class="region region-content">
<div id="block-system-main" class="block block-system">
<div class="content">
hello </div>
</div>
</div>
</div>
where do all those extra tags come from?
I actually expected <div style='height:300px'>hello</div>
drupal_render() can be used to render so called renderable arrays. These are self-contained, they tell render() which theme function/template to use.
Try dpm($page['content']), that should then have a '#theme' key that contains that information.
Nice one with the dpm.
To print the h2 and body you could write something like this in the page.tpl.php.
<?php print render($page['content']['system_main']['nodes'][1]); ?></div> ?>

Resources