get_template_part vs the_content? - wordpress

I have looked at several themes, and I see that "the loop" often works something like this:
while (have_posts()) {
the_post();
get_template_part('content');
}
The code that I developed for my theme looks like the following:
while (have_posts()) {
the_post();
the_content();
}
My code works as well, and it was something I came up with before I looked at the code for the other themes. I understand that there must be a reason why get_template_part('content') is used, rather than the_content(). I think the reason has something to do with the ability to customize things in a child theme, but I have scrutinized the documentation and the WordPress code, and I can't really figure out what the difference is exactly.
So what is the advantages of using get_template_part('content') overthe_content()?

get_template_part('content') & the_content() both are very different thing for use.
the_content() -> this will directly take only content of the editor area of your page from admin to front.
get_template_part('content') -> this will call to a file named content.php in your theme folder & take out put from that file, this file may can include html tags too after & before content of editor area.
in general case for all theme content.php has basic output code of editor, but when you are using any custom template then you may can use the_content() for easiness.

Related

Removing Comment Section and Date in Wordpress Projects and Posts

I was just wondering if there is a simple way to hide the comment box and date in WP posts and projects. I've followed everything and have unchecked the options under the screen options tab for both projects and posts and they are still showing. Anything other than good old CSS to hide this stuff?
Thanks!
Gerard
You can erase the HTML source code directly in yours templates files.
Open up your theme files, and look for your single.php file.
Look for a post meta section, and simply comment out/delete the part that generates the date, more than likely
<?php the_date(); ?>
Towards the bottom of the single.php file, there will most likely be some code that adds the comments form, again simply delete or comment it out, maybe: <?php comment_form(); ?>

How to add custom content in sidebar of each Wordpress post?

I want to integrate specific text (text, links, images) making reference to specific sentences of my blog post.
Is it possible to do it with code or using a plugin ?
I send you a sketch :
This is the sketch
That is common need and often Aside in WordPress is talked for it. There are WP plugins like Aside Widget, Custom Sidebars for ordinary needs. But if you need too much custom stuff like my website's "About this Article" sidebar widget - https://thecustomizewindows.com/2016/09/limitations-of-openvz-virtualization-to-guest-cloud-server-vps/ then it is better to use
Otto's this plugin to use PHP in text widget - https://wordpress.org/plugins/php-code-widget/ and use PHP. In my case, rest is PHP code like this on sidebar (I can use shortcode too) :
<?php if(is_single()) : ?>
<h3>About This Article</h3>
<strong>Title:</strong> <?php echo get_the_title(); ?><br />
Published on: <?php the_time('Y-m-d') ?>
<br />
...
// rest of the code
<?php endif; ?>
Obviously you can call post image thumbnail with WordPress function.
As you need specific text, you may think about combining Pull Quote Plugin or Aside Widget to mark the specific like and echo it with PHP.
As other options -- you can use CSS3 to automatically select first line, first paragraph, second sentence. You can use Javascript to conditionally mark.
Best possible customisation I saw is on BMJ's sidebars. They use Drupal, not WordPress. BMJ has beautiful sidebar -- (as example) - http://www.bmj.com/content/355/bmj.i4924 Drupal has description of the work - https://www.drupal.org/node/1557636 Sadly I lack idea about Drupal. I tried a lot behind using WordPress for academic purpose.

Blog page with theme completely different from the main theme?

I have been trying to make my website on Wordpress. I am using Brave Zeenat as my primary and Grido as my blog theme.
I have read many tutorials in places, which discuss how to apply a customized flavour of the main theme on a static page, e.g. Blog. However, the main theme I am using does not appeal to me as a blog theme at all, so I wanted to do something entirely different, so I have tried two methods.
First, I tried to just create a page named Blog and force it to take a theme of my choice using the Page Theme plugin. That worked instantly, but the blog page is empty and would not accept articles of certain categories by default like this.
Second, I tried to not use any plugin at all, and use a custom PHP file instead, which sets some loops and calls a theme. This file blog.php had to be in the main theme directory, otherwise it would not be applicable as a template from the page settings in Wordpress dash.
So I put it with my main theme, but call to load the other theme, like this:
<?php
/*
Template Name: Blog
*/
$paged = get_query_var('paged');
query_posts('cat=0&paged='.$paged);
global $more;
$more = 0;
load_template(WP_CONTENT_DIR . '/themes/grido_v1.0.1/index.php');
?>
Eventually I only want to see category no.9, but for now, I left it as 0, which should display all categories. But when I run this with Page Theme plugin disabled, I get this error: Fatal error: Call to undefined function themify_get() in /var/sites/v/visualdeceptions.info/public_html/wp-content/themes/grido_v1.0.1/index.php on line 10.
Now, although this is a themify error, I am sure if I try to use other premium themes as well, I will encounter very similar errors, because I have only set a custom php file, and no style, header, footer, etc. But I am not sure how to do it.
Try to add getheader() and getfooter() in the code
<?php
/*
Template Name: Blog
*/
get_header(); //HERE
$paged = get_query_var('paged');
query_posts('cat=0&paged='.$paged);
global $more;
$more = 0;
load_template(WP_CONTENT_DIR . '/themes/grido_v1.0.1/index.php');
get_footer(); //HERE
?>

How to show more links in custom query_posts and custom loops

In This Page http://atthy.com/blog/
I'm using Custom template to show the list of blog posts, Since, I use home.php file to display custom home page. I use query_posts() since its a custom template. I created a page in wp admin with the custom blog Home template. Everything is fine. But I can't get read more.. links to work, when using the_content('read more..')
When I use the_content('read more..') whole post content is displayed without cutting it off after <!--more--> and also, read more link is not showing up.
I read through wp codex http://codex.wordpress.org/Function_Reference/query_posts and even resetted global $more to 0
Here is the page template I'm using. http://pastebin.com/VTvN5dtT
What am I doing wrong?? Please Help.
I've not tested this myself, but according to http://codex.wordpress.org/Customizing_the_Read_More#How_to_use_Read_More_in_Pages, the
global $more;
$more = 0;
needs to be inside the loop and before the_content('read more..');. As such, in your pastebin code, move lines 15-16 to line 30. Like I said, I've not tested this, but give it a whirl and see what happens.
You need to make sure that the statements:
global $more;
$more = 0;
are placed after the call to the_post()

widgets_on_pages not working

Hello i'm using widgets_on_pages to place widgets on pages, i installed it and added a widget to the panel in my admin section, then i added [widgets_on_pages id=2] ("its the 2nd sidebar and it said i should add this") into my html on the place where the widget should appear but it only shows the code i added in pure text, nothing else happens, anyone know what i'm doing wrong?
If I understand correctly then the following applies... if not, apologies.
You should not need to do it this way. It seems that Vincent, you are trying to add the shortcode into a theme php file... this is incorrect and the shortcode is for adding into the page/post content by the post/page editor.
To add a Widgets on Pages sidebar to a template then v 0.0.7 (I believe) has built in template tags (see link text). This should allow you to add the following I think
<?php widgets_on_template("2"); ?>
Try this
<?php echo do_shortcode('[widgets_on_pages id=2]'] ?>

Resources