简体   繁体   中英

Make section dynamic on index.php (Wordpress)

I'm building my first Wordpress theme, so I'm pretty new to both Wordpress and PHP. I followed a bunch of tutorials and managed to take my existing website and convert it into a custom Wordpress theme. However, I have a "About" section on my homepage (index.php) and I'd like to make it dynamic.

I was following a tutorial and they added the Biographical Info in the User Profile in one of the pages using the following code:

<?php the_author_meta( 'description' ); ?>

But that doesn't work on the index.php file. I'm guessing it's because the Index doesn't have any authors, so it doesn't really make sense to have the bio from one of the users there... I might be completely wrong though.

Any suggestions??

you should use this in the index.php with the_author_meta like this:

the_author_meta('description', 12);

you have to include author ID here 12 and this way you'll make sure that there will be description there. you can find the author ID with get_user_by :

$the_user = get_user_by('email', 'foo@bar.com');
$the_user_id = $the_user->ID;
the_author_meta('description', $the_user_id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM