How to create a column shortcode in footer of wordpress - wordpress

I want to separate the three columns and each column having five rows in footer area of my wordpress site.. I don't know how to use short code for that.. Can anyone help me..
For example Like this footer I need using shortcode..

If you're intending to do it using a shortcode then use the following code to create it;
`<?php
function firstshortcode_function() {
*//Your Code Should Be Written Here!*
return 'My first shortcode';
}
add_shortcode('firstshortcode', 'firstshortcode_function');
?>`
.. and use this [firstshortcode] shortcode wherever you would like to call it.
Note: You can replace the function name with anything you like and replace the shortcode appropriately.
To add HTML content under it, use the following code;
<?php
function my_custom_shortcode( $atts ) {
/ Turn on buffering /
ob_start(); ?>
<div>
// YOUR HTML CODE GOES HERE
<h1>Test</h1>
<p>My content</p>
</div>
<?php
/ Get the buffered content into a var /
$sc = ob_get_contents();
/ Clean buffer /
ob_end_clean();
/ Return the content as usual /
return $sc;
}
add_shortcode( 'shortcode', 'my_custom_shortcode' );
?>

Related

What's the best/most common approach to multiple sections front page in WordPress

I'm new to WordPress and I'm thinking about developing some premium themes. I see that a real trend these days is these themes with multiple sections separated in horizontal blocks in the first page. Stuff like this:
<section class="about-us row">
<h1> About us</h1>
<p>Some lorem here </p>
</section>
<section class="features row">
<h1> Features</h1>
<div class="col-1-3">
<h2>Responsive and shit</h2>
<p>Some lorem here </p>
</div>
<div class="col-1-3">
<h2>Free support</h2>
......
</section>
<section class="testimonials">
........
</section>
I'd like to know what's the best or most common approach devs are taking to provide this feature for their end-users.
I see that some of the best selling themes are using page builders managing it as shortcodes, but I'm not planning to use any page builder, at least not in my first theme, I noted that it's quite easy to get a messy code when using them, so I want to start simple.
So guys, can you help me? would the answer be using just shortcodes?
Thank you
Step 1:
I would suggest breaking the layout into sections using the get_template_part() function in your front-page template. The benefit of this is you can simply call for whatever part of the layout you need in any page template like so: get_template_part('testimonials');. You can even use them in the header and footer if you need to.
In your case i'm assuming there are 3 template parts: about us, features, and testimonials. You will need to create 3 PHP files that contain all of the code for each of those 3 parts. The PHP files will need to be located in your template's root folder. The PHP file can obviously utilize PHP however you need it to, but the main idea is that your HTML code for that section or "template part" will be placed in it's own PHP file. If you need to pull posts from wordpress, or perform database queries to generate the content for that section, you can do so individually for each template part in it's own self-contained PHP file. For the purposes of this example, let's just assume that you've called the PHP files for your template parts about_us_part.php, features_part.php, and testimonials_part.php.
After you create your 3 PHP files, making sure they are placed in your template root, you simply place the following lines of code wherever you want that particular section or "template part" to appear in your Wordpress page template. Like so:
<?php get_template_part( 'about_us_part' ); // About Us (about_us_part.php) ?>
<?php get_template_part( 'features_part' ); // Features (features_part.php) ?>
<?php get_template_part( 'testimonials_part' ); // Testimonials (testimonials_part.php) ?>
Basically, get_template_part( '{slug}' ); searches for a filename in your template root matching {slug}.php. So you can name it whatever you want, but if there is no matching PHP file found, obviously nothing will show up. There is one other option for get_template_part() that allows you to specify a name for the template section. However it is optional and not required, you can use it like so:
<?php get_template_part( 'about_us_part', 'about-us' ); // About Us (about_us_part.php) ?>
<?php get_template_part( 'features_part', 'features' ); // Features (features_part.php) ?>
<?php get_template_part( 'testimonials_part', 'testimonials' ); // Testimonials (testimonials_part.php) ?>
You can read more about get_template_part() in the Wordpress codex here:
http://codex.wordpress.org/Function_Reference/get_template_part
Step 2:
Now say you wanted to allow the user to display these template parts using shortcodes, you'd need to give them that ability in your functions.php file. For instance, say we wanted to create 3 shortcodes for each of the 3 template parts above. You can do it pretty easily using the Wordpress Shortcode API. You'd add the following code to your functions.php file:
[about_us]
function themeprefix_about_us_shortcode( $attr ) {
ob_start(); // Start output buffer
get_template_part( 'about_us_part' ); //Get about_us_part.php
return ob_get_clean(); //Clear output buffer
}
add_shortcode( 'about_us', 'themeprefix_about_us_shortcode' );
Once that function is in your functions.php file, along with the matching add_shortcode() function users can call out the About Us section by using the shortcode [about_us]. The two parts of the add_shortcode() function are the shortcode name, and the function that generates the content for the shortcode. Like so: add_shortcode( '{shortcode name}', '{shortcode function}' );
You'd need to create 2 more for your other 2 shortcodes:
[features]
function themeprefix_features_shortcode( $attr ) {
ob_start(); // Start output buffer
get_template_part( 'features_part' ); //Get features_part.php
return ob_get_clean(); //Clear output buffer
}
add_shortcode( 'features', 'themeprefix_features_shortcode' );
[testimonials]
function themeprefix_testimonials_shortcode( $attr ) {
ob_start(); // Start output buffer
get_template_part( 'testimonials_part' ); //Get testimonials_part.php
return ob_get_clean(); //Clear output buffer
}
add_shortcode( 'testimonials', 'themeprefix_testimonials_shortcode' );
Note: I placed "themeprefix" on the front of each function. I'd reccomend replacing that with your theme name, or whatever prefix you might be using on the front of your theme's function names. However the function name can be whatever you want it to be, just be sure to update your add_shortcode() to the new function name.
You can read more about add_shortcode() in the Wordpress codex here:
http://codex.wordpress.org/Function_Reference/add_shortcode
Also, I reccomend reading the Shortcode API page in the codex to learn how to add parameters to your shortcodes:
http://codex.wordpress.org/Shortcode_API

Wordpress: Add content to edit.php

I'm trying to find out what action hook/filter I can use to insert content on the admin "edit.php" page (i want to place a few links above the 'posts' table)? I've found "edit_form_after_title" and "edit_form_after_editor" (these do exactly what I want to do, but they are for posts.php, not edit.php).
With the help of this answer: How do you create a custom edit.php / edit pages page
I came up with this:
<?php
# Called only in /wp-admin/edit.php pages
add_action( 'load-edit.php', function() {
add_filter( 'views_edit-talk', 'talk_tabs' ); // talk is my custom post type
});
# echo the tabs
function talk_tabs() {
echo '
<h2 class="nav-tab-wrapper">
<a class="nav-tab" href="admin.php?page=guests">Profiles</a>
<a class="nav-tab nav-tab-active" href="edit.php?post_type=talk">Talks</a>
<a class="nav-tab" href="edit.php?post_type=offer">Offers</a>
</h2>
';
}
?>
And it looks like this:
If you just wanted to add to the post title link you could do something like this
if (is_admin()) {
add_filter('the_title', function($title) {
return $before_title . $title . $after_title;
});
}
however, it doesn't sound like you want to add text to the title link.
To add html after the title and before the actions links, you could do like this
if (is_admin()) {
add_filter('post_row_actions', function($args) {
// echo your custom content here
return $args; // and dont forget to return the actions
});
}
There is also page_row_actions for the page edit screen (post_row_actions is only for posts)
As far as adding stuff before the title, I don't see a hook/filter to do that. See wp-admin/class-wp-posts-list-table.php line 463 function single_row if you want to look for yourself.

wordpress template file quick tag more no working

i created a page template to be used as my front/home page with the wordpress loop in it, here is the code:
<?php query_posts('posts_per_page=10'); ?>
<?php
/* Run the loop to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-index.php and that will be used instead.
*/
get_template_part( 'loop', 'idex' );
?>
but the problem is that the qiuicktag <!--more--> is not working , they always show the whole content. isn't the <!--more--> stored in the database?
I think the tag is just stored inside the text of the field post_content in the wp_posts table.
If you do not want WordPress to show the whole content, then use "the_excerpt" or call "the_content" in your loop with the correct parameters:
http://codex.wordpress.org/Customizing_the_Read_More
Just use a conditional tag in your loop.php where you call "the_content":
if(is_home() || is_front_page()) {
the_excerpt(); // or the_content( $more_link_text , $strip_teaser, $more_file );
} else {
the_content();
}
I hope this solves the problem. Otherwise there could be a bug or problem with your template regarding the "the_content"-function.

How do I append to the end of the comments array in WordPress?

I'm trying to include something at the end of the comments array for a WordPress plugin.
I currently have add_filter('comments_array', 'my_function'), where my_function($comments='') is something along the lines of:
my_function($comments='') {
echo 'something';
return $comments;
}
I obviously can't return the comments first, and echoing them doesn't work because $comments is a multi-dimensional array. Is there some way I can print the WordPress comments and then append something to them?
Thanks.
You want to add something that looks like a comment or add arbitrary html under each comment block?
Can you add to the page template(s) what you want to appear under the comments block? I.e.,
<?php comments_template(); ?>
html or php here
<?php endwhile; else: ?>

Adding custom tags in Wordpress

I'm creating a new WP theme and I would like to allow the user to insert a divider in between paragraphs or images he/she is entering, for a post/page.
I want the output to be something like:
<div class="divider"></div>
But I don't want the user to have to enter HTML in the WYSIWYG editor. Is it possible to ask them to enter something like:
<-- break -->
and then translate that to the div markup on display?
Thanks.
Build a function in your theme's functions.php file like this:
function add_div( $content ) {
$content = str_replace( '<!-- break -->', '<div class="divider"></div>', $content );
return $content;
}
then add the following to the theme:
add_filter( "the_content", "add_div" );
The function uses PHP's string replace function to find the text you want your users to input and replace it with the text you want to render, the add_filter() function uses Wordpress's content filter to apply your function to the content of each post after it is read from the database, but before it is rendered to the browser.
This will work in PHP4 and up, which is still the official level of support for Wordpress.

Resources