Community Forums › Forums › Archived Forums › General Discussion › Help Modifying Blog Plugin
Tagged: custom plugin
- This topic has 2 replies, 2 voices, and was last updated 5 years, 3 months ago by pixeldroid.
-
AuthorPosts
-
January 8, 2019 at 3:44 pm #226994pixeldroidMember
Hi All:
Our website uses a custom Genesis theme. I know very little WordPress/PHP and I am hoping to find someone who can help me modify our blog at https://lacted.org/questions/
This blog is controlled by 2 plugins - questions-plugin.php & single-questions.phpIf you look at a post, at the top you will see the Title of the post, and also a Post #. For example, on https://lacted.org/questions/0125-breastmilk-opiates-pharmacology/, the Title (The Pharmacology of Opiates in Breastmilk) and the Post # (CQ #125 - January 1, 2019) are injected with the plugins.
I want to modify and eventually remove the injection of these 2 lines, BUT I need to do it based on the Post #.
I've been able to remove the injection of the Post # using a $threshold variable and a conditional in single-questions.php:$threshold = 111; .... if ($query -> have_posts()) { $counter = 0; while ($query -> have_posts()) { $counter++; $query->the_post(); if ($post->ID == $post_id) { // echo 'made it here. Counter: ', $counter," Threshold: ",$threshold; if ($counter < $threshold) { $counter_text = "CQ #".$counter. " - "; } else { $counter_text = ""; } } } } else { // no posts found }
However, I'm not able to figure out how to do this for the Title. I can see that the Title is injected in questions-plugin.php, but I don't know how to add a conditional to accomplish this or if I need to go further into our theme.
I'd be happy to pay someone to help get this done.
Plugin code is below.
Thanks.
questions-plugin.php<?php /* Plugin Name: Question of the Week Description: CPT for Question of the Week */ /* Start Adding Functions Below this Line */ // Our custom post type function function create_cq_posttype() { register_post_type( 'questions', // CPT Options array( 'labels' => array( 'name' => __( 'Questions' ), 'singular_name' => __( 'Question' ) ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'questions'), 'supports' => array( 'title', 'editor', 'genesis-seo', 'thumbnail','genesis-cpt-archives-settings', 'comments' ), // to add a title or add text above the posts page. ) ); } // Hooking up our function to theme setup add_action( 'init', 'create_cq_posttype' ); /* * Creating a function to create our CPT */ function custom_cq_post_type() { // Set UI labels for Custom Post Type $labels = array( 'name' => _x( 'Questions', 'Post Type General Name', 'mm' ), 'singular_name' => _x( 'Question', 'Post Type Singular Name', 'mm' ), 'menu_name' => __( 'Questions', 'mm' ), 'parent_item_colon' => __( 'Parent Question', 'mm' ), 'all_items' => __( 'All Questions', 'mm' ), 'view_item' => __( 'View Question', 'mm' ), 'add_new_item' => __( 'Add New Question', 'mm' ), 'add_new' => __( 'Add New', 'mm' ), 'edit_item' => __( 'Edit Question', 'mm' ), 'update_item' => __( 'Update Question', 'mm' ), 'search_items' => __( 'Search Question', 'mm' ), 'not_found' => __( 'Not Found', 'mm' ), 'not_found_in_trash' => __( 'Not found in Trash', 'mm' ), ); // Set other options for Custom Post Type $args = array( 'label' => __( 'questions', 'mm' ), 'description' => __( 'Questions news', 'mm' ), 'labels' => $labels, // Features this CPT supports in Post Editor 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ), // You can associate this CPT with a taxonomy or custom taxonomy. //'taxonomies' => array( 'genres' ), /* A hierarchical CPT is like Pages and can have * Parent and child items. A non-hierarchical CPT * is like Posts. */ 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'page', ); // Registering your Custom Post Type register_post_type( 'questions', $args ); } /* Hook into the 'init' action so that the function * Containing our post type registration is not * unnecessarily executed. */ add_action( 'init', 'custom_cq_post_type', 0 ); ?>
single-questions.php
https://lacted.org/questions/<?php /** * The custom questions post type template */ //Add featured image above post remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); add_action( 'genesis_before_entry', 'minimum_questions_grid' ); function minimum_questions_grid() { echo '<div class="questions-image">'. get_the_post_thumbnail( $id, array(110,110) ).'</div>'; } add_filter( 'genesis_post_info', 'ck_new_post_info' ); function ck_new_post_info( $post_info ) { global $post; $post_id = $post->ID; $args = array ( 'post_type' => array( 'questions' ), 'order' => 'ASC', 'orderby' => 'date', 'posts_per_page' => '-1', ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { $counter = 0; while ( $query->have_posts() ) { $counter++; $query->the_post(); if ($post->ID == $post_id) $counter_text = "CQ #" . $counter . " - "; } } else { // no posts found } wp_reset_postdata(); $post_info = $counter_text . "[post_date]"; return $post_info; } //* Remove the entry meta in the entry footer remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 ); remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 ); //* Run the Genesis loop genesis();
January 9, 2019 at 7:00 am #234357Victor FontModeratorThe questions plugin is not inserting anything. That portion of code is creating the Custom Post Type in WordPress so you can enter the content. It has nothing to do with displaying content on the front end.
On the example post you've referenced, the post title is the standard title as generated within the Genesis loop. It's not being derived anywhere within that custom code. You can remove post titles with:
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
You'll have to wrap this in a conditional if you want to remove titles by specific post ID.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?January 9, 2019 at 1:43 pm #237589pixeldroidMemberThanks. I sent a request for assistance on your website.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.