Need help at post_title / the_title

The code below displays the correct page you have selected, its contents and short code. The page is selected in the theme options panel in Admin Admin.

I'm struggling to repeat the headline. At the moment, he repeats all the page headers. Any help really liked!

<?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).""; }?> 

Thanks again!

+4
source share
5 answers

to repeat the title of a particular Wordpress page, you execute this wordpress function

 <?php the_title() ?> 

you can also surround it with some html for formatting css, as shown below ->

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

luck

0
source

according to Codex: http://codex.wordpress.org/Function_Reference/get_pages

"post_name" is not an argument for get_pages, it is a possible value for "sort_column".

Try the following:

 <?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; ?> 
0
source
 <?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).""; }?> 
0
source

If you like only one page echo, this should do the trick:

 <?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).""; 
0
source

Firstly, I would recommend storing the actual page / message ID in the options table, and not its name, you can still display the page names for the user, just select the drop-down list with parameters as identifiers

Have you checked the $ page-> ID from j-man86's answer, actually returning the correct id?

Assuming the saved option is the page id and not the page title, the following will work

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

Source: https://habr.com/ru/post/1391873/


All Articles