php 需要post_title / the_title帮助

t8e9dugd  于 2022-12-02  发布在  PHP
关注(0)|答案(5)|浏览(163)

下面的代码显示我选择的页面,它的内容和shortocde正确。页面是从WP管理的主题选项面板中选择的。
我正在努力呼应标题。目前它呼应所有页面的标题。任何帮助非常感激!

<?php
     $blockwho = get_option('good_blockwho');
     $homeblockwho = get_pages ('post_name='.$blockwho); ?>

<?php foreach ($homeblockwho as $hbw) {   
     $content = $hbw->post_content;
     $title = $hbw->post_title;
     apply_filters('the_content', $content);

     echo "<h2><span>".$title."</span></h2>";
     echo "".do_shortcode($content)."";
}?>

再次感谢!

xwbd5t1u

xwbd5t1u1#

为了呼应一个单一的WordPress页面的标题,你做这个WordPress的功能

<?php the_title() ?>

你也可以用一些html将它包围起来,这样就可以进行css格式的设置-〉

<h2><?php the_title() ?></h2>

祝你好运

thigvfpy

thigvfpy2#

根据法典:http://codex.wordpress.org/Function_Reference/get_pages
“post_name”不是get_pages的参数,它是“sort_column”的可能值。
请尝试以下操作:

<?php
global $post;
$blockwho = get_option('good_blockwho');
$page = get_page_by_title($blockwho);

$myposts = get_posts('post_type=page&p='$page->ID);
foreach($myposts as $post) :
setup_postdata($post);
?>

    <?php the_title(); ?>

<?php endforeach; ?>
hk8txs48

hk8txs483#

<?php
     $blockwho = get_option('good_blockwho');
     $homeblockwho = get_pages ('post_name='.$blockwho); ?>

<?php foreach ($homeblockwho as $hbw) {   
     $content = $hbw->post_content;
     $title = $hbw->post_title;
     apply_filters('the_content', $content);

     echo "<h2><span>".$homeblockwho ->post_title."</span></h2>";
     echo "".do_shortcode($content)."";
}?>
vshtjzan

vshtjzan4#

如果您只想回显一个页面,以下命令应该可以:

<?php
$blockwho = get_option('good_blockwho');
$page = get_post($blockwho);

$content = $page->post_content;
apply_filters('the_content', $content);

echo "<h2><span>".$page->post_title."</span></h2>";
echo "".do_shortcode($content)."";
cmssoen2

cmssoen25#

首先,我建议在选项表中存储实际的页面/帖子ID,而不是它的名称,您仍然可以向用户显示页面标题,只是有一个下拉框,其中的选项值作为ID
你有没有检查过j-man 86的答案是否返回了正确的ID?
假设stored选项是页面ID而不是页面标题,则可以使用以下代码

$page = get_page(get_option('good_blockwho'));
$title = $page->post_title;
$content = apply_filters('the_content', $page->post_content);

相关问题