网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

引入Wordpress帖子标题作为链接

GG网络技术分享 2025-03-18 16:12 0


问题描述:

I have a Wordpress site and I\'m using the basic loop to bring in each Wordpress post

html

<?php 

if ( have_posts() ) {

while ( have_posts() ) {

the_post();

//

// Post Content here

//

} // end while

} // end if

?>

However I only want to bring in the title of each post as a link to that post (on its own single.php page) instead of all the content/images, etc. I have only been able to get all or nothing results.

网友观点:

By keeping your code, you can go this way.

<?php 

if ( have_posts() ) {

while ( have_posts() ) {

the_post();

//

echo \'<h2><a href=\\\"\'.get_the_permalink().\'\\\">\'.get_the_title().\'</a></h2>\';

//

} // end while

} // end if

?>

This way you\'ll get only your title with permalink. let me know if it helps you out or any thing else needed ?

###

hi you can give something like this

<?php 

if ( have_posts() ) {

while ( have_posts() ) {

the_post();

//

echo \'<a href=\\\"<?php the_permalink(); ?>\\\"><?php the_title(); ?></a>\';

//

} // end while

} // end if

?>

for further details you can refer this site

https://codex.wordpress.org/Function_Reference/the_permalink

标签:

提交需求或反馈

Demand feedback