You get a bonus - 1 coin for daily activity. Now you have 1 coin

WORDPRESS 8. Post meta data.

Lecture



Today we will look at the concept of “meta-data of a post” or post-metadata: date, categories, author, number of comments, that is, any information attached to each post.

We are already in the eighth lesson, so I dare to hope you have already understood the basic principles of working with WordPress themes. You will notice that my instructions will be grouped into larger blocks (fewer steps). Before we get started, turn on Denwer , open the folder with the theme, the browser, and the index.php file.

Here is what should be in your index.php file at this stage:

?
01
02
03
04
05
06
07
08
09
ten
eleven
12
13
14
15
sixteen
17
18
nineteen
20
21
22
23
24
25
26
27
28
29
thirty
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head profile= "http://gmpg.org/xfn/11" >
     <title><?php bloginfo( 'name' ); ?><?php wp_title(); ?></title> ); ?><?php wp_title(); ?></title>
     <meta http-equiv= "Content-Type" content= "<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
     <meta name= "generator" content= "WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats please -->
     <link rel= "stylesheet" href= "<?php bloginfo('stylesheet_url'); ?>" type= "text/css" media= "screen" />
     <link rel= "alternate" type= "application/rss+xml" title= "RSS 2.0" href= "<?php bloginfo('rss2_url'); ?>" />
     <link rel= "alternate" type= "text/xml" title= "RSS .92" href= "<?php bloginfo('rss_url'); ?>" />
     <link rel= "alternate" type= "application/atom+xml" title= "Atom 0.3" href= "<?php bloginfo('atom_url'); ?>" />
     <link rel= "pingback" href= "<?php bloginfo('pingback_url'); ?>" />
     <?php wp_get_archives( 'type=monthly&format=link' ); ?> ); ?>
     <?php //comments_popup_script(); // off by default ?> //comments_popup_script(); // off by default ?>
     <?php wp_head(); ?>
</head>
<body>
<div id= "header" >
     <h1><a href= "?php bloginfo('url'); ?>" ><?php bloginfo( 'name' ); ?></a></h1> ); ?></a></h1>
     <?php bloginfo( 'description' ); ?> ); ?>
</div>
<div id= "container" >
     <?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?> (have_posts()) : the_post(); ?>
         <div class = "post" >
         <h2><a href= "<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2> ><?php the_title(); ?></a></h2>
             <div class = "entry" >
                 <?php the_content(); ?>
             </div>
         </div>
     <?php endwhile ; ?> ; ?>
     <?php endif ; ?> ; ?>
</div>
</body>
</html>

Copy the code from the postmetadata.txt file and paste it under <? Php the_content (); ?> . (Note: in this case, you can copy and paste. When I connect WordPress themes, I also copy and paste this part. You do not need to fully understand it yet, you just need to know what each piece of code does.)

Save the file and refresh the browser, you should see something like the following:

  WORDPRESS 8. Post meta data.

You can also look at the source code of your browser to see what the post-metadata looks like.

Explanations :

<p class = "postmetadata"> and </ p> - all information about postmetadata is inside the paragraph tag under the name class = "postmetadata", because I wanted to separate postmetadata from content. Without a paragraph tag, the metadata of the entry will go right after the content, without any separating space.

<? php _e ('Filedunder & # 58;'); ?> - & # 58; this is the code that calls the colon “:”. Set <? Php _e (''); ?> around Categories & # 58; not necessary. You can simply print. Categories:

<? php the_category (','); ?> - the_category (); This is a PHP function that calls all the categories for which you have included tags in the post. If you put together Categories: and the_category (); together, you will get "Categories: Category 1 Name, Category 2 Name" . A comma inside the_category (); - this is a way to separate category names. Take another look at the screenshot with the post-metadata and note the comma between the links to the categories.

<? php _e ('by'); ?> - the same as Categories:. If you are creating a theme for personal use, putting _e () around the word Author is optional. I think the _e () function is used to adapt topics to translations, which is important when hundreds of people from different countries view your topic. If you are going to create themes for wide use, it is better to use _e (), in case you may need translatable themes.

<? php the_author (); ?> - speaks for itself. This function simply writes your name (or the name of the person who wrote the post).

<br /> - if you need an empty line, but you do not want to use empty areas that give paragraph tags, use BR. Pay attention to the slash / . This is another self-closing tag.

<? php comments_popup_link ('NoComments & # 187;', '1 Comment & # 187;', '% Comments & # 187;'); ?> - the comments_popup_link () function calls the comments pop-up when the pop-up comments option is activated. If this option is not activated, then comments_popup_link () will simply lead you to the list of comments.

No Comments & # 187; - this is what will be displayed if you have no comments.
1 Comment & # 187; - when you have one comment.
% Comments & 187; - when you have more than one comment. For example, 8 comments. % Sign here means quantity.
& # 187; - This is a code that displays a double arrow. "

<? php edit_post_link ('Edit', '|', "); ?> - You can see this only when logged in as an administrator. edit_post_link () simply displays an edit link so you can choose which post to edit. And you do not have to search the entire list of posts in the administration panel to find the right one. edit_post_link () has three sets of single quotes. The first set is for the word you name the edit link. If you use Edit post , it will be written Edit post, but not Edit . The second set of quotes is for anything before the link. In this case, for the vertical line | ; that's what the & 124; code is for . The third pair of single quotes is for anything following an edit link. In this case, there is nothing after the link.

Log into the admin panel, then go back to the first page to see the link to edit. You will see a vertical line, followed by an “Edit” link.

Continued in the next lesson.


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Content Management Systems (CMS)

Terms: Content Management Systems (CMS)