如何使用<p></p>包装器显示给定页面ID的内容?
我目前使用的方法是:
<?php
$id=21;
$post = get_page($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
Run Code Online (Sandbox Code Playgroud)
例如,page ID = 21有以下内容:Some content
wordpress echo是什么 <p>Some content</p>
任何建议都非常感谢.
我有一个主题有两个自定义帖子类型,布道和成员.我也有永久链接设置为postname.
首先,single.php会捕获一般的博客帖子以及成员,但不会播放布道......它只会显示index.php文件.
经过一些研究,我发现重置(保存)永久链接会重置它们.这种方法现在可以捕获成员自定义帖子,但只显示index.php用于讲道.
这就是我称之为......
// Custom Post types for Sermons
add_action('init', 'sermons');
function sermons() {
$args = array(
'labels' => array(
'name' => __( 'Sermons' ),
'singular_name' => __( 'Sermons' ),
'add_new' => __( 'Add Sermon' ),
'add_new_item' => __( 'Add Sermon' ),
'edit_item' => __( 'Edit Sermon' ),
'new_item' => __( 'Add Sermon' ),
'view_item' => __( 'View Sermon' ),
'search_items' => __( 'Search Sermons' ),
'not_found' => __( 'No Home Sermons found' ),
'not_found_in_trash' => __( 'No Sermons …Run Code Online (Sandbox Code Playgroud) 我希望能够在我的主题中放置一个条件PHP代码,当管理员或只有一个用户(ID = 1)登录时,它会加载不同的样式表.
是否有WordPress功能来实现这一目标?
这个div有一个类(比如说"示例"),在帖子上设置为"display:none".
我只是希望管理员在登录时查看它,我将为该类创建一个新的CSS属性,如:
.example {
display: block;
}
Run Code Online (Sandbox Code Playgroud) 我在index.php页面中有以下代码,用于获取所有页面并更改它们.问题是我没有用来the_content()显示内容,而是使用echo $page->post_content().我现在必须在我的页面中嵌入一个联系表格7,但是当我在这里阅读不同的问题时,如果没有,则短代码将无效the_content().
我的问题是如何在这里展示联系表格.
$pages = get_pages($args);
foreach ($pages as $page){
// Override Homepage
if($page->ID == 5){
$page->post_content = file_get_contents(get_template_directory_uri().'/includes/homepage-override.php');
}
// Check if it is menu page
if($page->post_parent == 169){
$page->post_content = file_get_contents(get_template_directory_uri().'/includes/location-menu-page.php?location='.$page->post_title);
}
// Calling Gallery Images
if($page->ID == 23){
$page->post_content = file_get_contents(get_template_directory_uri().'/includes/gallery-page.php');
}
// Calling about page
//if($page->ID == 7 || $page->ID == 17 || $page->ID == 29){
if(has_post_thumbnail($page->ID)):
$image = wp_get_attachment_image_src( get_post_thumbnail_id($page->ID), 'single-post-thumbnail' );
$dom = new DOMDocument();
@$dom->loadHTML($page->post_content);
$imgs = $dom->getElementsByTagName("img"); …Run Code Online (Sandbox Code Playgroud) 我正在为Wordpress网站开发自定义主题,我想使用Wordpress核心数据验证函数来验证某些表单的信息.
每次我尝试使用该sanitize_text_field()函数时,我都会收到此错误:
致命错误:调用未定义的函数sanitize_text_field().
我已经阅读了许多类似问题的帖子,特别是使用$wpdb,但它们似乎都没有用.
我正在尝试使用此卫生功能的文件位于我的主题目录中,以防这条信息有助于解开这个谜团.
我已经看到一些帖子谈论包括wp-load.php和formatting.php文件,但我的尝试都没有.
所以我发现你不能在PHP回声中运行PHP(对我来说是愚蠢的)所以我想不出另一种方法来运行这个脚本,也许做一个变量?
它是一个php脚本中的wordpress php脚本
<?php if ( !is_user_logged_in() ) {
echo '<a href=" <?php echo get_site_url(); ?>/login" class="typcn typcn-key-outline">Log in</a>';
}
else {
echo '<a href="<?php echo get_site_url(); ?>/wp-login.php?action=logout" class="typcn typcn-key-outline">Log out</a>';
} ?>
Run Code Online (Sandbox Code Playgroud) 如何将remove_post_type_support('email_template', 'title');唯一的内容应用于后期编辑屏幕?
标题应在创建时可用,不可编辑。
有关此错误的一些问题,但我找不到任何解决方案.我正在开发一个WordPress主题,在排队脚本中出现了这个错误:
Uncaught TypeError: $ is not a function
at components.js?ver=4.8:65
at components.js?ver=4.8:95
Run Code Online (Sandbox Code Playgroud)
这是我的enqueue代码添加到functions.php:
function goc_scripts() {
wp_enqueue_style( 'goc-style', get_stylesheet_uri() );
wp_enqueue_style( 'socicon', get_stylesheet_directory_uri() . '/css/socicon.css', array() );
wp_enqueue_style( 'bootstrap-social', get_stylesheet_directory_uri() . '/css/bootstrap-social.css', array() );
wp_enqueue_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css');
wp_enqueue_style('font-awesome', get_template_directory_uri() . '/css/font-awesome.min.css');
wp_enqueue_style('simple-line-icons', get_template_directory_uri() . '/css/simple-line-icons.min.css');
wp_enqueue_style('animate', get_template_directory_uri() . '/css/animate.min.css');
wp_enqueue_style('cubeportfolio', get_template_directory_uri() . '/css/cubeportfolio.min.css');
wp_enqueue_style( 'owlcarousel-style', get_template_directory_uri() . '/css/owl.carousel.css' );
wp_enqueue_style( 'fancybox', get_template_directory_uri() . '/css/jquery.fancybox.css' );
wp_enqueue_style( 'goc-slider', get_template_directory_uri() . '/css/slider.css' );
wp_enqueue_style( 'goc-plugins', get_template_directory_uri() . '/css/plugins.css' );
wp_enqueue_style( 'goc-red3', …Run Code Online (Sandbox Code Playgroud) 编辑:这是我试图分页的当前代码。它创建一个自定义查询,不包括最新帖子以及一个类别中的所有帖子。分页在大多数情况下都可以正常工作,但是问题是分页列表中的最后一个链接将我带到了空白页。
<section class="card-grid card-grid--push">
<main class="container container--wide">
<?php
$current_page = get_query_var('paged');
$current_page = max( 1, $current_page );
$per_page = 3;
$offset = ( $current_page - 1 ) * $per_page + 1;
$post_list = new WP_Query(array(
'cat' => -15,
'posts_per_page' => $per_page,
'paged' => $current_page,
'offset' => $offset,
'orderby' => 'date',
'order' => 'DESC',
));
if ( $post_list->have_posts() ):
while ( $post_list->have_posts() ):
$post_list->the_post();
?>
<a href="<?php the_permalink(); ?>" <?php post_class('card'); ?>>
<article class="card__content">
<?php the_post_thumbnail('th-card'); ?>
<div class="card__head">
<span class="category"> …Run Code Online (Sandbox Code Playgroud) 我正在使用高级自定义字段来创建特定类别的帖子。我使用Elementor(免费版)进行格式化,我希望所有使用ACF创建的帖子都应显示在我页面的特定部分下。但是,我无法做到这一点,因为elementor pro支持此功能,并且我无法在elementor中编写php。
关于如何做到这一点的任何想法?
wordpress wordpress-theming custom-wordpress-pages advanced-custom-fields elementor