WP: Display a specific custom post type list (archive) and that post content (single) within a custom page template - wordpress

Here's what I have.
I have a custom page template that I use for a parent page and all child pages created under that parent. This template dynamically displays the parent, "About", and all child pages, "Contact", "Terms", "Privacy", etc. on the left navigation side bar and cooresponding content as the user clicks around.
I have a custom post type, "Press", and the client wants this as a new menu choice on said left navigation side bar i.e.; "About", "Press Releases", "Contact" . . . and so on . . .
I assume I need to inject some logic into the custom page template that currently has the basic query for "page" content. I'm guessing the logic would be something like "Get me some normal page content BUT if the user clicks on "Press Releases" I'll engage another alternate query that pings the CPT "Press", grab that post_id and display the content accordingly.
Am I off track here or just having a really bad brain fart today?

Did you try adding the custom post type to the wp_list arguments?
<?php wp_list_pages( $args ); ?>
<?php $args = array(
'child_of' => 0, //parent page
'exclude' => '',
'include' => '', //parent page
'post_type' => 'page, Press' //include custom post type
); ?>

Related

WPBakery Post Grid Custom Query

I am using WPBakery and I would like to use the Post Grid to display the child pages of the current page. I understand that I can use a custom query within WPBakery, however, I am struggling with fetching the current post ID which is accepted by WPB.
I have a custom post type called 'partners' and some have child pages which I would like to bring through using the grid.
I'm looking to turn this into a custom query which is accepted by WPBakery.
$args = array(
'post_parent' => $post->ID,
'posts_per_page' => -1,
'post_type' => 'partners',
);
When use the Post Grid to display the child pages of the current page.
I use string:post_parent="parent page ID"&posts_per_page=-1&post_type=page

Creating different navwalker navigations for wordpress?

I am re-building our Learning Management System using WordPress. We use bootstrap and navwalker for the upper (main) navigation. I'd like to have another upper (main) navigation when the student is logged in. How would I go about this? Woudl you recommend my developer creates a different PHP Header Request?
So, at the moment all templates have this function:
<?php get_header();
Woudl the sensible thing be to create all the templates that need a different navigation like this:
<?php get_header(logged-in-templates);
So, the 'logged-in-templates) pull in the different navwalker...
Hope that makes sense!
Thanks
As i understood you want to display different nav menus if user is logged in and if the user is not logged in. In such case you can register additional nav menu location in functions.php:
register_nav_menus( array(
'logged_in_menu' => esc_html__( 'Menu for logged in users', 'yourthemename' ),
) );
and then just check
if(is_user_logged_in()) {
wp_nav_menu( array( 'logged_in_menu' => 'yourthemename' ) );
} else {
wp_nav_menu( array( 'primary_menu' => 'yourthemename' ) );
}
Is this what you are looking for?

WordPress Text Widget on Custom Sidebar

I am new to WordPress. I am creating a custom sidebar where I want to display only Text Widget on a Contact page. There will be different sidebar on other pages.
I know how to make different sidebars on different pages.
The issue is:
I want to display specific text widget on the custom sidebar. How do I target specific text bar as well as how to pass its value on the code?
I tried to create text widget using
<?php the_widget('WP_widget_text');?>
What will be the instance and args in this code?
P.S: I am using Zerif-lite wordPress theme
I think you are misunderstanding the use of the_widget function. The description from the WordPress Codex article is:
This template tag displays an arbitrary widget outside of a sidebar.
It shouldn't be used in a custom sidebar created with register sidebar.
If you just have a sidebar layout, without a registered WordPress sidebar, then you should use the_widget.
The second parameter, $instance, is an array or query string of the widgets settings.
For example, to display the WordPress categories widget in a template you would use:
$instance = array(
'title' => __( 'Categories' ),
'count' => 0,
'hierarchical' => 0,
'dropdown' => 0,
);
the_widget( 'WP_Widget_Categories', $instance );
If you are using a custom sidebar for the contact form you can use get_sidebar to display it in your template.
<?php get_sidebar('contact'); ?>
This would pull from the file wp-content/yourTheme/sidebar-contact.php. That sidebar can use the_widget directly to display your text widget or use dynamic_sidebar to display widgets added to the sidebar in the WordPress dashboard.

Place custom post type in add_submenu_page

I'm trying to place a custom post type under a menu page, I'm Using sandbox theme,
For example.
Main Menu
Sub Menu
Sub Menu(Custom Post)
This is the sample codes for place a submenu page. But I dont know how to implement it on custom post.
add_submenu_page(
'sandbox_theme_menu',
'Projects',
'Projects',
'administrator',
'sandbox_theme_social_examples',
create_function( null, 'sandbox_theme_display( "social_examples" );' )
);
I'm aware of using menu_position, but it is not what I want to do.
Any idea on how can I do this?
Add show_in_menu when register post type. Example('supports' added to show where place):
'supports' => array(
'title',
'thumbnail',
'editor'
),
'show_in_menu'=>'options-general.php'
Instead of options-general.php place your menu link. You can see it on mouseover. If link has get parameter like options-general.php?page=custom.php copy it all.

How to add title attribute when a page has a particular template

in my admin page i can change the default template page to another custom template.
What i need is:
In my nav header menu i have many links and i have to set title attribute of a tag when the a tag point to a page that will be rendered with my custom template and not with the default one. Example:
<li><a hreh=".." title="myCustom">link1</a></li> //this title will be redirected with my custom template
<li><a hreh="..">link2</a></li> //this title will be redirected with default template
<li><a hreh="..">link3</a></li> //this title will be redirected with default template
<li><a hreh=".." title="myCustom">link4</a></li> //this title will be redirected with my custom template
If i open header.php that links are created by:
<?php $params = array(
'theme_location' =>'primary',
'limit' => 5,
'format' => 'custom',
'link_before' => '<span>',
'link_after' => '</span>' );
wp_nav_menu($params);
?>
How can i check if link is rendered by default template or by mine one?
I'm not sure what you are trying to do but about the title thing, you can easily add that at backend... Appearance > Menus. A sample image below..
I'm not sure if this will help but have you tried reading Creating Your Own Page Templates?
So that when you create a page, you can choose what template to use for that certain page. Like this image below,
If your theme is using the function body_class, like <body <?php body_class(); ?>>, your Html is already printing what you need to target elements only in that page:
This page is using the template file: /twentytwelve/page-templates/front-page.php.
You see there's a StackOverflow class there ;), and that's by:
add_filter('body_class', 'body_class_so_14302462');
function body_class_so_14302462( $classes )
{
global $post;
if( 'page' != $post->post_type )
return $classes;
$classes[] = 'STACKOVERFLOW';
return $classes;
}
Instead of adding a class to the array, you could completely override it using $classes = 'custom-and-only-class';, and also do all kind of checks to fine tune the output.

Resources